Skip to content

feat(provider): add chatgpt provider with ChatGPT account sign-in#3512

Merged
dgageot merged 3 commits into
mainfrom
feat/chatgpt-provider
Jul 8, 2026
Merged

feat(provider): add chatgpt provider with ChatGPT account sign-in#3512
dgageot merged 3 commits into
mainfrom
feat/chatgpt-provider

Conversation

@Sayt-0

@Sayt-0 Sayt-0 commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

Adds a chatgpt model provider that uses a ChatGPT Plus/Pro/Business subscription instead of an OPENAI_API_KEY, via the same OAuth PKCE flow as OpenAI's Codex CLI. The sign-in runs from docker agent setup (picking chatgpt opens the browser flow, no new command); the access token is refreshed transparently and surfaces through the standard credential machinery (doctor, setup, auto selection, first_available).

How it works

docker agent setup  (pick chatgpt)
        |  (browser, OAuth PKCE, auth.openai.com, localhost:1455 callback)
        v
<config-dir>/chatgpt-auth.json  (0600, auto-refresh)
        |
        v
"chatgpt-login" env source  ->  virtual CHATGPT_OAUTH_TOKEN variable
        |
        +-> doctor / setup / auto selection / first_available / preflight (generic)
        +-> chatgpt provider (OpenAI client + per-request middleware:
            Authorization, chatgpt-account-id, OpenAI-Beta, originator, session_id)

Serving the login as a virtual env var lets every env-var-driven consumer work without special cases, while an explicitly set CHATGPT_OAUTH_TOKEN (e.g. a pre-minted token in CI) keeps precedence over the stored sign-in.

Changes

Area Change
pkg/chatgpt (new) PKCE login flow, credential store, token refresh, JWT claims parsing
chatgpt provider OpenAI-compatible alias; Responses API pinned (the backend has no chat-completions endpoint)
doctor chatgpt credential row (source chatgpt-login) and a sign-in hint in issues; shows sign-in state (account row)
setup picking chatgpt runs the browser sign-in and stores the OAuth credential (single entry point, no separate auth command)
auto selection chatgpt ordered right after openai, so behavior is unchanged for existing API-key users; default model gpt-5.2
missing-env errors sign-in hint when CHATGPT_OAUTH_TOKEN is missing
security token excluded from eval-container credential forwarding; the store is never touched under go test without an explicit override
docs + example provider page, overview/concepts/configuration tables, JSON schema, examples/chatgpt.yaml

Signing out is removing <config-dir>/chatgpt-auth.json; sign-in state shows up in docker agent doctor.

Request shape (Codex backend)

Backend constraint Handling
Responses API only chat-completions requests are routed to /responses; an explicit api_type override is ignored (debug-logged)
store must be false forced
instructions required system messages are concatenated into the field, with a default fallback
sampling params rejected temperature, top_p, max_output_tokens dropped (debug-logged)
workspace account header chatgpt-account-id parsed from the JWT claims

Validation

Check Result
go build ./... and js/wasm build of touched packages pass
go test ./... pass (4 pre-existing environmental failures, identical on a clean tree)
golangci-lint run, go run ./lint ., go mod tidy --diff clean
docs markdownlint + canonical check pass

26 new tests cover the OAuth mechanics (fake issuer: PKCE parameters, state validation, code exchange, refresh and token rotation), request shaping (fake Codex backend: endpoint, headers, instructions extraction, multi-turn tool calls), and doctor/setup/auto integration.

Notes

  • The localhost callback port (1455) and the client ID are fixed by OpenAI's OAuth client registration for Codex CLI; the flow cannot use a random port.
  • Live verification against the real backend needs a ChatGPT account and a browser. The request contract mirrors Codex CLI and known-working open-source integrations; backend errors surface with the full response body (the error-body middleware applies), so any live-contract adjustment stays localized to pkg/model/provider/openai/chatgpt.go.
  • Embeddings and reranking are not served by the Codex backend (documented on the provider page).

Adds a chatgpt model provider that uses a ChatGPT Plus/Pro/Business
subscription instead of an OPENAI_API_KEY, via the same OAuth PKCE flow
as OpenAI's Codex CLI. `docker agent auth login chatgpt` stores the
credential; the access token is refreshed transparently and exposed to
credential detection (doctor, setup, auto selection, first_available)
as the virtual CHATGPT_OAUTH_TOKEN variable served by a new
chatgpt-login environment source. Requests target the ChatGPT Codex
backend (Responses API only) with the required headers and request
shape.
@Sayt-0 Sayt-0 requested a review from a team as a code owner July 7, 2026 14:22
@aheritier aheritier added area/cli CLI commands, flags, output formatting area/config For configuration parsing, YAML, environment variables area/docs Documentation changes area/providers/openai For features/issues/fixes related to the usage of OpenAI models kind/feat PR adds a new feature (maps to feat:). Use on PRs only. labels Jul 7, 2026
Sayt-0 added 2 commits July 8, 2026 10:00
The chatgpt provider is a docker-agent alias for the ChatGPT Codex
backend; models.dev catalogs its models under the "openai" id, so
TestParseExamples fails to resolve chatgpt/gpt-5.2. Add chatgpt to the
modelsDevAbsentProviders skip map, like other aliases absent from the
catalog.
The auth command group (login/logout/status) added a whole command tree
for a single provider. The setup wizard already runs the browser sign-in
when chatgpt is picked, so it becomes the only entry point:

- remove `docker agent auth` and its tests
- point every sign-in hint (doctor, missing-env errors, token refresh,
  auto-selection) at `docker agent setup`
- document sign-in status via doctor and sign-out as removing
  chatgpt-auth.json
@dgageot dgageot merged commit e135779 into main Jul 8, 2026
16 checks passed
@dgageot dgageot deleted the feat/chatgpt-provider branch July 8, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli CLI commands, flags, output formatting area/config For configuration parsing, YAML, environment variables area/docs Documentation changes area/providers/openai For features/issues/fixes related to the usage of OpenAI models kind/feat PR adds a new feature (maps to feat:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants