feat(openrouter): add configurable provider routing#235
Merged
lidge-jun merged 1 commit intoJul 22, 2026
Conversation
|
✅ Target branch corrected This pull request now targets The |
riique
force-pushed
the
codex/openrouter-provider-routing
branch
from
July 22, 2026 01:24
b2d8e06 to
3c6f3ca
Compare
Owner
|
Review done — the fail-closed semantics look right: with no routing config nothing is injected, invalid config is rejected, and routing only applies to the canonical OpenRouter URL on the Local verification on top of current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
openRouterRoutingmodelOpenRouterRoutingprovider.order,provider.only, andprovider.allow_fallbackswire fieldsWhy
OpenRouter can serve the same model through multiple inference providers. Those endpoints can differ substantially in prompt-cache support, cache hit behavior, retention, and cache pricing. For long Codex sessions, an endpoint with strong caching can be materially cheaper and faster than another endpoint serving the same model.
OpenRouter provides sticky routing automatically, but users still need explicit control when they require a particular provider's cache semantics or want to fail closed instead of silently switching to an endpoint with worse cache behavior. OpenRouter's documented request-level provider routing already supports this through
order,only, andallow_fallbacks; this PR exposes those controls in opencodex.References:
Example
{ providers: { openrouter: { adapter: openai-chat, baseUrl: https://openrouter.ai/api/v1, apiKey: ${OPENROUTER_API_KEY}, openRouterRouting: { order: [deepseek], allowFallbacks: false }, modelOpenRouterRouting: { anthropic/claude-sonnet-5: { only: [anthropic], allowFallbacks: false } } } } }A matching model override replaces the provider-wide default. With no routing preference configured, request bodies retain the existing behavior and OpenRouter keeps its default routing policy.
Validation
bun run typecheck: passedbun run lint:gui: passedbun run privacy:scan: passedprintf; they pass only when that shell dependency is available.