Repository navigation
feat(chatgpt): backport #41522 client subscription forwarding to stable/1.106.x for v1.106.8 - #49888
Conversation
Backport of #41522 to stable/1.106.x. Cherry-picked from 2e27a02 (litellm_codex_forward_chatgpt_login), adapted to the line (reject_server_owned_wif_params instead of the fields registry, no attribute_or_none helper, acompletion provider detection carries the request's extra_headers, pass_through_request gains upstream_headers_filter). Original main author: devin-ai-integration[bot]. Author reset to the PR author so the CLA check can match a signer.
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
PR overviewThis PR backports ChatGPT client subscription forwarding to stable/1.106.x for v1.106.8, updating router credential handling and ChatGPT request configuration. One issue has been addressed, but two security issues remain open. An authorized caller can cause a deployment’s saved ChatGPT access token to be sent to a caller-controlled endpoint. Separately, caller-supplied authorization headers can disconnect requests from the configured deployment’s budget accounting while still using its saved credentials, allowing repeated requests to bypass deployment budgets. Open issues (2)
Fixed/addressed: 1 · PR risk: 8/10 Reviews |
…lied provider headers A forwarded ChatGPT bearer now has to be a ChatGPT JWT before the router treats it as the deployment key, and its per-request deployment id no longer hashes the bearer, so distinct tokens reuse one cost-map entry per deployment instead of adding one each. The proxy drops any provider_specific_header the request body carried before it builds its own, the used_client_oauth_token stamp only counts an Anthropic OAuth token, and the sync Responses handler merges provider-scoped headers only for chatgpt so other providers keep the line's behavior
[High impact] The PR changes how ChatGPT subscription credentials travel through shared LiteLLM request paths. The repository’s live QA requirement must be satisfied before merging Findings
SummaryBackports client ChatGPT subscription forwarding and native Codex routes to
Reviews (2) · Last reviewed commit: "fix(chatgpt): stop forwarded ChatGPT log..." · Reviewed by Greptile |
| return await pass_through_request( | ||
| request=request, | ||
| target=f"{CHATGPT_API_BASE}/{endpoint}", | ||
| custom_headers=dict(headers), | ||
| user_api_key_dict=user_api_key_dict, | ||
| custom_llm_provider="chatgpt", | ||
| upstream_headers_filter=lambda _: headers, |
There was a problem hiding this comment.
Successful live proof is missing
The supplied live proof only shows rejected requests with fake ChatGPT tokens. The repository requires successful live proxy requests for translation changes, including affected streams and tool calls. Before merging, add commands and outputs for the standard and native routes at c4847e1dff87ed747d45f56caab9e50863327de2
Rule Used: Apply this rule only to PRs that fix LLM translation bugs or add LLM translation features. LLM translation means converting requests, responses, streaming events, tool calls, and errors between the API a caller uses on LiteLLM (any endpoint or SDK fu... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
This is a backport of #41522, whose live proof covers these routes. A live run on this line's tip is still owed
There was a problem hiding this comment.
Agreed. The live proof from #41522 is useful for route coverage, but it doesn’t verify the adapted backport on stable/1.106.x; a live run on this PR’s tip is still owed. My earlier request named the wrong commit: please attach successful proxy-to-provider results for the affected standard and native routes, with commands and outputs, run at 19ab60e7ac2fcd9e18e5c09d21a7028cf2d66b96.
A saved ChatGPT login, from chatgpt_auth_file or the default token store, is now only ever sent to the authenticator's own base URL. A caller-supplied api_base with client-side credentials no longer receives it on chat or Responses calls
| if deployment_provider in _FORWARDED_CREDENTIAL_ISOLATION_PROVIDERS | ||
| else None | ||
| ) | ||
| if is_clientside_credential(request_kwargs=kwargs) or forwarded_authorization is not None: |
There was a problem hiding this comment.
High: Ignored authorization headers bypass deployment budgets
For a ChatGPT deployment using a saved login, an authenticated caller can submit provider_specific_header={"custom_llm_provider":"chatgpt","extra_headers":{"Authorization":"Bearer not-a-jwt"}} in the JSON body; the proxy preserves this field, and this branch accepts it even though the provider ignores it as a client credential. The request receives a synthetic model_info.id while still using the saved gateway token, so RouterBudgetLimiting cannot associate its spend with the configured deployment and repeated requests bypass that deployment's max_budget.
Keep the original budget-accounting identity whenever gateway credentials are used, and only isolate forwarded credentials that the provider will actually select.
There was a problem hiding this comment.
Real, and main has the same path. This backport mirrors #41522, so the fix goes to main first and comes here after
19ab60e to
3d2263d
Compare
| client_credential: Final = get_chatgpt_request_credential(litellm_params) | ||
| if client_credential is not None: | ||
| return chatgpt_client_api_base(api_base), client_credential.access_token, custom_llm_provider | ||
| if api_key: |
There was a problem hiding this comment.
High: Saved ChatGPT login sent to a caller-controlled endpoint
With client-side credentials enabled and chatgpt_auth_file configured on a deployment, an authorized caller can POST /v1/responses with api_key: "dummy" and api_base: "https://attacker.example": this branch accepts the destination, but ChatGPTResponsesAPIConfig.validate_environment() subsequently replaces the dummy key with the deployment's saved access token, which the HTTP handler sends there. Keep credential and destination selection consistent by using the selected authenticator's base whenever the saved auth file supplies the token.
| if api_key: | |
| if api_key and not get_chatgpt_auth_file(litellm_params): |
A forwarded ChatGPT bearer gets its own per-request deployment so its errors never cool down the gateway login, but that deployment's id used to hash the bearer, so every distinct token added a litellm.model_cost entry that was never removed. The id now leaves the bearer out, so forwarded logins share one entry per deployment. Main's router core registers no pricing for per-request deployments, so it never had this growth
|
bugbot run |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 731bfff. Configure here.
| ) | ||
| if extra_headers is None and not scoped_headers: | ||
| return None | ||
| return {**(extra_headers or {}), **scoped_headers} |
There was a problem hiding this comment.
Header merge is case-sensitive
Medium Severity
merge_provider_specific_headers spreads extra_headers and scoped ChatGPT headers by exact key, so authorization and Authorization both survive. get_chatgpt_client_credential then takes the first case-insensitive match, which can be a non-ChatGPT value and skip client-subscription forwarding in favor of the gateway login.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 731bfff. Configure here.
A chatgpt deployment that logs in through chatgpt_auth_file, on a proxy with no default ChatGPT login, made the spend writer resolve its provider through the default authenticator. That raised after the SpendLogs row was queued, so key, user, team and daily spend for every gateway-login Responses call was skipped. Partial pick of the provider_stores_the_conversation short-circuit and its regression test from main's b8283d8 (#44772), which #41522 relied on there
Prepares stable/1.106.x for the v1.106.9 patch, which ships BerriAI#51261 and BerriAI#49888. litellm-enterprise and litellm-proxy-extras have no changes since v1.106.8, so only the root package moves.


TLDR
Backport of #41522 to
stable/1.106.x, shipping as v1.106.8Problem this solves:
/backend-api/codex/*requests through the gateway return 404 on 1.106How it solves it:
User Flow
Before: a developer on a 1.106 gateway gets billed on the gateway's ChatGPT account
model: chatgpt/gpt-*with a saved gateway loginAfter: the same request runs on the developer's own subscription
model: chatgpt/gpt-*with a saved gateway loginRelevant issues
Backport of #41522 (fixes #46062 on this line)
Linear ticket
Resolves LIT-10389
key-feature: codex-subscription-passthrough
Approved as an exception to the backport policy, since #41522 is a feature and not a P0 fix
Backport checklist
reject_server_owned_wif_paramsin place ofreject_server_owned_wif_fields, with the same exemption ofchatgpt_auth_fileon deployment-management routesgetattrin place ofattribute_or_none, which the line does not haveacompletionandresponsespass the request'sextra_headersandprovider_specific_headerinto provider detection through the line'sGenericLiteLLMParamscall shapepass_through_requestgains theupstream_headers_filterargument from feat(vertex_ai): let operators drop chosen anthropic-beta values on the Vertex AI pass-through routes #47185oidc/api_key references is dropped because that feature is not on the linelitellm.model_costentry that was never removed, so every distinct token grew the worker's memory (the Veria finding onlitellm/router.py). Main deleted its Python router core in refactor(router): delete the python router core #50178 on 2026-11-05, and the Rust core that replaced it builds the per-request deployment without registering pricing. Here the id now leaves the bearer out, so forwarded logins share one entry per deployment and stay separate from the gateway's own deploymentdeclared_authenticating_providershort-circuit inprovider_stores_the_conversation, and without it achatgpt/*deployment withchatgpt_auth_fileon a proxy with no default ChatGPT login raised in the spend writer after the SpendLogs row was queued. Key, user, team and daily spend for every gateway-login Responses call was skipped. The pick takes only that line and its regression testtest_a_chatgpt_responses_row_queues_without_a_default_chatgpt_login, which fails at 731bfff with the ChatGPTGetAccessTokenErrorand passes at 3b51173.tests/unit/proxy/db/test_db_spend_update_writer.py,tests/unit/responses/andtests/unit/llms/chatgpt/pass at 3b51173, 1409 passedstable/1.106.xtip 25fc8bf. The final tree is byte-identical to the pick plus the bump applied straight onto that tippyproject.tomlanduv.lockbumped to 1.106.8 in their own commit, one above the v1.106.7 release. Noenterprise/orlitellm-proxy-extras/changes, so no subpackage bumpTestAutoRouterTraceProvenancetests that fail the same way on the untouchedstable/1.106.xtipruff format --checkflags the same 10 files on the line before and after the pick, so nothing newScreenshots / Proof of Fix
The pick is the main squash adapted only for missing helpers, so the end-to-end proof is the one captured on #41522. See the Screenshots / Proof of Fix section there, Before at dab39d7 and After at a207c3a
On this line at 19ab60e (tree identical to 3d2263d), the pick's own tests pass with the run above. The CVE sweep and
/gauntlet-miniwere not run for this revisionThe cost-map fix ran live on two proxies at the same time, Before at 3d2263d and After at 731bfff, each with its own Postgres and Redis and the same config. The deployment is
chatgpt/gpt-*with a saved gateway login file, and each call carries a different unsigned ChatGPT JWT inAuthorizationplus the gateway key inx-litellm-api-key, so ChatGPT answersinvalid_issuerwithout spending a subscription. The deployment id each call ran on is read from its spend log row. Both proxies print"workers" flag is ignored when reloading is enabled, so this checkout serves one worker and the two-worker check was droppedBefore (3d2263d)
invalid_issuereach, spend rows on three different deployment ids (3df8babf...,0e55f575...,62e165ff...), one new cost-map entry per tokeninvalid_issuer, spend row on the configured deploymentaa14d2a0...After (731bfff)
invalid_issuereach, all three spend rows on one shared deployment id5750fcf2...invalid_issuer, spend row still onaa14d2a0..., so a forwarded login's errors stay off the gateway deploymentType
🆕 New Feature
Caveats (if any)
Severe
High
Medium
Link to Devin session: https://app.devin.ai/sessions/164d0a6b82f946569e8cb19e1f5c5656
Open in Devin Desktop: https://app.devin.ai/desktop/session/164d0a6b82f946569e8cb19e1f5c5656?variant=devin
Requested by: @jesus-berri
Note
High Risk
Changes authentication, credential forwarding, and proxy passthrough paths; misconfiguration could leak tokens or bill the wrong ChatGPT account.
Overview
Adds ChatGPT/Codex subscription passthrough so Codex and Pi can use a LiteLLM virtual key for gateway auth while the caller’s ChatGPT OAuth bearer is what actually bills OpenAI.
The
chatgpt/provider gainschatgpt_auth_filefor per-deployment saved logins, client-supplied ChatGPT OAuth detection in headers/provider_specific_header, and safer routing (metadata no longer triggers device login; forwarded bearers use isolated per-request deployments without bloating the cost map).The proxy exposes native
GET/POST /backend-api/codex/{models,responses}with dual auth (Authorization= subscription,x-litellm-api-key= gateway), whitelisted upstream headers, and credential redaction in passthrough logs. Inference routes block caller-suppliedchatgpt_auth_file; proxy pre-call wiring forwards scoped ChatGPT OAuth headers only tochatgpt.Includes a cookbook, OpenAPI snapshot updates, and v1.106.8 bump (backport of main subscription-forwarding work).
Reviewed by Cursor Bugbot for commit 731bfff. Bugbot is set up for automated code reviews on this repo. Configure here.