feat(provider): route the managed wallet through OpenRouter only#110
Merged
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
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.
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 thethk_wallet token to anthropic/openai/google/openrouter alike). Each of those upstreams streams reasoning in a different shape (Claudethinking, OpenAI summary items, Google thoughts, OpenRouterreasoning_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
managedtoggle)Two pure, unit-tested helpers:
managedRoutesOpenRouterOnly(config)— true only forbilling.llm === "managed".managedProviderAllowed(id)—openrouter+ the hostedsynscidemo.Wired into:
managedProxyKey(providerID, baseURL)— never attach thethk_wallet token to a first-party proxy.isProviderAllowed— drop every non-OpenRouter / non-synsciprovider from a managed session.defaultModel()/getSmallModel()read the filtered state, so they become OpenRouter-only transitively.Safety
billing.llmdefaults toundefined(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) andrequireAtlasProxyForManagedKeyare 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
managedis 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.