Skip to content

Add ChatGPT subscription provider via OAuth 2.0 PKCE - #53166

Merged
rtfeldman merged 39 commits into
mainfrom
feat/chatgpt-subscription-provider
May 14, 2026
Merged

rtfeldman merged 39 commits into
mainfrom
feat/chatgpt-subscription-provider

Conversation

@morgankrey

Copy link
Copy Markdown
Contributor

Adds a new language model provider that lets users authenticate with their ChatGPT Plus/Pro subscription and use OpenAI models (codex-mini-latest, o4-mini, o3) directly in the Zed agent — without needing a separate API key.

How it works

  1. OAuth 2.0 + PKCE sign-in: Uses OpenAI's official Codex CLI client ID to run an authorization code flow. A local HTTP server on 127.0.0.1:1455 captures the callback, exchanges the code for tokens, and stores them in the system keychain.

  2. Token refresh: Access tokens are automatically refreshed when they're within 5 minutes of expiry, using the stored refresh token.

  3. Responses API: Requests go to https://chatgpt.com/backend-api/codex/responses using the existing open_ai::responses client (Responses API format, not Chat Completions which was deprecated for this endpoint in Feb 2026).

  4. Required headers: originator: zed, OpenAI-Beta: responses=experimental, ChatGPT-Account-Id (extracted from JWT), store: false in the body.

Files changed

  • crates/open_ai/src/responses.rs: Add store: Option<bool> field to Request; add extra_headers param to stream_response for per-provider header injection
  • crates/language_models/src/provider/openai_subscribed.rs: New provider (sign-in UI, OAuth flow, token storage/refresh, model list)
  • crates/language_models/src/provider/open_ai.rs, open_ai_compatible.rs, opencode.rs: Pass vec![] for new extra_headers param
  • crates/language_models/src/language_models.rs: Register the new provider
  • crates/language_models/Cargo.toml: Add rand and sha2 deps for PKCE

Open questions / known gaps

  • Terms of service: Usage appears to be within OpenAI's ToS (interactive use via their official CLI client ID), but needs legal sign-off before shipping
  • Redirect URI: Currently http://localhost:1455/auth/callback — may need to match exactly what OpenAI's Codex CLI uses
  • UI polish: The sign-in card is functional but minimal; needs design review
  • Error messages: OAuth error responses from the callback URL aren't surfaced to the user yet
  • o3 availability: o3 may require a higher subscription tier; consider gating it

Testing

Sign-in flow was designed to match the Copilot Chat provider pattern. Manual testing against the live OAuth endpoint is needed.

Release Notes:

  • Added ChatGPT subscription provider, allowing users to use their ChatGPT Plus/Pro subscription with the Zed agent

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 4, 2026
@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label Apr 4, 2026
morgankrey and others added 23 commits April 6, 2026 14:47
Adds a new language model provider that authenticates users with their
ChatGPT Plus/Pro subscription using OpenAI's Codex CLI OAuth client,
then routes requests to chatgpt.com/backend-api/codex/responses.

- New openai_subscribed provider with OAuth PKCE sign-in flow
- Stores credentials in the system keychain (access + refresh tokens)
- Auto-refreshes tokens within 5 minutes of expiry
- Exposes codex-mini-latest, o4-mini, and o3 models
- Adds `store` field and `extra_headers` param to Responses API client
- Propagate refreshed credentials to in-memory State immediately after
  persisting, so subsequent requests don't redundantly refresh again
- Clear sign_in_task when keychain write fails during OAuth, so the
  UI doesn't get stuck in a permanent "Signing in..." state
…vider

- Replace the hardcoded CodexModel enum (3 models) with open_ai::Model,
  so all standard OpenAI models appear in the dropdown after signing in.
