Skip to content

feat(chatgpt): support per-model chatgpt_auth_file for multiple ChatGPT accounts - #41928

Closed
devin-ai-integration[bot] wants to merge 11 commits into
mainfrom
litellm_chatgpt_multi_account
Closed

devin-ai-integration[bot] wants to merge 11 commits into
mainfrom
litellm_chatgpt_multi_account

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Use several ChatGPT accounts in one LiteLLM proxy, with a separate saved login for each model deployment. This refresh preserves the original contributor's work, brings it onto current main, and restricts account selection to proxy administrators

Details

TLDR

Problem this solves:

  • ChatGPT deployments share one process-wide login
  • Selecting another model cannot select another account

How it solves it:

  • Assign an auth file to each deployment
  • Keep tokens and account headers paired across both APIs
  • Restrict server-side credential selection to proxy administrators

Intentional product change: compared with the earlier PR revision, delegated model managers cannot select or replace a server-owned ChatGPT auth file; proxy administrators own that operation, and request-level credential opt-in cannot override it

User Flow

Before: two configured accounts still send requests through the default login

  1. Configure account-a and account-b aliases with separate saved logins
  2. Send POST http://localhost:4000/v1/chat/completions with model account-b and a greeting request
  3. Receive HTTP 200, but the default account supplies the answer
  4. Repeat through POST http://localhost:4000/v1/responses and observe the same account

After: each alias uses its configured account

  1. Configure account-a and account-b aliases with separate saved logins
  2. Send POST http://localhost:4000/v1/chat/completions with model account-b and a greeting request
  3. Receive HTTP 200 with the configured account-b credentials used upstream
  4. Repeat through POST http://localhost:4000/v1/responses and observe account-b
  5. Other callers cannot select a server auth file through request parameters

Relevant issues

Fixes #23777; continues the original implementation from #33680 and preserves this PR's contributor history

Pre-Submission checklist

  • Added meaningful account-isolation and permission tests
  • Focused tests pass: 2,829 passed, 260 warnings; an additional Responses-focused run passed 2,884 tests before the final auth-gate change
  • All required CI/CD checks pass on the latest commit
  • Scope stays limited to per-deployment ChatGPT accounts
  • Automated reviews on the latest tip are complete; the prior 3fb2f3bf91c review was Greptile 5/5 and Bugbot clean

Current tip: 5cdc4c5a82f13c0420553b4eb147e2c4cca132e9. make check passes on this committed tip. Fresh automated reviews and current-tip CI are pending

Compatibility and Test Connection

#41522 includes this revision and adds client-owned ChatGPT login forwarding. Its combined live account-selection matrix covers stored accounts, caller overrides, client-only setup, streaming, and routing groups

Admins can test an unsaved chatgpt_auth_file using /health/test_connection. Non-admin probes return 403 before provider dispatch. This was checked on a real PostgreSQL-backed proxy with client-side credentials both disabled and enabled; the outgoing bearer and account header matched account-b in every successful admin probe

The live probe also exposed an existing ChatGPT Responses limitation: string input was forwarded unchanged and OpenAI rejected it with Input must be a list. The adapter now normalizes plain text to a user message while preserving list input. The regression test checks the outgoing shape and selected credential pair. This normalization overlaps #38086; its structured-output fix remains relevant, and this PR does not close #38085

The current ChatGPT and health-endpoint run passes 384 tests. The earlier evidence below remains labeled with the revision on which it ran

Screenshots / Proof of Fix

Live proxy requests used two distinct saved ChatGPT logins and GPT-6 Luna, with identical configuration on both revisions. An observer around the real HTTP transport compared the outgoing token and account header with the selected local record, recording only account-a/account-b labels; it forwarded requests unchanged and used no mocked provider responses. The isolated loopback QA proxy disabled master-key enforcement; the example below uses normal gateway authentication

Shared configuration, with illustrative paths:

model_list:
  - model_name: account-a
    litellm_params:
      model: chatgpt/gpt-6-luna
      chatgpt_auth_file: /app/auth/account-a/auth.json
  - model_name: account-b
    litellm_params:
      model: chatgpt/gpt-6-luna
      chatgpt_auth_file: /app/auth/account-b/auth.json
  - model_name: subscription-pool
    litellm_params:
      model: chatgpt/gpt-6-luna
      chatgpt_auth_file: /app/auth/account-a/auth.json
  - model_name: subscription-pool
    litellm_params:
      model: chatgpt/gpt-6-luna
      chatgpt_auth_file: /app/auth/account-b/auth.json
  - model_name: default-login
    litellm_params:
      model: chatgpt/gpt-6-luna
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

