Skip to content

feat(proxy): forward client ChatGPT subscriptions on native Codex routes - #48437

Closed
moe-berri wants to merge 2 commits into
mainfrom
litellm_codex_subscription_gateway
Closed

moe-berri wants to merge 2 commits into
mainfrom
litellm_codex_subscription_gateway

Conversation

@moe-berri

@moe-berri moe-berri commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Superseded by #41522. The native Codex implementation is included in that PR at 2123d9ddc6083f41f6458ab827a49c494522843f, alongside standard LiteLLM model forwarding. This PR is closed and should not be merged separately

Codex and Pi users can keep their ChatGPT login in their client and send subscription requests through LiteLLM. The gateway uses a separate virtual key for access and usage attribution, reusing the existing passthrough transport and logging

Details

TLDR

Problem this solves:

  • Native Codex subscription routes return 404 on the gateway
  • Client login and gateway access need separate credentials

How it solves it:

  • Forward native catalog and Responses requests to OpenAI
  • Authenticate the gateway key through existing proxy auth
  • Preserve HTTP/SSE, enforce model access, and record usage
  • Redact credential headers from shared passthrough logging

User Flow

Before: a signed-in Codex user cannot send subscription requests through the gateway

  1. Sign in to ChatGPT in Codex
  2. Set the provider URL to http://localhost:4000/backend-api/codex and supply a LiteLLM key through x-litellm-api-key
  3. Ask Codex to reply with Hello
  4. Codex reports 404 Not Found for /backend-api/codex/responses

After: the same user receives a response using their own subscription

  1. Sign in to ChatGPT in Codex
  2. Set the provider URL to http://localhost:4000/backend-api/codex and supply a LiteLLM key through x-litellm-api-key
  3. Ask Codex to reply with Hello
  4. Codex responds, and LiteLLM records token usage under the caller's gateway key

Relevant issues

Fixes #46062

This independently implements the native route scope requested in #46062. #41522 instead adds caller credential forwarding through routed model APIs and includes multiaccount provider changes. #46684 is an alternative native-route implementation, not a dependency of this PR

Documentation is coordinated with the setup guide and the subscription overview. Merge this implementation first, then the guide, then the overview

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
  • Every automated review on my PR's latest commit has finished

make check passes on the committed head. The new route tests and existing OpenAI passthrough logging tests pass, 82 tests. The earlier broader mapped run passed 1,312 tests and exposed one Azure logging regression that was corrected and retested in the final 82-test run

Screenshots / Proof of Fix

The comparison uses Codex 0.160.0, the same existing ChatGPT login, GPT-6 Luna with high reasoning, and the prompt Reply with exactly Hello. Do not use tools. Each proxy runs from its stated commit. The base listens on port 14124 and the candidate on port 14123, with a disposable Postgres database for candidate usage attribution

Provider setup, with the URL changed only to select the proxy under test:

model = "gpt-6-luna"
model_reasoning_effort = "high"
model_provider = "litellm_subscription"

[model_providers.litellm_subscription]
name = "LiteLLM subscription"
base_url = "http://localhost:4000/backend-api/codex"
wire_api = "responses"
requires_openai_auth = true
env_http_headers = { "x-litellm-api-key" = "LITELLM_API_KEY" }

Before (4c674e8)

Interactive Codex

  1. Export a gateway key as LITELLM_API_KEY, run codex --no-alt-screen, and enter the prompt above
  2. Codex reports unexpected status 404 Not Found: {"detail":"Not Found"}

Interactive Codex before

Native catalog

  1. Run curl -i http://localhost:14124/backend-api/codex/models
  2. The proxy returns 404 and {"detail":"Not Found"}

After (1ceca04)

Interactive Codex

  1. Export a gateway key as LITELLM_API_KEY, run codex --no-alt-screen, and enter the prompt above
  2. Codex replies Hello. and the gateway records the completed inference under demo-developer, with 11,845 input and 6 output tokens

Interactive Codex after

Watch the recorded setup and request flow. It reuses an existing login and omits browser sign-in. Terminal output is recorded, with idle time shortened

Native catalog

  1. Send GET /backend-api/codex/models with a ChatGPT bearer and separate x-litellm-api-key
  2. Both distinct live logins receive HTTP 200 and the native catalog, including the tested model

Additional live checks on this head used two distinct saved logins and generated gateway keys for separate test users. Both inference calls completed with 16 input and 5 output tokens, and both rejected a disallowed model with 403. The saved rows contained neither subscription token. An HTTP client observer confirmed each outgoing request carried its respective account token, with the gateway key and cookies absent

Pi 0.73.1's actual agent SDK also completed an SSE request at high reasoning. Its model metadata was extended locally to select GPT-6 Luna because that Pi release's bundled catalog predates the model. This is SDK evidence, not a claim that the interactive Pi CLI was recorded

Controlled regression tests cover missing and invalid gateway credentials, missing subscription credentials, header injection, request/body preservation, streaming usage, and upstream 401/403/429 without account fallback

Type

New Feature

Caveats

Medium

  • HTTP/SSE only; native WebSockets and other backend routes excluded
  • No account pooling, stored login, or dashboard onboarding
  • Gateway and ChatGPT identities are independently authenticated
  • Enterprise reporting and forced token refresh were not live-tested
  • Quota errors were controlled tests, not deliberate subscription exhaustion

Low

  • Native catalog visibility does not grant inference permissions
  • ChatGPT dollar budgets do not measure subscription allowances

Final Attestation

  • Regressions in all real-world use cases are impossible

The tested behaviors and limits are stated above; no universal regression guarantee is claimed

@codspeed

codspeed Bot commented Oct 26, 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 litellm_codex_subscription_gateway (1ceca04) with main (1ecc782)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (85871f7) during the generation of this report, so 1ecc782 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

1 participant