- Add o4-mini as a proper variant in open_ai::Model.
- Keep codex-mini-latest as a Custom model entry.
- Add instructions field to responses::Request and extract system
  messages into it for the Codex backend (fixes 'Instructions are
  required' error).
- Delegate to open_ai::Model for supports_images, max_output_tokens,
  count_tokens, and supports_parallel_tool_calls instead of hardcoding.
The Codex backend (chatgpt.com/backend-api/codex) only supports a subset
of OpenAI models. Replace the open_ai::Model::iter() approach with a
dedicated ChatGptModel enum listing only the models that work through
the Codex backend, based on Roo Code's Codex model catalog:

- gpt-5.4, gpt-5.4-mini
- gpt-5.3-codex, gpt-5.3-codex-spark
- gpt-5.2-codex, gpt-5.2
- gpt-5.1-codex-max, gpt-5.1-codex, gpt-5.1-codex-mini, gpt-5.1
- gpt-5-codex, gpt-5-codex-mini, gpt-5

Older models (gpt-3.5-turbo, gpt-4, o1, o3, etc.) and the deprecated
codex-mini-latest are removed since they aren't available through this
backend.
Multiple concurrent stream_completion calls seeing expired credentials
would all independently call refresh_token(). With OAuth rotating
refresh tokens, the first refresh invalidates the old token, causing
all subsequent concurrent refreshes to fail.

Add a Shared<Task> to State so the first caller to notice expiry
spawns the refresh task and subsequent callers join the same future.
If the user starts the sign-in flow but never completes it in the
browser, the TCP listener on port 1455 would block forever. Race
the accept against a 2-minute timer so the port is released and the
UI gets a meaningful error.
Replace hand-rolled format! string interpolation with
url::form_urlencoded::Serializer in exchange_code and refresh_token.
The previous code didn't percent-encode the code, verifier, or
refresh_token values, which would break if they contained &, =, or +.
Early-return if a sign-in task is already in progress. Without this,
a second call would drop the existing task (cancelling it while port
1455 may still be bound) and the new task could fail to bind.
Dropping sign_in_task prevents a completing OAuth flow from writing
credentials back into state after the user has signed out.
The ConfigurationView was duplicating sign-out logic (missing the
sign_in_task cancellation) and constructing a throwaway provider for
sign-in. Extract both into free functions so the provider and the
view share the same implementation.
The ConfigurationView shows 'Signed in as {email}' but the email
was never populated. OpenAI's token endpoint doesn't include email
at the top level — it's in the JWT id_token claims. Refactor
extract_account_id into extract_jwt_claims that parses the JWT once
and returns both account_id and email.
The hand-rolled percent_decode was incorrect for multi-byte UTF-8
(decoded each byte as an independent char). Use url::Url for building
the auth URL and form_urlencoded::parse for decoding the callback
query string. Remove both hand-rolled functions.
Previously a schema change or corruption would silently show the
user as signed out. Now a log::warn helps diagnose the issue.
If the system clock is before the UNIX epoch, the silent unwrap_or(0)
would cause broken credential expiry behavior. Now the error is
visible in logs.
A single read() could miss query parameters if the browser's HTTP
request is split across TCP segments. Read in a loop until the
header terminator is found.
Add http_client::oauth_callback_page() that generates a nicely styled
HTML page with Zed branding for OAuth callback responses. Use it in
both the ChatGPT subscription provider and the MCP context server
OAuth flow, replacing the unstyled inline HTML in both places.

The template is parameterized on title and message so both callers
get consistent styling that updates in one place.
smol::Timer::after is banned by a project-wide clippy lint. Pass
the AsyncApp through to await_oauth_callback so it can use
cx.background_executor().timer() instead.
@rtfeldman
rtfeldman force-pushed the feat/chatgpt-subscription-provider branch from 7d1af89 to 64069d5 Compare April 6, 2026 18:55
@rtfeldman
rtfeldman marked this pull request as ready for review April 6, 2026 19:11
The into_open_ai_response call was hardcoding
supports_parallel_tool_calls=true and supports_prompt_cache_key=false
instead of asking the model. This meant reasoning models like GPT-5
Codex variants would incorrectly send parallel_tool_calls=true,
which could cause API errors. Add the missing methods to ChatGptModel
and delegate like the standard OpenAI provider does.
Three tests covering get_fresh_credentials:
- test_concurrent_refresh_deduplicates: two concurrent callers with
  expired credentials only trigger one HTTP refresh call
- test_fresh_credentials_skip_refresh: fresh credentials return
  immediately with no HTTP call
- test_no_credentials_returns_no_api_key: missing credentials return
  the correct error variant
Two CI failures from 831c244 ("Extract OAuth callback server into
its own crate"):

- check_licenses: new crates need a LICENSE-{APACHE,GPL} symlink to
  the repo-root license file. Add LICENSE-APACHE symlink pointing to
  ../../LICENSE-APACHE, matching the crate's `license = "Apache-2.0"`
  metadata and the convention used by other Apache-licensed crates
  (e.g. http_client).

- check_dependencies (cargo machete): `smol` is unused in
  context_server since 24703c9 ("Drop smol::spawn from MCP OAuth
  callback wrapper"). Remove the now-unused workspace dep from
  context_server/Cargo.toml.
@rtfeldman
rtfeldman added this pull request to the merge queue May 14, 2026
Merged via the queue into main with commit 37f6d7a May 14, 2026
31 checks passed
@rtfeldman
rtfeldman deleted the feat/chatgpt-subscription-provider branch May 14, 2026 21:07
@probably-neb

Copy link
Copy Markdown
Collaborator

/cherry-pick preview
/cherry-pick stable

@zed-zippy

zed-zippy Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

zed-zippy Bot added a commit that referenced this pull request May 14, 2026
…-pick to preview) (#56807)

Cherry-pick of #53166 to preview

----
Adds a new language model provider that lets users authenticate with
their ChatGPT Plus/Pro subscription and use OpenAI models
(codex-mini-latest, o4-mini, o3) directly in the Zed agent — without
needing a separate API key.

## How it works

1. **OAuth 2.0 + PKCE sign-in**: Uses OpenAI's official Codex CLI client
ID to run an authorization code flow. A local HTTP server on
`127.0.0.1:1455` captures the callback, exchanges the code for tokens,
and stores them in the system keychain.

2. **Token refresh**: Access tokens are automatically refreshed when
they're within 5 minutes of expiry, using the stored refresh token.

3. **Responses API**: Requests go to
`https://chatgpt.com/backend-api/codex/responses` using the existing
`open_ai::responses` client (Responses API format, not Chat Completions
which was deprecated for this endpoint in Feb 2026).

4. **Required headers**: `originator: zed`, `OpenAI-Beta:
responses=experimental`, `ChatGPT-Account-Id` (extracted from JWT),
`store: false` in the body.

## Files changed

- `crates/open_ai/src/responses.rs`: Add `store: Option<bool>` field to
`Request`; add `extra_headers` param to `stream_response` for
per-provider header injection
- `crates/language_models/src/provider/openai_subscribed.rs`: New
provider (sign-in UI, OAuth flow, token storage/refresh, model list)
- `crates/language_models/src/provider/open_ai.rs`,
`open_ai_compatible.rs`, `opencode.rs`: Pass `vec![]` for new
`extra_headers` param
- `crates/language_models/src/language_models.rs`: Register the new
provider
- `crates/language_models/Cargo.toml`: Add `rand` and `sha2` deps for
PKCE

## Open questions / known gaps

- [ ] **Terms of service**: Usage appears to be within OpenAI's ToS
(interactive use via their official CLI client ID), but needs legal
sign-off before shipping
- [ ] **Redirect URI**: Currently `http://localhost:1455/auth/callback`
— may need to match exactly what OpenAI's Codex CLI uses
- [ ] **UI polish**: The sign-in card is functional but minimal; needs
design review
- [ ] **Error messages**: OAuth error responses from the callback URL
aren't surfaced to the user yet
- [ ] **`o3` availability**: o3 may require a higher subscription tier;
consider gating it

## Testing

Sign-in flow was designed to match the Copilot Chat provider pattern.
Manual testing against the live OAuth endpoint is needed.

Release Notes:

- Added ChatGPT subscription provider, allowing users to use their
ChatGPT Plus/Pro subscription with the Zed agent

---------

Co-authored-by: Zed Zippy
<234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>

Co-authored-by: morgankrey <morgan@zed.dev>
Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>
@probably-neb

Copy link
Copy Markdown
Collaborator

/cherry-pick stable

zed-zippy Bot added a commit that referenced this pull request May 14, 2026
…-pick to stable) (#56811)

Cherry-pick of #53166 to stable

----
Adds a new language model provider that lets users authenticate with
their ChatGPT Plus/Pro subscription and use OpenAI models
(codex-mini-latest, o4-mini, o3) directly in the Zed agent — without
needing a separate API key.

## How it works

1. **OAuth 2.0 + PKCE sign-in**: Uses OpenAI's official Codex CLI client
ID to run an authorization code flow. A local HTTP server on
`127.0.0.1:1455` captures the callback, exchanges the code for tokens,
and stores them in the system keychain.

2. **Token refresh**: Access tokens are automatically refreshed when
they're within 5 minutes of expiry, using the stored refresh token.

3. **Responses API**: Requests go to
`https://chatgpt.com/backend-api/codex/responses` using the existing
`open_ai::responses` client (Responses API format, not Chat Completions
which was deprecated for this endpoint in Feb 2026).

4. **Required headers**: `originator: zed`, `OpenAI-Beta:
responses=experimental`, `ChatGPT-Account-Id` (extracted from JWT),
`store: false` in the body.

## Files changed

- `crates/open_ai/src/responses.rs`: Add `store: Option<bool>` field to
`Request`; add `extra_headers` param to `stream_response` for
per-provider header injection
- `crates/language_models/src/provider/openai_subscribed.rs`: New
provider (sign-in UI, OAuth flow, token storage/refresh, model list)
- `crates/language_models/src/provider/open_ai.rs`,
`open_ai_compatible.rs`, `opencode.rs`: Pass `vec![]` for new
`extra_headers` param
- `crates/language_models/src/language_models.rs`: Register the new
provider
- `crates/language_models/Cargo.toml`: Add `rand` and `sha2` deps for
PKCE

## Open questions / known gaps

- [ ] **Terms of service**: Usage appears to be within OpenAI's ToS
(interactive use via their official CLI client ID), but needs legal
sign-off before shipping
- [ ] **Redirect URI**: Currently `http://localhost:1455/auth/callback`
— may need to match exactly what OpenAI's Codex CLI uses
- [ ] **UI polish**: The sign-in card is functional but minimal; needs
design review
- [ ] **Error messages**: OAuth error responses from the callback URL
aren't surfaced to the user yet
- [ ] **`o3` availability**: o3 may require a higher subscription tier;
consider gating it

## Testing

Sign-in flow was designed to match the Copilot Chat provider pattern.
Manual testing against the live OAuth endpoint is needed.

Release Notes:

- Added ChatGPT subscription provider, allowing users to use their
ChatGPT Plus/Pro subscription with the Zed agent

---------

Co-authored-by: Zed Zippy
<234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>

Co-authored-by: morgankrey <morgan@zed.dev>
Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>
Nkr1shna pushed a commit to neozed-industries/neo-zed that referenced this pull request May 15, 2026
…53166) (cherry-pick to stable) (zed-industries#56811)

Cherry-pick of zed-industries#53166 to stable

----
Adds a new language model provider that lets users authenticate with
their ChatGPT Plus/Pro subscription and use OpenAI models
(codex-mini-latest, o4-mini, o3) directly in the Zed agent — without
needing a separate API key.

## How it works

1. **OAuth 2.0 + PKCE sign-in**: Uses OpenAI's official Codex CLI client
ID to run an authorization code flow. A local HTTP server on
`127.0.0.1:1455` captures the callback, exchanges the code for tokens,
and stores them in the system keychain.

2. **Token refresh**: Access tokens are automatically refreshed when
they're within 5 minutes of expiry, using the stored refresh token.

3. **Responses API**: Requests go to
`https://chatgpt.com/backend-api/codex/responses` using the existing
`open_ai::responses` client (Responses API format, not Chat Completions
which was deprecated for this endpoint in Feb 2026).

4. **Required headers**: `originator: zed`, `OpenAI-Beta:
responses=experimental`, `ChatGPT-Account-Id` (extracted from JWT),
`store: false` in the body.

## Files changed

- `crates/open_ai/src/responses.rs`: Add `store: Option<bool>` field to
`Request`; add `extra_headers` param to `stream_response` for
per-provider header injection
- `crates/language_models/src/provider/openai_subscribed.rs`: New
provider (sign-in UI, OAuth flow, token storage/refresh, model list)
- `crates/language_models/src/provider/open_ai.rs`,
`open_ai_compatible.rs`, `opencode.rs`: Pass `vec![]` for new
`extra_headers` param
- `crates/language_models/src/language_models.rs`: Register the new
provider
- `crates/language_models/Cargo.toml`: Add `rand` and `sha2` deps for
PKCE

## Open questions / known gaps

- [ ] **Terms of service**: Usage appears to be within OpenAI's ToS
(interactive use via their official CLI client ID), but needs legal
sign-off before shipping
- [ ] **Redirect URI**: Currently `http://localhost:1455/auth/callback`
— may need to match exactly what OpenAI's Codex CLI uses
- [ ] **UI polish**: The sign-in card is functional but minimal; needs
design review
- [ ] **Error messages**: OAuth error responses from the callback URL
aren't surfaced to the user yet
- [ ] **`o3` availability**: o3 may require a higher subscription tier;
consider gating it

## Testing

Sign-in flow was designed to match the Copilot Chat provider pattern.
Manual testing against the live OAuth endpoint is needed.

Release Notes:

- Added ChatGPT subscription provider, allowing users to use their
ChatGPT Plus/Pro subscription with the Zed agent

---------

Co-authored-by: Zed Zippy
<234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>

Co-authored-by: morgankrey <morgan@zed.dev>
Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>
Nkr1shna pushed a commit to neozed-industries/neo-zed that referenced this pull request May 15, 2026
…53166) (cherry-pick to stable) (zed-industries#56811)

Cherry-pick of zed-industries#53166 to stable

----
Adds a new language model provider that lets users authenticate with
their ChatGPT Plus/Pro subscription and use OpenAI models
(codex-mini-latest, o4-mini, o3) directly in the Zed agent — without
needing a separate API key.

## How it works

1. **OAuth 2.0 + PKCE sign-in**: Uses OpenAI's official Codex CLI client
ID to run an authorization code flow. A local HTTP server on
`127.0.0.1:1455` captures the callback, exchanges the code for tokens,
and stores them in the system keychain.

2. **Token refresh**: Access tokens are automatically refreshed when
they're within 5 minutes of expiry, using the stored refresh token.

3. **Responses API**: Requests go to
`https://chatgpt.com/backend-api/codex/responses` using the existing
`open_ai::responses` client (Responses API format, not Chat Completions
which was deprecated for this endpoint in Feb 2026).

4. **Required headers**: `originator: zed`, `OpenAI-Beta:
responses=experimental`, `ChatGPT-Account-Id` (extracted from JWT),
`store: false` in the body.

## Files changed

- `crates/open_ai/src/responses.rs`: Add `store: Option<bool>` field to
`Request`; add `extra_headers` param to `stream_response` for
per-provider header injection
- `crates/language_models/src/provider/openai_subscribed.rs`: New
provider (sign-in UI, OAuth flow, token storage/refresh, model list)
- `crates/language_models/src/provider/open_ai.rs`,
`open_ai_compatible.rs`, `opencode.rs`: Pass `vec![]` for new
`extra_headers` param
- `crates/language_models/src/language_models.rs`: Register the new
provider
- `crates/language_models/Cargo.toml`: Add `rand` and `sha2` deps for
PKCE

## Open questions / known gaps

- [ ] **Terms of service**: Usage appears to be within OpenAI's ToS
(interactive use via their official CLI client ID), but needs legal
sign-off before shipping
- [ ] **Redirect URI**: Currently `http://localhost:1455/auth/callback`
— may need to match exactly what OpenAI's Codex CLI uses
- [ ] **UI polish**: The sign-in card is functional but minimal; needs
design review
- [ ] **Error messages**: OAuth error responses from the callback URL
aren't surfaced to the user yet
- [ ] **`o3` availability**: o3 may require a higher subscription tier;
consider gating it

## Testing

Sign-in flow was designed to match the Copilot Chat provider pattern.
Manual testing against the live OAuth endpoint is needed.

Release Notes:

- Added ChatGPT subscription provider, allowing users to use their
ChatGPT Plus/Pro subscription with the Zed agent

---------

Co-authored-by: Zed Zippy
<234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>

Co-authored-by: morgankrey <morgan@zed.dev>
Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>
pull Bot pushed a commit to soitun/zed-ai that referenced this pull request May 15, 2026
## Summary

- Document the new ChatGPT Subscription provider from zed-industries#53166
- Add to the LLM Providers page alphabetically between Anthropic and
DeepSeek
- Cover sign-in flow, available models (GPT-5.5, GPT-5.3 Codex), and
sign-out

## Test plan

- [ ] Verify section renders correctly in docs preview
- [ ] Confirm links and anchors work

Release Notes:

- N/A
zed-zippy Bot added a commit that referenced this pull request May 15, 2026
…ew) (#56905)

Cherry-pick of #56828 to preview

----
## Summary

- Document the new ChatGPT Subscription provider from #53166
- Add to the LLM Providers page alphabetically between Anthropic and
DeepSeek
- Cover sign-in flow, available models (GPT-5.5, GPT-5.3 Codex), and
sign-out

## Test plan

- [ ] Verify section renders correctly in docs preview
- [ ] Confirm links and anchors work

Release Notes:

- N/A

Co-authored-by: morgankrey <morgan@zed.dev>
zed-zippy Bot added a commit that referenced this pull request May 15, 2026
…e) (#56906)

Cherry-pick of #56828 to stable

----
## Summary

- Document the new ChatGPT Subscription provider from #53166
- Add to the LLM Providers page alphabetically between Anthropic and
DeepSeek
- Cover sign-in flow, available models (GPT-5.5, GPT-5.3 Codex), and
sign-out

## Test plan

- [ ] Verify section renders correctly in docs preview
- [ ] Confirm links and anchors work

Release Notes:

- N/A

Co-authored-by: morgankrey <morgan@zed.dev>
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
…53166)

Adds a new language model provider that lets users authenticate with
their ChatGPT Plus/Pro subscription and use OpenAI models
(codex-mini-latest, o4-mini, o3) directly in the Zed agent — without
needing a separate API key.

## How it works

1. **OAuth 2.0 + PKCE sign-in**: Uses OpenAI's official Codex CLI client
ID to run an authorization code flow. A local HTTP server on
`127.0.0.1:1455` captures the callback, exchanges the code for tokens,
and stores them in the system keychain.

2. **Token refresh**: Access tokens are automatically refreshed when
they're within 5 minutes of expiry, using the stored refresh token.

3. **Responses API**: Requests go to
`https://chatgpt.com/backend-api/codex/responses` using the existing
`open_ai::responses` client (Responses API format, not Chat Completions
which was deprecated for this endpoint in Feb 2026).

4. **Required headers**: `originator: zed`, `OpenAI-Beta:
responses=experimental`, `ChatGPT-Account-Id` (extracted from JWT),
`store: false` in the body.

## Files changed

- `crates/open_ai/src/responses.rs`: Add `store: Option<bool>` field to
`Request`; add `extra_headers` param to `stream_response` for
per-provider header injection
- `crates/language_models/src/provider/openai_subscribed.rs`: New
provider (sign-in UI, OAuth flow, token storage/refresh, model list)
- `crates/language_models/src/provider/open_ai.rs`,
`open_ai_compatible.rs`, `opencode.rs`: Pass `vec![]` for new
`extra_headers` param
- `crates/language_models/src/language_models.rs`: Register the new
provider
- `crates/language_models/Cargo.toml`: Add `rand` and `sha2` deps for
PKCE

## Open questions / known gaps

- [ ] **Terms of service**: Usage appears to be within OpenAI's ToS
(interactive use via their official CLI client ID), but needs legal
sign-off before shipping
- [ ] **Redirect URI**: Currently `http://localhost:1455/auth/callback`
— may need to match exactly what OpenAI's Codex CLI uses
- [ ] **UI polish**: The sign-in card is functional but minimal; needs
design review
- [ ] **Error messages**: OAuth error responses from the callback URL
aren't surfaced to the user yet
- [ ] **`o3` availability**: o3 may require a higher subscription tier;
consider gating it

## Testing

Sign-in flow was designed to match the Copilot Chat provider pattern.
Manual testing against the live OAuth endpoint is needed.

Release Notes:

- Added ChatGPT subscription provider, allowing users to use their
ChatGPT Plus/Pro subscription with the Zed agent

---------

Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>
jonx pushed a commit to jonx/zed-aros that referenced this pull request Jul 17, 2026
## Summary

- Document the new ChatGPT Subscription provider from zed-industries#53166
- Add to the LLM Providers page alphabetically between Anthropic and
DeepSeek
- Cover sign-in flow, available models (GPT-5.5, GPT-5.3 Codex), and
sign-out

## Test plan

- [ ] Verify section renders correctly in docs preview
- [ ] Confirm links and anchors work

Release Notes:

- N/A
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…53166)

Adds a new language model provider that lets users authenticate with
their ChatGPT Plus/Pro subscription and use OpenAI models
(codex-mini-latest, o4-mini, o3) directly in the Zed agent — without
needing a separate API key.

## How it works

1. **OAuth 2.0 + PKCE sign-in**: Uses OpenAI's official Codex CLI client
ID to run an authorization code flow. A local HTTP server on
`127.0.0.1:1455` captures the callback, exchanges the code for tokens,
and stores them in the system keychain.

2. **Token refresh**: Access tokens are automatically refreshed when
they're within 5 minutes of expiry, using the stored refresh token.

3. **Responses API**: Requests go to
`https://chatgpt.com/backend-api/codex/responses` using the existing
`open_ai::responses` client (Responses API format, not Chat Completions
which was deprecated for this endpoint in Feb 2026).

4. **Required headers**: `originator: zed`, `OpenAI-Beta:
responses=experimental`, `ChatGPT-Account-Id` (extracted from JWT),
`store: false` in the body.

## Files changed

- `crates/open_ai/src/responses.rs`: Add `store: Option<bool>` field to
`Request`; add `extra_headers` param to `stream_response` for
per-provider header injection
- `crates/language_models/src/provider/openai_subscribed.rs`: New
provider (sign-in UI, OAuth flow, token storage/refresh, model list)
- `crates/language_models/src/provider/open_ai.rs`,
`open_ai_compatible.rs`, `opencode.rs`: Pass `vec![]` for new
`extra_headers` param
- `crates/language_models/src/language_models.rs`: Register the new
provider
- `crates/language_models/Cargo.toml`: Add `rand` and `sha2` deps for
PKCE

## Open questions / known gaps

- [ ] **Terms of service**: Usage appears to be within OpenAI's ToS
(interactive use via their official CLI client ID), but needs legal
sign-off before shipping
- [ ] **Redirect URI**: Currently `http://localhost:1455/auth/callback`
— may need to match exactly what OpenAI's Codex CLI uses
- [ ] **UI polish**: The sign-in card is functional but minimal; needs
design review
- [ ] **Error messages**: OAuth error responses from the callback URL
aren't surfaced to the user yet
- [ ] **`o3` availability**: o3 may require a higher subscription tier;
consider gating it

## Testing

Sign-in flow was designed to match the Copilot Chat provider pattern.
Manual testing against the live OAuth endpoint is needed.

Release Notes:

- Added ChatGPT subscription provider, allowing users to use their
ChatGPT Plus/Pro subscription with the Zed agent

---------

Co-authored-by: Zed Zippy <234243425+zed-zippy[bot]@users.noreply.github.com>
Co-authored-by: Richard Feldman <richard@zed.dev>
Co-authored-by: Richard Feldman <oss@rtfeldman.com>
Co-authored-by: Agus Zubiaga <agus@zed.dev>
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
## Summary

- Document the new ChatGPT Subscription provider from zed-industries#53166
- Add to the LLM Providers page alphabetically between Anthropic and
DeepSeek
- Cover sign-in flow, available models (GPT-5.5, GPT-5.3 Codex), and
sign-out

## Test plan

- [ ] Verify section renders correctly in docs preview
- [ ] Confirm links and anchors work

Release Notes:

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

Labels

area:ai Related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants