Skip to content

feat(provider): route the managed wallet through OpenRouter only#110

Merged
Aayam Bansal (aayambansal) merged 1 commit into
mainfrom
feat/managed-openrouter-routing
Jul 6, 2026
Merged

feat(provider): route the managed wallet through OpenRouter only#110
Aayam Bansal (aayambansal) merged 1 commit into
mainfrom
feat/managed-openrouter-routing

Conversation

@aayambansal

Copy link
Copy Markdown
Member

The centerpiece of the streaming/reasoning fix. When a user is on the managed wallet (billing.llm === "managed"), all wallet inference now flows through OpenRouter only — never the Anthropic / OpenAI / Google managed proxies.

Why

openscience had broadened managed inference into a first-party multi-proxy fan-out via managedProxyKey (attaching the thk_ wallet token to anthropic/openai/google/openrouter alike). Each of those upstreams streams reasoning in a different shape (Claude thinking, OpenAI summary items, Google thoughts, OpenRouter reasoning_details), so the managed path had four fragile reasoning branches — the root cause of "reasoning traces are broken across providers." Funneling the wallet through OpenRouter collapses that to one unified reasoning stream.

How (all gated on the explicit managed toggle)

Two pure, unit-tested helpers:

  • managedRoutesOpenRouterOnly(config) — true only for billing.llm === "managed".
  • managedProviderAllowed(id)openrouter + the hosted synsci demo.

Wired into:

  1. managedProxyKey(providerID, baseURL) — never attach the thk_ wallet token to a first-party proxy.
  2. isProviderAllowed — drop every non-OpenRouter / non-synsci provider from a managed session. defaultModel() / getSmallModel() read the filtered state, so they become OpenRouter-only transitively.

Safety

  • BYOK + auto-detect untouched. Everything is gated on the explicit toggle; billing.llm defaults to undefined (auto). The existing "managed atlas proxy base URLs are forwarded" / "…without proxy URLs fail" tests (which never set the toggle) still pass, as do all 69 provider tests.
  • pinByokToPublicEndpoint (BYOK-leak guard) and requireAtlasProxyForManagedKey are unchanged.

Flagged for your call

Under the strict reading, an explicit managed session also drops first-party OAuth providers (Codex "Sign in with ChatGPT", Claude Pro/Max) — a user who wants their own OAuth subscription switches LLM spend to BYOK. Since managed is an explicit opt-in meaning "bill my wallet," this matches intent, but say the word if you'd rather keep OAuth usable inside managed mode.

Tests

test/provider/managed-routing.test.ts: pure-helper coverage + hermetic availability tests (managed ⇒ only OpenRouter loads; BYOK anthropic keeps its public endpoint; legacy auto-detect unchanged). Reasoning-stream correctness on this OpenRouter path is the immediate follow-up PR.

When the LLM spend toggle is explicitly "managed", wallet inference now
flows through OpenRouter exclusively — the first-party managed proxies
(anthropic / openai / google), which openscience had fanned the wallet
across via managedProxyKey, are taken out of the managed path. OpenRouter
is the one gateway with a single unified reasoning stream, so this both
implements "wallet ⇒ OpenRouter, no other providers" and sets up the
reasoning-trace fix (follow-up PR).

Two pure helpers gate everything:
- managedRoutesOpenRouterOnly(config): true only for billing.llm==='managed'.
- managedProviderAllowed(id): openrouter + the hosted synsci demo.

Wired into (1) managedProxyKey — never attach the thk_ wallet token to a
first-party proxy; and (2) isProviderAllowed — drop non-OpenRouter/non-synsci
providers from a managed session, which transitively makes defaultModel()
and getSmallModel() OpenRouter-only (they read the filtered state).

BYOK and the legacy auto-detect path (billing.llm unset/null/'byok') are
untouched — the existing managed-proxy-forwarding tests, which never set
the toggle, still pass. pinByokToPublicEndpoint and the managed-key sanity
check are unchanged.
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openscience Ready Ready Preview, Comment Jul 6, 2026 3:49pm

Request Review

@aayambansal Aayam Bansal (aayambansal) merged commit 959eee4 into main Jul 6, 2026
12 checks passed
@aayambansal Aayam Bansal (aayambansal) deleted the feat/managed-openrouter-routing branch July 6, 2026 15:52
Aayam Bansal (aayambansal) added a commit that referenced this pull request Jul 8, 2026
When the LLM spend toggle is explicitly "managed", wallet inference now
flows through OpenRouter exclusively — the first-party managed proxies
(anthropic / openai / google), which openscience had fanned the wallet
across via managedProxyKey, are taken out of the managed path. OpenRouter
is the one gateway with a single unified reasoning stream, so this both
implements "wallet ⇒ OpenRouter, no other providers" and sets up the
reasoning-trace fix (follow-up PR).

Two pure helpers gate everything:
- managedRoutesOpenRouterOnly(config): true only for billing.llm==='managed'.
- managedProviderAllowed(id): openrouter + the hosted synsci demo.

Wired into (1) managedProxyKey — never attach the thk_ wallet token to a
first-party proxy; and (2) isProviderAllowed — drop non-OpenRouter/non-synsci
providers from a managed session, which transitively makes defaultModel()
and getSmallModel() OpenRouter-only (they read the filtered state).

BYOK and the legacy auto-detect path (billing.llm unset/null/'byok') are
untouched — the existing managed-proxy-forwarding tests, which never set
the toggle, still pass. pinByokToPublicEndpoint and the managed-key sanity
check are unchanged.
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.

1 participant