The default login points to account-a. Both payloads request “Reply with exactly the word Hello” with no output-token cap

Before (72f1ac4)

Chat Completions

  1. Send the following request for account-a, then account-b

    curl http://localhost:4000/v1/chat/completions \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"account-b","messages":[{"role":"user","content":"Reply with exactly the word Hello"}]}'
  2. Both return HTTP 200 and Hello; outgoing credential pairs both match account-a

Responses

  1. Send the following request for account-a, then account-b, then default-login

    curl http://localhost:4000/v1/responses \
      -H "Authorization: Bearer $LITELLM_MASTER_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"model":"account-b","input":[{"role":"user","content":"Reply with exactly the word Hello"}]}'
  2. All return HTTP 200 and Hello; outgoing credential pairs all match account-a

Streaming model group

  1. Repeat both endpoint requests with model subscription-pool and "stream":true
  2. Both return HTTP 200, Hello, and a completion event; both use account-a

Request-level credential selectors

  1. On a real PostgreSQL-backed proxy, create an internal user through POST /user/new and use its returned key
  2. Send both endpoint payloads with a top-level chatgpt_auth_file, then with that selector in extra_body; repeat with allow_client_side_credentials false and true
  3. Top-level selectors and nested Chat Completions selectors return 200 using the default account; nested Responses selectors return 400 after reaching provider validation

Model-management permissions

  1. POST /model/new as the proxy administrator with a configured auth file
  2. Observe HTTP 200 with a model ID, then repeat creation and PATCH /model/{model_id}/update as the internal user
  3. Both non-admin writes return HTTP 403 for the existing role restriction, without naming the auth-file field; this does not establish that baseline permits delegated credential writes

Saved prompts without a usable default directory

  1. Keep explicit account files, remove the default-login deployment, set the default token directory beneath an ordinary file, and register a local Dotprompt named account-check
  2. Send both endpoint requests for both aliases with "prompt_id":"account-check"
  3. All four return HTTP 400 with no outgoing provider requests

After (2bfb569)

Chat Completions

  1. Repeat the same Chat Completions request for account-a, then account-b
  2. Both return HTTP 200 and Hello; outgoing credential pairs match account-a and account-b respectively

Responses

  1. Repeat the same Responses request for account-a, then account-b, then default-login
  2. All return HTTP 200 and Hello; outgoing credential pairs match account-a, account-b, and account-a respectively

Streaming model group

  1. Repeat both endpoint requests with model subscription-pool and "stream":true
  2. Both return HTTP 200, Hello, and a completion event; this run selected account-a for both requests

Request-level credential selectors

  1. Repeat both endpoints, both selector locations, and both client-side-credential settings against the PostgreSQL-backed proxy
  2. All eight return HTTP 401 with an error naming chatgpt_auth_file, before a provider request

Model-management permissions

  1. Repeat POST /model/new as the proxy administrator with a configured auth file
  2. Observe HTTP 200 with a model ID, then repeat creation and PATCH /model/{model_id}/update as the internal user
  3. Both non-admin writes return HTTP 403 naming chatgpt_auth_file, with client-side credentials disabled and enabled

Saved prompts without a usable default directory

  1. Repeat the four saved-prompt requests with the same unusable default token directory
  2. All four return HTTP 200 and Hello; outgoing credential pairs match the selected account for both APIs
  3. The outgoing bodies contain the saved prompt, confirming the real prompt callback ran

No outgoing provider body contained the auth-file selector. The streaming sample proves the model group works, not statistical balancing; the explicit aliases prove both accounts independently

The original four request-path regression cases fail on the base and pass on the tip. The expanded matrix covers saved prompts and an unusable default token directory too. They exercise concurrent SDK and Router calls through Chat Completions and Responses with no default login, mocking only the external HTTP response

The official Dockerfile builds successfully from 2bfb5692166. A container using writable mounted auth directories, a generated gateway key, and one worker returned HTTP 200 with Hello for both accounts through both APIs. This container check verifies responses; the transport-observed account pairing above comes from the local proxy run

Remaining CI evidence

The compatibility and types-shard jobs passed on the prior commit, 3fb2f3bf91c. Current-tip CI is pending

The tokenizer timing assertion failed again on 3fb2f3bf91c (0.115s during a 0.422s count). It also fails on the exact main base: 0.128s event-loop stall against its 0.100s threshold. Equivalent local runs reproduce it on base (0.120s) and tip (0.123s), using the same environment and identical Rust sources. This PR does not change that tokenizer or test

The dependency scanner flags filelock and the VS Code extension's development dependency on msal-node in unchanged lockfiles. These required checks remain unresolved; they are not counted as passing

Documentation

Separate draft documentation PRs are prepared for merging after this feature:

Type

New Feature

Caveats

Severe

  • Proxy administrators own server-side ChatGPT credential selection

Medium

  • Model access still depends on each account's plan
  • Existing refresh-file concurrency limitations remain; use one local process
  • Routing does not track remaining subscription allowances

The second account rejects GPT-6.1 Sol but accepts GPT-6 Luna. The final paired live run uses GPT-6 Luna for both accounts

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

Note

Medium Risk
Changes OAuth credential selection and proxy auth rules for ChatGPT; misconfiguration could route requests under the wrong account, but request-level credential override is explicitly blocked.

Overview
Adds a chatgpt_auth_file deployment parameter so each ChatGPT model alias can use its own OAuth auth.json, with cached per-path authenticators driving bearer tokens and account headers for chat and Responses.

Routing and SDK: litellm_params (including chatgpt_auth_file) is passed into ChatGPT provider resolution and Responses bridging/prompt paths so the correct subscription is chosen end-to-end.

Proxy hardening: chatgpt_auth_file is treated as server-owned credentials—blocked on inference and nested request bodies, writable only by proxy admins on model config; /health/test_connection can probe an unsaved file for admins.

Responses fix: Plain-string input is wrapped as a user message list before upstream calls (health probes and API compatibility).

Reviewed by Cursor Bugbot for commit 5cdc4c5. Bugbot is set up for automated code reviews on this repo. Configure here.

…PT accounts

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

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

@codspeed

codspeed Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 35 untouched benchmarks


Comparing litellm_chatgpt_multi_account (5cdc4c5) with main (72f1ac4)1

Open in CodSpeed

Footnotes

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

@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed changes appear safe to merge; account-file probes remain administrator-only, and string input keeps its text.

Summary

Adds per-deployment ChatGPT accounts across Chat Completions and Responses.

  • ChatGPT deployments can use separate saved accounts on both APIs.
  • Only proxy administrators can choose server-side ChatGPT account files.

Reviews (9) · Last reviewed commit: "fix(chatgpt): normalize subscription hea..." · Reviewed by Greptile

Comment thread litellm/llms/chatgpt/authenticator.py Resolved
… test docstring

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

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.

Stale Bugbot comment from a previous run.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

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.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…cator

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

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.

Stale Bugbot comment from a previous run.

@moe-berri

Copy link
Copy Markdown
Contributor

@greptileai Please review the updated multi-account ChatGPT implementation, particularly credential isolation, proxy permissions, and compatibility with current routing paths

@moe-berri

Copy link
Copy Markdown
Contributor

bugbot run
Please review this revision for account mixing, client-controlled auth-file selection, and regressions in ChatGPT request routing

@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.

Stale Bugbot comment from a previous run.

@moe-berri

Copy link
Copy Markdown
Contributor

@greptileai please review 2bfb569. Saved-prompt routing, lazy auth-directory creation, parameter inventories, and administrator configuration are fixed and verified.

@moe-berri

Copy link
Copy Markdown
Contributor

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.

Stale Bugbot comment from a previous run.

@moe-berri

Copy link
Copy Markdown
Contributor

@greptileai please review 3fb2f3b. The remaining test mutation is removed; runtime code is unchanged and local checks pass

@moe-berri

Copy link
Copy Markdown
Contributor

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.

Stale Bugbot comment from a previous run.

@moe-berri

Copy link
Copy Markdown
Contributor

@greptileai Please review commit 5cdc4c5 for administrator probe permissions and string input normalization, including compatibility with the client forwarding PR.

@moe-berri

Copy link
Copy Markdown
Contributor

bugbot run Please review commit 5cdc4c5, especially account selection and administrator authorization when testing unsaved ChatGPT configurations.

@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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5cdc4c5. Configure here.

@mateo-berri

Copy link
Copy Markdown
Contributor

Superseded by #41522, which merged on Oct 26 and includes this PR's per-model chatgpt_auth_file support and the admin-only gate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants