Skip to content

feat(openrouter): add configurable provider routing#235

Merged
lidge-jun merged 1 commit into
lidge-jun:devfrom
riique:codex/openrouter-provider-routing
Jul 22, 2026
Merged

feat(openrouter): add configurable provider routing#235
lidge-jun merged 1 commit into
lidge-jun:devfrom
riique:codex/openrouter-provider-routing

Conversation

@riique

@riique riique commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add provider-wide OpenRouter routing preferences through openRouterRouting
  • add exact per-model overrides through modelOpenRouterRouting
  • map camel-case config to OpenRouter's provider.order, provider.only, and provider.allow_fallbacks wire fields
  • validate the canonical OpenRouter Chat Completions target and fail closed on malformed or inapplicable configuration
  • document the feature in the architecture SOT and all configuration reference locales

Why

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, and allow_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

  • focused OpenRouter routing tests: 26 passed
  • focused routing/config/server tests: 119 passed
  • bun run typecheck: passed
  • bun run lint:gui: passed
  • bun run privacy:scan: passed
  • docs build: 97 pages generated successfully
  • broad suite run: 3370 passed, 4 skipped; three in-flight feature failures were fixed and pass in the focused rerun. Two unrelated Windows Cursor shell-fixture tests still fail locally because they invoke POSIX printf; they pass only when that shell dependency is available.

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

Target branch corrected

This pull request now targets dev.

The [WRONG BRANCH] title prefix has been removed. The pull request has been marked ready for review again.

@github-actions github-actions Bot changed the title feat(openrouter): add configurable provider routing [WRONG BRANCH] feat(openrouter): add configurable provider routing Jul 22, 2026
@github-actions
github-actions Bot marked this pull request as draft July 22, 2026 01:22
@riique
riique changed the base branch from main to dev July 22, 2026 01:24
@github-actions github-actions Bot changed the title [WRONG BRANCH] feat(openrouter): add configurable provider routing feat(openrouter): add configurable provider routing Jul 22, 2026
@github-actions
github-actions Bot marked this pull request as ready for review July 22, 2026 01:24
@riique
riique force-pushed the codex/openrouter-provider-routing branch from b2d8e06 to 3c6f3ca Compare July 22, 2026 01:24
@lidge-jun

Copy link
Copy Markdown
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 openai-chat transport. Config surface follows the existing provider-wide + exact-model override pattern, and the locale docs are consistent.

Local verification on top of current dev passed (focused routing/config/openai-chat tests + typecheck). I've approved the pending CI runs; once Cross-platform CI and React Doctor are green this is ready to absorb into dev.

@lidge-jun
lidge-jun merged commit 897bdcc into lidge-jun:dev Jul 22, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants