Skip to content

feat(proxy): add per-user ChatGPT subscription passthrough - #46684

Closed
dm3ch wants to merge 4 commits into
BerriAI:mainfrom
dm3ch:litellm_chatgpt_subscription_passthrough
Closed

dm3ch wants to merge 4 commits into
BerriAI:mainfrom
dm3ch:litellm_chatgpt_subscription_passthrough

Conversation

@dm3ch

@dm3ch dm3ch commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Developers can use their locally signed-in ChatGPT subscription through LiteLLM without putting an OpenAI API key on the proxy. The client keeps login and token refresh, while a separate LiteLLM key controls gateway access and usage attribution

Details

TLDR

Problem this solves

  • Native ChatGPT subscription clients cannot use existing OpenAI API passthrough

How it solves it

  • Adds authenticated native catalog and Responses HTTP/SSE routes
  • Keeps subscription login and refresh in the client
  • Separates gateway credentials from subscription credentials
  • Reuses shared forwarding, decompression, credential filtering, and Responses accounting
  • Preserves upstream background billing and resumed-stream model detection

Intentional product change: passthrough logs and response-header callbacks receive redacted credential headers instead of raw credentials

User Flow

Before, the locally signed-in client cannot send a subscription prompt through the gateway

  1. Sign into ChatGPT in Codex and configure the gateway URL and a separate LiteLLM virtual key
  2. Send a prompt to POST http://localhost:4000/backend-api/codex/responses and receive 404 Not Found
  3. Open http://localhost:4000/ui/?page=logs and find no completed subscription response with token usage

After, the same client receives a subscription response attributed to its gateway identity

  1. Sign into ChatGPT in Codex and configure the gateway URL and a separate LiteLLM virtual key
  2. Send the same prompt to POST http://localhost:4000/backend-api/codex/responses and receive the streamed answer
  3. Open http://localhost:4000/ui/?page=logs to inspect the gateway user, key alias, model, and token usage

Relevant issues

Fixes #46062

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible and solves one problem
  • Every automated review on my PR's latest commit has finished and its findings are addressed

Rebased onto f2118fc7, preserving #47171 Responses billing, background settlement markers, and resumed-stream model detection. The native subscription routes remain separate from existing API-key-backed OpenAI passthrough

At fa6f998c, make check BASE_REF=upstream/main passes, along with 3,532 selected unit tests and 16 fixed-host TLS integration cases. Compressed HTTP/SSE cases verify model restrictions, usage persistence, and credential isolation. The cancellation case observes reservation release and connection closure while the upstream remains blocked

Independent review caught a decoded gzip response being decoded again when creating a redacted callback copy. Two route regressions reproduced it before the fix and pass afterward. The follow-up review found no remaining issues in that scope

This PR adds no dependencies or decoder. It uses upstream's bounded gzip/zstd middleware from #47418 and its final outbound-header filter rather than adding another relay header switch

At fa6f998c, external unit, smoke, lint, schema sync, coverage upload, and Codecov patch checks pass. Two checks fail

  • OSV scan reports dependency advisories also present in the upstream run at f2118fc7. All three scanned lockfiles match upstream exactly
  • Python CodeQL exceeds its 2 GiB result-set limit in the log-injection query. This is an analysis failure, not a clean security result. Upstream's main-branch analysis passes, so this PR check remains unresolved

No current-tip Greptile, Veria, or Bugbot reviews are reported. Missing results are not approvals. The PR remains draft and no maintainer review is requested

Screenshots / Proof of Fix

Used interactive Codex CLI 0.163.0 with an existing real ChatGPT sign-in, gpt-6.1-sol, a separate per-user gateway key, and request compression enabled. Both local proxies used isolated PostgreSQL databases. No mock LLM provider was used. Terminal captures follow the previously approved proof format

Both runs used this client configuration, with credentials retained only in private client files and the gateway key supplied through the environment

model = "gpt-6.1-sol"
model_provider = "litellm_subscription"
model_reasoning_effort = "low"

[features]
enable_request_compression = true

[model_providers.litellm_subscription]
name = "LiteLLM subscription gateway"
base_url = "http://127.0.0.1:4000/backend-api/codex"
requires_openai_auth = true
supports_websockets = false
env_http_headers = { "x-litellm-api-key" = "LITELLM_GATEWAY_KEY" }

The interactive command was

codex --no-alt-screen -a never -s read-only \
  --enable enable_request_compression \
  'Reply exactly LITELLM_SUBSCRIPTION_OK. Do not use tools.'

Before (f2118fc)

Interactive subscription prompt

  1. Start the interactive Codex command against the upstream gateway
  2. Capture its pane with tmux capture-pane -p -S -160 -t pr46684-before and observe the failed native request
>_ OpenAI Codex (v0.163.0)
Reply exactly LITELLM_SUBSCRIPTION_OK. Do not use tools.
unexpected status 404 Not Found: {"detail":"Not Found"}
url: http://127.0.0.1:4000/backend-api/codex/responses

Native catalog

  1. Send GET http://127.0.0.1:4000/backend-api/codex/models?client_version=0.163.0 with the two separate credentials
  2. Observe 404 and {"detail":"Not Found"}

Gateway attribution

  1. Send the native prompt through the upstream gateway
  2. Observe the 404 failure, with no completed subscription response or token usage to attribute

After (fa6f998)

Interactive subscription prompt

  1. Start the identical interactive Codex command against the signed PR tip
  2. Capture its pane with tmux capture-pane -p -S -160 -t pr46684-after and observe the real subscription response
>_ OpenAI Codex (v0.163.0)
Reply exactly LITELLM_SUBSCRIPTION_OK. Do not use tools.
LITELLM_SUBSCRIPTION_OK
Worked for 9s
GPT-6.1-Sol low

Native catalog

  1. Send the identical authenticated catalog request
  2. Observe 200 and the native models array containing nine models, including the selected gpt-6.1-sol

Gateway attribution

  1. Read back the persisted completion and compare its usage with the Codex session's terminal usage event
  2. Observe matching input, output, and total token counts attributed to the separate gateway identity
user                           key_alias                      model          input  output  total
subscription-rebase-qa-after    subscription-rebase-qa-after   gpt-6.1-sol   11254      12  11266
  1. Observe a separate background title request with 9,117 input and 62 output tokens, attributed to the same gateway identity
  2. Scan proxy logs, terminal captures, and persisted metadata for the actual gateway and subscription credentials. No credential values were found

Type

New Feature

Caveats

Medium

  • Subscription WebSockets require HTTP/SSE fallback
  • Managed enterprise requirements configuration remains unverified
  • Deployments need standard proxy dependencies for zstd decoding

Low

  • Cost estimates do not represent subscription billing or quota
  • Two external checks fail, and bot review evidence is missing

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@CLAassistant

CLAassistant commented Oct 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 35 untouched benchmarks


Comparing dm3ch:litellm_chatgpt_subscription_passthrough (fa6f998) with main (f2118fc)

Open in CodSpeed

@dm3ch
dm3ch force-pushed the litellm_chatgpt_subscription_passthrough branch 2 times, most recently from e805443 to 89fa601 Compare October 15, 2026 22:56
@github-actions

Copy link
Copy Markdown
Contributor

#46062 was fixed by #41522 on main, so this pull request is closed. Reopen it if something was missed.

@github-actions github-actions Bot closed this Oct 26, 2026
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.

[Feature]: Per-user ChatGPT subscription passthrough for Codex-compatible clients

2 participants