Repository navigation
Description
Summary
Could you consider adding built-in, opt-in bindings between upstream credentials and configured proxy routes?
We use opencode2api and appreciate how much functionality is now supported upstream. One feature for which we still maintain a small downstream customization is preventing a credential from silently moving to another proxy when its assigned proxy fails. Native support would let us remove that customization and follow upstream releases directly.
By “built-in,” we mean available in the standard application, not enabled for every existing deployment. Existing configurations should retain their current routing behavior unless the operator explicitly enables binding.
Current behavior
Reviewed against v1.4.3 / main at 0bb23c7:
nodePoolininternal/gateway/pool.goinitially assigns keys to proxies by array position (i % number_of_proxies). This is an initial assignment, not a different proxy being selected for the same key on every request.rebindUnavailableProxyininternal/gateway/refresh.gomoves credentials from an unavailable proxy to another route.- Rebuilding the runtime after changing the key/proxy lists recalculates the positional assignments.
- Session affinity selects a preferred credential; it does not express a persistent policy for which proxy that credential may use.
Automatic migration is a reasonable availability-oriented default. The missing option is an explicit routing policy for deployments where changing a credential's egress route is not acceptable.
Why this would be useful
- Predictable credential routing. Operators can deliberately associate each credential with its required network route, including environments with controlled outbound connectivity or egress allowlists.
- Failure isolation. A proxy outage should not silently change the routing of that credential or move its traffic onto a route assigned to other credentials. The operator should be able to choose isolation over automatic migration.
- Auditable configuration changes. Adding, removing, or reordering unrelated entries should not implicitly change an existing binding.
- Less downstream maintenance. This is routing policy rather than provider-specific request shaping, so it seems appropriate for the gateway itself instead of a long-lived private patch.
This request does not assume that changing IPs necessarily causes an upstream ban, and it is not a request to bypass provider limits or restrictions.
Requested behavior
Explicit bindings
Allow an operator to associate a configured Zen or Go credential with a configured proxy route. The exact configuration schema is up to the maintainers; stable references would be preferable to array indexes or duplicating raw secrets in another section.
A binding is a restriction on where a credential may be sent, not a requirement that every proxy have exactly one credential. Operators may intentionally assign multiple credentials to one route.
Fail closed for bound credentials
If a bound proxy is unavailable, keep the credential associated with that proxy and apply the normal bounded retry/cooldown behavior. Do not silently send that credential through another proxy or through direct egress.
This does not need to disable ordinary fallback to a different credential: if request policy permits selecting credential B, B should simply use its own configured route. A diagnostic explicitly targeting credential A should not substitute B.
Recovery of the original proxy should restore usability without changing the binding. A removed or unresolved proxy reference should produce a clear validation error rather than an implicit direct/default route. An invalid hot reload should leave the previous valid runtime active.
Stable and consistent application
Bindings should survive save/reload/restart and reordering of unrelated entries. Reassigning a credential to another route should require an intentional configuration change.
The same restriction should apply to other requests that carry that credential, such as model discovery, selected-key diagnostics, and Go quota reads—not only normal inference.
Anonymous routing can remain unchanged. Existing unbound configurations, and explicitly permitted direct routing outside a binding, should remain backward-compatible.
A binding to a proxy route must not be described as a guarantee of one public IP: a rotating #pool endpoint can change its exit independently. Document this distinction, and either reject such entries in a stable-egress mode or clearly explain the limitation.
Possible incremental approach
If explicit persistent mappings are too large for an initial change, an opt-in strict mode that disables automatic key migration would already be useful.
We currently use a small guard around rebindUnavailableProxy for that limited behavior. However, that alone does not provide persistent mappings, prevent direct assignments, or make positional configuration changes safe. Those limitations should be explicit rather than presenting the smaller change as the complete binding feature.
A first version could be file-managed, provided the WebUI preserves its settings. Binding controls and masked key/proxy status in the WebUI could follow separately.
Suggested acceptance tests
All of these can use local fake upstreams/proxies without live provider credentials:
- A bound key only reaches its configured proxy, including retries and background credential-bearing requests.
- Failure of that proxy does not send the same key to another proxy or direct egress.
- Recovery resumes traffic on the original route.
- Save, reload, restart, and reordering unrelated entries preserve explicit bindings.
- Missing/removed references are rejected; a rejected reload preserves the previous runtime.
- Unbound configurations retain existing behavior; anonymous routing is unaffected.
- Configuration round-trips and diagnostics do not expose credentials.
Related work and question
I found #113, which proposes pinning all keyed traffic to direct egress. It addresses a related desire for stable routing, but not assigning different credentials to different configured proxies. This request is intended to complement that discussion rather than duplicate it.
Would you consider supporting this routing policy upstream? If so, would you prefer a small strict-mode increment first, or an explicit per-key binding model from the start?
Thank you for maintaining the project and for considering this request.
Activity
feat(gateway): add optional per-key proxy binding with fail-closed ro…