OpenAI API key
How to get an OpenAI API key (the ChatGPT API key)
Create an OpenAI API key on the API keys page at platform.openai.com, then buy at least $5 of prepaid credit (the default is $10), because a key with no balance fails. ChatGPT Plus, Go and Free include no API credits; Pro tiers can claim $100 to $500 a month of API credits instead.
- Minimum credit
- $5, default $10
- Credit expiry
- 1 year after purchase
- ChatGPT Plus
- No API credits
- Pro API credits
- $100 to $500 a month
Updated
Get an OpenAI API key in 6 steps
- Sign in or create an account at
platform.openai.com. - Open the API keys page at
platform.openai.com/settings/organization/api-keysand create a new secret key. - Copy the key right away, because OpenAI shows the full secret only once when you create it, and if you lose it you'll have to create a new key and update your application.
- Go to your organization's billing overview, add your payment details and buy at least $5 of prepaid credit (the default is $10); auto-reload is turned on by default during setup, so switch it off if you don't want automatic purchases.
- Save the key in the
OPENAI_API_KEYenvironment variable by addingexport OPENAI_API_KEY='yourkey'to~/.zshrcor~/.bash_profileon macOS and Linux, or by runningsetx OPENAI_API_KEY "<yourkey>"in the Windows command prompt. - Send a test request to make sure the key works.
Deleting a key stops it from working, so any app that still relies on that key will break.
What it costs to use the key
Creating an OpenAI API key is free, but API usage is billed separately from any ChatGPT plan.
- Monthly usage limits cap what you can spend by tier: $100 on Free, $500 on Build (after $5 in total credit purchases), $5,000 on Launch (after $100) and $200,000 on Grow (after $500).
- Your balance can briefly go negative because API access may not stop the instant your credits run out, and that negative amount gets deducted from your next purchase.
The table below shows which accounts and ChatGPT plans include API credits: only paid Pro and Business plans do.
| Account or plan | API credits | Notes |
|---|---|---|
| New API account | None, prepay from $5 | Credits expire after 1 year |
| ChatGPT Free, Go or Plus | None | API billed separately |
| ChatGPT Pro 100 | $100 a month | Unused credits expire each cycle |
| ChatGPT Pro 200 | $200 a month | Not for Codex through API keys |
| ChatGPT Pro 500 | $500 a month | Plan must be 7+ days old |
| Business Standard | $20 per paid seat | Pooled, capped at $500 a month |
| Business Premium | $100 per paid seat | Pooled, capped at $500 a month |
Make your first request
Every request sends your key in an Authorization: Bearer header, and the official SDKs (npm install openai or pip install openai) read OPENAI_API_KEY from your environment, so you never hardcode it. Revoking a key takes effect within a few seconds, while most other changes to a key's authentication propagate within 15 minutes.
The first call below checks that your key works by listing models at https://api.openai.com/v1/models, and the second sends a prompt to the Responses API (POST https://api.openai.com/v1/responses).
export OPENAI_API_KEY="your-key-here"
curl https://api.openai.com/v1/models \
-H "Authorization: Bearer $OPENAI_API_KEY"
curl https://api.openai.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{"model": "gpt-6.1-sol", "input": "Say hello in five words."}'Keep the key safe
- Use one key per person: Sharing API keys is against OpenAI's Terms of Use, so invite team members to your organization instead.
- Never ship a key in a browser or mobile app: Route all API requests through your own backend.
- Never commit a key to a repository: Keep it in an environment variable or a key management service.
- Set an expiration date on project keys and rotate them: Admins can enforce a maximum key lifetime for the organization or a project.
- Set monthly spend limits with hard enforcement: Spend alerts alone won't stop API traffic when your budget runs out.
- Rotate immediately if a key may have leaked: You can also turn on IP allowlisting so OpenAI rejects requests from other addresses even when the key is valid.
Fix common API key errors
The table below lists the authentication, billing and limit errors from OpenAI's error codes guide. Only the 401 errors point at the key or your IP, while four of the 429 errors come from billing and spend limits. For billing errors, check error.code in the response, because error.type can still read insufficient_quota.
| Error | Meaning | Fix |
|---|---|---|
| 401 Incorrect API key provided | Wrong, mistyped or deleted key | Copy it again or create a new key |
| 401 IP not authorized | Your IP is not on the allowlist | Call from an allowed IP or edit the list |
| 403 Country not supported | Unsupported country or region | Call from a supported country |
| 429 credit_ | No prepaid credits left | Add credits in billing |
| 429 organization_ | Organization hit its spend limit | Raise or remove the limit |
| 429 project_ | Project hit its spend limit | Raise it in project settings |
| 429 organization_ | OpenAI-assigned monthly limit reached | Request a higher usage limit |
| 429 Rate limit reached | Too many requests too fast | Slow down, follow Retry-After |
Use your ChatGPT plan as the API key
If what you want is a ChatGPT API key that runs on the ChatGPT subscription you already pay for, Plan2API does that for ChatGPT plans with Codex, such as Plus or Pro, without per-token billing.
You sign up with a Google account, connect ChatGPT by signing in with a one-time device code, and get a p2a_ key that works with the OpenAI Chat Completions format (POST /v1/chat/completions) at https://api.plan2api.com/v1 using model ids like openai/gpt-6.1-sol, openai/gpt-6-astra or openai/gpt-6-luna. Requests run on your plan's own Codex limits, there's no /v1/responses or /v1/embeddings endpoint, and the Plan2API Free plan gives you 50 chat requests a day for $0 with no card required.
from openai import OpenAI
client = OpenAI(
base_url="https://api.plan2api.com/v1",
api_key="p2a_...",
)
reply = client.chat.completions.create(
model="openai/gpt-6.1-sol",
messages=[{"role": "user", "content": "Write a haiku about API keys."}],
)
print(reply.choices[0].message.content)Use the AI subscriptions you already pay for as one OpenAI-compatible API key.
- Free: 1 subscription, 50 requests a day, no card
- Pro: $12 a month
FAQ
Is an OpenAI API key free?
Creating the key is free, but using it requires prepaid credit with a $5 minimum purchase (the default is $10). If you pay for ChatGPT Pro 100, Pro 200, Pro 500 or Business, you can claim monthly API credits instead without adding an API payment method, as long as your subscription is at least 7 days old and uses the same email as your API account.
Does ChatGPT Plus include API access?
No. ChatGPT Plus and the OpenAI API are billed separately, and Plus isn't eligible for OpenAI's monthly API credit benefit.
Where do I find my OpenAI API key?
You create and manage keys on the API keys page at platform.openai.com/settings/organization/api-keys. OpenAI shows the full secret key only once when you create it, so if you lost it, you have to create a new key and update your application.
Why does my new OpenAI API key return error 429?
It's usually credit_balance_exhausted, which means your organization has no prepaid credits left. Buy at least $5 of credit in your billing overview and wait a few minutes for the balance update to go through. Other 429 codes point to an enforced spend limit (organization_spend_limit_exceeded or project_spend_limit_exceeded), your monthly usage limit (organization_usage_limit_exceeded), or the request rate limit (Rate limit reached for requests).
Is a ChatGPT API key the same as an OpenAI API key?
Yes. To call OpenAI's models from your own code, you use an API key from platform.openai.com; your regular ChatGPT login isn't an API key. A Plan2API p2a_ key is the exception: it calls Codex models through your connected ChatGPT plan.
Can I share my OpenAI API key with my team?
No, sharing API keys breaks OpenAI's Terms of Use. Invite your teammates to your organization on the platform so each person can create their own unique key.
Sources
- OpenAI Help: Where to find your API keyhelp.openai.com
- OpenAI Help: Prepaid API billinghelp.openai.com
- OpenAI Help: API key safetyhelp.openai.com
- OpenAI Help: API credits benefithelp.openai.com
- OpenAI API error codesdevelopers.openai.com
- OpenAI rate limits and usage tiersdevelopers.openai.com
- OpenAI API reference: authenticationdevelopers.openai.com
- OpenAI developer quickstartdevelopers.openai.com