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, ...
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:
Credential Sources: A way to get a ChatGPT OAuth session
Such as local authentication, or when a user auths with Sign in with ChatGPT
Client Adapters: Allows you to actually use the Credential Source
Such as with Vercel's AI SDK or with the OpenAI client
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 localconst credentials = openaiCredentials();
// Use those credentials to create an AI SDK objectconst openai = createOpenAIOAuth(credentials);
// Use AI SDK to run the requestconst result = awaitgenerateText({
model: openai("gpt-5.4-mini"),
prompt: "Hello!",
});
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.
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.
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:
import { createOpenAIOAuth } from"@openai-oauth/ai-sdk";
import { openaiCredentials } from"@openai-oauth/local";
import { generateImage } from"ai";
const openai = createOpenAIOAuth(openaiCredentials());
const result = awaitgenerateImage({
model: openai.image("gpt-image-2"),
prompt: "A tiny house in a forest",
});
With the OpenAI JavaScript SDK:
import { createOpenAIOptions } from"@openai-oauth/openai-client";
import { openaiCredentials } from"@openai-oauth/local";
import OpenAI from"openai";
const client = newOpenAI(createOpenAIOptions(openaiCredentials()));
const result = await client.images.generate({
model: "gpt-image-2",
prompt: "A tiny house in a forest",
});
Image editing uses the same clients through generateImage() or client.images.edit(). Image streaming, masks, custom output formats, and variations are not currently supported.
Use SignInWithChatGPT when users should sign in with their own ChatGPT account.
npm i @openai-oauth/react
It is currently only available for React.
"use client";
import { SignInWithChatGPT } from "@openai-oauth/react";
export default function Page() {
return <SignInWithChatGPT />;
}
The button handles the full browser sign-in flow. After sign-in, it becomes a disconnect button.
The prebuilt button includes a small "Powered by OpenAI OAuth" link by default to support this project. Pass hideAttribution to remove the attribution link.
Hosted web apps need the open-source Sign in with ChatGPT extension for Chrome or Firefox to complete the OAuth handoff securely. The prebuilt component detects the current browser and shows the correct install screen when needed.
Model requests cannot be made directly from a browser due to CORS (This also applies for Desktop apps inside a WebView or browser renderer such as Electron or Tauri).
For hosted web apps, one way to do this is to send the browser session to your own app route:
Additionally, you can create a custom sign-in system with the hook. Custom interfaces are responsible for presenting the extension installation link when needed.
import { useSignInWithChatGPT } from "@openai-oauth/react";
function CustomLogin() {
const login = useSignInWithChatGPT();
if (login.status === "signed-in") {
return <button onClick={login.logout}>Disconnect</button>;
}
if (login.status === "needs-extension") {
return (
<div>
<a href={login.installUrl} rel="noreferrer" target="_blank">
Install Sign in with ChatGPT
</a>
<button onClick={login.login}>Try again</button>
<button onClick={login.reset}>Cancel</button>
</div>
);
}
return (
<button onClick={login.login}>Sign in with ChatGPT</button>
);
}
Only models supported by Codex are available. This list updates over time and depends on your ChatGPT plan.
There is no stateful replay support on the CLI /v1/responses endpoint. The proxy is stateless and expects callers to send the full conversation history.
Hosted browser sign-in currently supports Chrome and Firefox. Safari is not yet supported.
OpenAI OAuth is an unofficial, community-maintained project and is not affiliated with, endorsed by, or sponsored by OpenAI.
OpenAI OAuth uses ChatGPT credentials, which should be treated like passwords.
Each person must use their own ChatGPT account and keep credentials private. Do not pool, share, or redistribute access tokens. Apps offering Sign in with ChatGPT must protect each user's credentials and use them only for requests that user authorizes.
You are responsible for complying with OpenAI's Terms of Use, Usage Policies, and any agreement that applies to your account. Do not bypass rate limits, restrictions, or safeguards.
Provided as-is with no warranties. OpenAI may change or disable the underlying services at any time, and you assume the risks of using this project.