Skip to content

feat(chatgpt): backport #41522 client subscription forwarding to stable/1.106.x for v1.106.8 - #49888

Merged
yuneng-berri merged 9 commits into
stable/1.106.xfrom
litellm_backport_41522_stable_1_106_x
Nov 11, 2026
Merged

yuneng-berri merged 9 commits into
stable/1.106.xfrom
litellm_backport_41522_stable_1_106_x

Conversation

@jesus-berri

@jesus-berri jesus-berri commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Backport of #41522 to stable/1.106.x, shipping as v1.106.8

Problem this solves:

  • Codex users behind the gateway spend the gateway's ChatGPT subscription, not their own
  • Native /backend-api/codex/* requests through the gateway return 404 on 1.106

How it solves it:

User Flow

Before: a developer on a 1.106 gateway gets billed on the gateway's ChatGPT account

  1. The proxy admin configures model: chatgpt/gpt-* with a saved gateway login
  2. A developer signs into their own ChatGPT account in Codex and points it at the gateway with their LiteLLM key
  3. They POST https://litellm-domain/v1/responses and the answer is billed to the gateway account

After: the same request runs on the developer's own subscription

  1. The proxy admin configures model: chatgpt/gpt-* with a saved gateway login
  2. A developer signs into their own ChatGPT account in Codex and points it at the gateway with their LiteLLM key
  3. They POST https://litellm-domain/v1/responses and the answer is billed to their own ChatGPT account, and GET https://litellm-domain/backend-api/codex/models lists their subscription's models

Relevant 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

  • feat(chatgpt): forward client subscriptions through the gateway #41522 cherry-picked from its main squash commit 2e27a02 as one commit (129e2d6), with the squash SHA and the original main author recorded in the commit message. The commit author is the PR author so the CLA check can match a signer, since the bot author on main has not signed it
  • Same 43 files as the main squash. Only the added and removed lines were compared, file by file, and every difference is an adaptation to helpers the line has
    • reject_server_owned_wif_params in place of reject_server_owned_wif_fields, with the same exemption of chatgpt_auth_file on deployment-management routes
    • getattr in place of attribute_or_none, which the line does not have
    • acompletion and responses pass the request's extra_headers and provider_specific_header into provider detection through the line's GenericLiteLLMParams call shape
    • pass_through_request gains the upstream_headers_filter argument from feat(vertex_ai): let operators drop chosen anthropic-beta values on the Vertex AI pass-through routes #47185
    • one picked test about oidc/ api_key references is dropped because that feature is not on the line
  • Earlier revisions of this PR carried five extra hardening fixes that are not on main. They were reverted here so the line matches main, and they go to main first in their own PR, then get backported from there
  • One fix is back on top of the pick (731bfff) because it closes a gap that main does not have. A forwarded ChatGPT bearer gets its own per-request deployment, and on this line that deployment's id hashed the bearer and registered a litellm.model_cost entry that was never removed, so every distinct token grew the worker's memory (the Veria finding on litellm/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 deployment
  • One more fix on top (3b51173) is a partial pick of feat(usage): show subscription-covered providers and account fees separately #44772 (b8283d8 on main). feat(chatgpt): forward client subscriptions through the gateway #41522 relied on its declared_authenticating_provider short-circuit in provider_stores_the_conversation, and without it a chatgpt/* deployment with chatgpt_auth_file on 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 test test_a_chatgpt_responses_row_queues_without_a_default_chatgpt_login, which fails at 731bfff with the ChatGPT GetAccessTokenError and passes at 3b51173. tests/unit/proxy/db/test_db_spend_update_writer.py, tests/unit/responses/ and tests/unit/llms/chatgpt/ pass at 3b51173, 1409 passed
  • Merged with the current stable/1.106.x tip 25fc8bf. The final tree is byte-identical to the pick plus the bump applied straight onto that tip
  • pyproject.toml and uv.lock bumped to 1.106.8 in their own commit, one above the v1.106.7 release. No enterprise/ or litellm-proxy-extras/ changes, so no subpackage bump
  • The 15 test files the pick touches pass on the line at 19ab60e (same tree as 3d2263d, only the pick's author changed), 4728 passed and 11 skipped. The 4 failures are TestAutoRouterTraceProvenance tests that fail the same way on the untouched stable/1.106.x tip
  • ruff format --check flags the same 10 files on the line before and after the pick, so nothing new

Screenshots / 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-mini were not run for this revision

The 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 in Authorization plus the gateway key in x-litellm-api-key, so ChatGPT answers invalid_issuer without 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 dropped

for jwt in $JWT_1 $JWT_2 $JWT_3; do
  curl -s http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $jwt" -H "x-litellm-api-key: $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gpt-5.4","messages":[{"role":"user","content":"say ok"}]}'
done
curl -s http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gpt-5.4","messages":[{"role":"user","content":"say ok"}]}'
# select model_id from "LiteLLM_SpendLogs" where request_id = '<x-litellm-call-id>'

Before (3d2263d)

  1. Three forwarded logins -> HTTP 401 invalid_issuer each, spend rows on three different deployment ids (3df8babf..., 0e55f575..., 62e165ff...), one new cost-map entry per token
  2. Gateway key only -> HTTP 401 invalid_issuer, spend row on the configured deployment aa14d2a0...

After (731bfff)

  1. Three forwarded logins -> HTTP 401 invalid_issuer each, all three spend rows on one shared deployment id 5750fcf2...
  2. Gateway key only -> HTTP 401 invalid_issuer, spend row still on aa14d2a0..., so a forwarded login's errors stay off the gateway deployment

Type

🆕 New Feature

Caveats (if any)

Severe

High

Medium

  • Copied from feat(chatgpt): forward client subscriptions through the gateway #41522
    • No automatic fallback to another gateway ChatGPT subscription
    • No dashboard login or server-managed client token refresh
    • Native compatibility supports HTTP and SSE, not WebSockets
    • Real quota exhaustion and workspace billing remain unverified
    • Encrypted-history replay across accounts remains unverified

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 gains chatgpt_auth_file for 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-supplied chatgpt_auth_file; proxy pre-call wiring forwards scoped ChatGPT OAuth headers only to chatgpt.

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.

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.
@jesus-berri
jesus-berri requested a review from a team November 3, 2026 16:24
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

CLAassistant commented Nov 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Comment thread litellm/router.py Resolved
@veria-ai

veria-ai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

This 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
@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[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

  1. P2 Successful live proof is missing ▶

Summary

Backports client ChatGPT subscription forwarding and native Codex routes to stable/1.106.x for 1.106.8

  • ChatGPT requests can use the caller’s own subscription through LiteLLM.
  • Codex clients can use native model-list and response routes through LiteLLM.
  • Forwarded ChatGPT logins reuse one deployment entry per configured deployment.

Reviews (2) · Last reviewed commit: "fix(chatgpt): stop forwarded ChatGPT log..." · Reviewed by Greptile

Comment thread litellm/responses/utils.py Resolved
Comment on lines +80 to +86
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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a backport of #41522, whose live proof covers these routes. A live run on this line's tip is still owed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@jesus-berri jesus-berri changed the title feat(chatgpt): backport #41522 client subscription forwarding to stable/1.106.x feat(chatgpt): backport #41522 client subscription forwarding to stable/1.106.x for v1.106.8 Nov 10, 2026
Comment thread litellm/router.py
if deployment_provider in _FORWARDED_CREDENTIAL_ISOLATION_PROVIDERS
else None
)
if is_clientside_credential(request_kwargs=kwargs) or forwarded_authorization is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Real, and main has the same path. This backport mirrors #41522, so the fix goes to main first and comes here after

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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
@jesus-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

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
@yuneng-berri
yuneng-berri merged commit 97a519b into stable/1.106.x Nov 11, 2026
6 of 7 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_backport_41522_stable_1_106_x branch November 11, 2026 20:32
pocharlies pushed a commit to pocharlies-org/litellm that referenced this pull request Nov 12, 2026
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.

This branch was successfully deployed

No deployments
e2e-changed — 3b51173d Deployed Nov 11, 2026 by jesus-berri via oauth #6108
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.

3 participants