>
{completion}
> ); } ``` ```ts // app/api/chat/route.ts import { createOpenAIOAuth } from "@openai-oauth/ai-sdk"; import { openaiCredentials } from "@openai-oauth/react/server"; import { streamText } from "ai"; export async function POST(request: Request) { const { prompt } = await request.json(); const openai = createOpenAIOAuth(openaiCredentials(request)); const result = streamText({ model: openai("gpt-5.4-mini"), prompt, }); return result.toTextStreamResponse(); } ``` First-time users will be prompted to install Sign in with ChatGPT for [Chrome](https://chromewebstore.google.com/detail/sign-in-with-chatgpt/odbgboachaefbbbdiffcefhpkekhfcna) or [Firefox](https://addons.mozilla.org/firefox/addon/sign-in-with-chatgpt/) for secure authentication. Works with any web framework and OpenAI-compatible client. [Learn more](#react-component) # Docs For more information on each of the packages, refer to package-specific `README.md`. ## What is Supported - Working Endpoints: - `/v1/responses` - `/v1/chat/completions` - `/v1/models` (account-aware by default, or overridden with `--models`) - Streaming Responses - Toolcalls - Reasoning Traces See [Known Limitations](#known-limitations) for more information. ## `openai-oauth` CLI ```bash npx openai-oauth ``` This starts an OpenAI-compatible endpoint (by default at `localhost:10531`) that is connected to your ChatGPT account. Press `d` to keep it running in the background or `q` to quit. You can also start it in the background directly: ```bash npx openai-oauth --detach npx openai-oauth status ``` Follow its logs or stop it from any terminal: ```bash npx openai-oauth logs --follow npx openai-oauth stop ``` If you are not signed in, it will ask you to sign in locally. Your credentials will be stored in `~/.codex` (the same place `codex` CLI uses). You can always directly sign in (without starting the server): ```bash npx openai-oauth login ``` Login listens on loopback and uses `http://localhost:1455/auth/callback`, the local callback URL accepted by OpenAI OAuth. The CLI also supports a few configuration options that generally do not need to be edited.openai-oauth CLI Flags| Config | CLI flag | Default | Description |
|---|---|---|---|
| Host binding | --host |
127.0.0.1 |
Host interface the local proxy binds to. Non-loopback hosts expose the proxy to your network. |
| Port | --port |
10531 |
Port the local proxy binds to. |
| Model allowlist | --models |
Account-specific Codex models discovered from ChatGPT | Comma-separated list of model ids exposed by /v1/models. When omitted, the CLI discovers the models your account has access to. |
| Codex client version | --codex-version |
Latest @openai/codex from npm, with a bundled fallback |
Override the Codex client version used for model discovery. |
| Upstream base URL | --base-url |
https://chatgpt.com/backend-api/codex |
Override the upstream Codex base URL. |
| OAuth client ID | --oauth-client-id |
app_EMoamEEZ73f0CkXaXp7hrann |
Override the OAuth client id used for login and refresh. |
| OAuth token URL | --oauth-token-url |
https://auth.openai.com/oauth/token |
Override the OAuth token URL used for login and refresh. |
| Auth file path | --oauth-file |
--oauth-file path if provided, otherwise $CODEX_HOME/auth.json or ~/.codex/auth.json |
Override where the local OAuth auth file is discovered. |
| Open browser | --open / --no-open |
--open |
Open the login URL in a browser during npx openai-oauth login. Use --no-open to print the URL instead. |
| Login timeout | --login-timeout-ms |
300000 |
How long the login command waits for the OAuth callback, in milliseconds. |
openai-oauth-provider