Browse by type

<a href="https://www.npmjs.com/package/openai-oauth">NPM</a> | <a href="#legal">Legal</a>
[!NOTE]
What's new in v2?
Add Sign in with ChatGPT to your apps to let users bring their own ChatGPT accounts for AI. Works across free and paid plans. Try it out on Vercel.
![]()
And much more:
- Image Generation: Generate and edit images with GPT Image 2
- GPT-5.6 Support: OpenAI OAuth now automatically gets the newest OpenAI models
- Improved CLI: Run in the background with Detached Mode and sign in via the CLI
- Client Adapters: Connect through Vercel AI SDK, the OpenAI client, or any OpenAI-compatible client
- Apache-2.0 License: Use OpenAI OAuth in both open-source and proprietary applications
Turn your ChatGPT account into an OpenAI-Compatible API. Learn more
$ npx openai-oauth@latest
OpenAI-compatible endpoint ready at http://127.0.0.1:10531/v1
Use this as your OpenAI base URL. No API key is required.
Available Models: gpt-5.6-terra, gpt-5.6-sol, gpt-image-2, ...
Access your ChatGPT account directly from TypeScript on your machine
npm i @openai-oauth/local @openai-oauth/ai-sdk ai
If you are not signed in to Codex locally, first run npx openai-oauth login.
import { createOpenAIOAuth } from "@openai-oauth/ai-sdk";
import { openaiCredentials } from "@openai-oauth/local";
import { generateText } from "ai";
const openai = createOpenAIOAuth(openaiCredentials());
const result = await generateText({
model: openai("gpt-5.4-mini"),
prompt: "Hello!",
});
Works with any OpenAI-compatible client. Learn more
Let your users sign in with their ChatGPT accounts.

npm i @openai-oauth/react @openai-oauth/ai-sdk ai @ai-sdk/react
Quickstart for Next.js:
// app/page.tsx
"use client";
import { openaiAuthHeaders, SignInWithChatGPT } from "@openai-oauth/react";
import { useCompletion } from "@ai-sdk/react";
export default function Page() {
const { complete, completion, isLoading } = useCompletion({
api: "/api/chat",
streamProtocol: "text",
});
return (
<>
<SignInWithChatGPT />
<button
disabled={isLoading}
onClick={async () => {
await complete("Hello!", {
headers: await openaiAuthHeaders(),
});
}}
>
Ask
</button>
{completion}
</>
);
}
// 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 or Firefox for secure authentication.
Works with any web framework and OpenAI-compatible client. Learn more
For more information on each of the packages, refer to package-specific README.md.
/v1/responses/v1/chat/completions/v1/models (account-aware by default, or overridden with --models)See Known Limitations for more information.
openai-oauth CLInpx 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:
npx openai-oauth --detach
npx openai-oauth status
Follow its logs or stop it from any terminal:
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):
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. |
The openai-oauth SDK allows you to integrate ChatGPT login into your local apps and also enable Sign in with ChatGPT for your users.

The SDK is primarily built around two concepts:
In general, the SDK will follow this pattern:
import { openaiCredentials } from "@openai-oauth/local";
import { createOpenAIOAuth } from "@openai-oauth/ai-sdk";
import { generateText } from "ai";
// Get credentials from local
const credentials = openaiCredentials();
// Use those credentials to create an AI SDK object
const openai = createOpenAIOAuth(credentials);
// Use AI SDK to run the request
const result = await generateText({
model: openai("gpt-5.4-mini"),
prompt: "Hello!",
});
These allow you to get the OAuth credentials from OpenAI.
@openai-oauth/localnpm i @openai-oauth/local
Use local Codex credentials which live on your machine (normally at ~/.codex).
import { openaiCredentials } from "@openai-oauth/local";
const credentials = openaiCredentials();
This should work out-of-the-box if you're already logged in with Codex, but to log in again, you can run npx openai-oauth login.
You can also point to a specific auth file:
const credentials = openaiCredentials({
authFilePath: "/path/to/auth.json",
});
@openai-oauth/reactnpm i @openai-oauth/react
Use request-bound credentials from the user's browser, with Sign in with ChatGPT.
import { openaiCredentials } from "@openai-oauth/web/server";
const credentials = openaiCredentials(request);
openaiAuthHeaders() returns a plain header object, so it works with both fetch and AI SDK hooks like useCompletion.
In order to actually establish the credentials in the user's browser, you can use openai-oauth's built-in Sign in with ChatGPT SDK, documented below.
For framework neutral usage, see documentation for @openai-oauth/web in packages/web.
Your OpenAI credentials are by default stored on your device in IndexedDB and encrypted at rest with WebCrypto.
Your app server receives request-bound credentials only when the browser sends them with openaiAuthHeaders(), which returns a plain header object.
openai-oauth lets you bring your own credential storage solution if this is not good enough. See documentation for @openai-oauth/web in packages/web for more information.
These adapters let you use your openai-oauth credentials in any client.
@openai-oauth/ai-sdknpm i openai @openai-oauth/ai-sdk
Connect openai-oauth to Vercel AI SDK with this provider.
import { createOpenAIOAuth } from "@openai-oauth/ai-sdk";
import { openaiCredentials } from "@openai-oauth/local";
import { generateText } from "ai";
const openai = createOpenAIOAuth(openaiCredentials());
const result = await generateText({
model: openai("gpt-5.5"),
prompt: "Reply with exactly: hello",
});
Learn more about how to use Vercel AI SDK. See supported features above.
Migrating from openai-oauth-provider
Vercel AI SDK integration is now independent of your credential source. openai-oauth-provider will soon be deprecated, and the preferred route for using local credentials with the Vercel AI SDK is shown in the example above.
You now import and provide an extra openaiCredentials, either from @openai-oauth/local for local credentials as before or from another credential source.
@openai-oauth/openai-clientnpm i openai @openai-oauth/openai-client
OpenAI JavaScript SDK options adapter.
import { createOpenAIOptions } from "@openai-oauth/openai-client";
import { openaiCredentials } from "@openai-oauth/local";
import OpenAI from "openai";
const client = new OpenAI(createOpenAIOptions(openaiCredentials()));
openai-oauth also works with any OpenAI-compatible client as long as it takes a custom baseURL and fetch.
import { createOpenAIOAuthTransport } from "@openai-oauth/core";
import { openaiCredentials } from "@openai-oauth/local";
const credentials = openaiCredentials();
const transport = createOpenAIOAuthTransport({
auth: () => credentials.getSession(),
});
const baseURL = transport.baseURL;
const fetch = transport.fetch;
For example, here's how you would implement the OpenAI JavaScript SDK manually:
const client = new OpenAI({
apiKey: "openai-oauth",
baseURL: transport.baseURL,
fetch: transport.fetch,
});
Generate and edit images with GPT Image 2 using the same ChatGPT credentials and client adapters.
The dev proxy exposes the OpenAI-compatible /v1/images/generations and /v1/images/edits endpoints:
curl http://127.0.0.1:10531/v1/images/generations \
-H "Content-Type: application/json" \
-d '{"model":"gpt-image-2","prompt":"A tiny house in a forest"}'
With Vercel AI SDK:
```ts import { createOpenAIOAuth } from "@openai-oauth/ai-sdk"; import { openaiCredentials } from "@openai-oauth/local"; import
browse all types & interfaces →
$ claude mcp add openai-oauth \
-- python -m otcore.mcp_server <graph>