ChatGPT API Key: How to Get One and Use It for Free (2026)
Get a ChatGPT API key in 5 steps on the OpenAI platform, see what it costs in 2026, whether it’s free, and how to fix 401 and 429 errors.
On this page How to get a ChatGPT API key (quick steps)
Independent and reader-supported. Some links may earn us a commission; it never changes our rankings. Editorial policy
A “ChatGPT API key” is really an OpenAI API key. You don’t get it from the ChatGPT chat app. You create it on the OpenAI developer platform, and it lets your own code, apps and automations call the same models that power ChatGPT. Here’s the fast way to get one, what it really costs, whether you can use it for free, and how to fix the errors most people hit.
How to get a ChatGPT API key (quick steps)
- Go to platform.openai.com/api-keys and sign in. Your normal ChatGPT login works (email, Google, Microsoft or Apple).
- Pick the project the key should belong to. Every key lives inside a project, and new accounts get a default one. Use a separate project per app so you can track spend and revoke keys cleanly.
- Click Create new secret key, give it a name (for example “n8n-prod”), and choose permissions: All, Restricted or Read only.
- Copy the key straight away. It starts with
sk-proj-and is shown in full only once. If you lose it, create a new one. - Open Settings → Billing and add credits. The minimum purchase is $5, and auto-reload is switched on by default, so turn it off or set a limit if you want a hard budget.

That’s it. Creating the key is free; you only pay when you send requests.
Key Takeaways
- ChatGPT Plus is not the API. Your ChatGPT subscription and API usage are billed separately. Plus gives you no API credits, and API credits don’t upgrade ChatGPT.
- The API is prepaid. Buy credits (from $5), and every request draws down the balance. Purchased credits expire after one year.
- It’s cheap for small projects. 1,000 chatbot replies cost about $0.20 on GPT-6 Luna and about $4 on GPT-6 Sol.
- Keep the key on a server. Never put it in browser code, mobile apps or a public GitHub repo.
- Most errors are billing, not code. A 429 usually means no credits or a spend limit, not that your script is broken.
Is the ChatGPT API free?
Not really. OpenAI’s “Free” usage tier is a usage cap for new accounts, not free tokens. The quickstart lets you run a test request, but for real use you need a positive credit balance. In practice, plan on spending at least $5.
Ways to use it free or almost free:
- Credit grants. If your Billing page shows a credit grant (from a promotion, a hackathon or a research program), OpenAI spends it before your purchased credits.
- Startup programs. Accelerators and cloud startup programs sometimes include OpenAI or Azure OpenAI credits. Check the current terms, as amounts change.
- Azure free account. Azure’s trial credit can be used with Azure OpenAI models. That gives you an Azure key and endpoint, not an OpenAI key.
- Use the cheapest model. With GPT-5 Nano or GPT-6 Luna, $5 lasts a long time for testing.
Skip “free ChatGPT API key” lists and shared keys on GitHub or Discord. Those keys are stolen or leaked, they get revoked quickly, and using them breaks OpenAI’s terms.
How much does the ChatGPT API cost?
You pay per token, separately for input (your prompt) and output (the reply). 1,000 tokens is roughly 750 English words. Standard prices per 1M tokens on OpenAI’s pricing page as of October 16, 2026:
| Model | Best for | Input / 1M | Output / 1M |
|---|---|---|---|
| gpt-6-astra | Hardest reasoning and coding | $10.00 | $50.00 |
| gpt-6.1-sol | Strong all-rounder, the default pick | $2.00 | $10.00 |
| gpt-6-luna | Cheap, fast, high volume | $0.10 | $0.50 |
| gpt-5.6-terra | Mid-range alternative | $2.00 | $12.00 |
| gpt-5.4-mini | Older budget model | $0.75 | $4.50 |
| gpt-5-nano | Cheapest text model | $0.05 | $0.40 |
| gpt-4o-mini | Legacy, still in many tutorials | $0.15 | $0.60 |
Batch and Flex processing cost half the standard rate if you can wait for results. Repeated prompt prefixes are billed at a much cheaper cached-input rate. Prompts above 272K input tokens use a higher long-context rate.
Real cost examples
- Support chatbot, 1,000 replies (500 input + 300 output tokens each): about $0.20 on GPT-6 Luna, $4 on GPT-6.1 Sol, $20 on GPT-6 Astra.
- Summarising 100 blog posts (2,000 tokens in, 300 out each): about $0.04 on Luna, $0.70 on Sol.
- An n8n or Make automation running 50 small calls a day on Luna: well under $1 a month.

ChatGPT Plus vs the ChatGPT API
| ChatGPT Plus | OpenAI API | |
|---|---|---|
| What it is | The chat app at chatgpt.com | Programmatic access for your own code and tools |
| Billing | Fixed monthly subscription | Prepaid credits, pay per token |
| Where you manage it | chatgpt.com settings | platform.openai.com |
| Includes the other? | No API credits | No ChatGPT upgrade |
The login is the same, but the bills are separate. If you only chat, Plus is enough. If you want a key for an app, plugin or automation, you need API credits, with or without Plus.
How to use your ChatGPT API key
Save the key as an environment variable, so it never ends up in your code:
# macOS / Linux
export OPENAI_API_KEY="sk-proj-..."
# Windows (PowerShell)
setx OPENAI_API_KEY "sk-proj-..."
Then make a test request with the official Python SDK (pip install openai). It reads the key from the environment automatically and uses the current Responses API:
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6-luna",
input="Say hello in one sentence.",
)
print(response.output_text)
Older tutorials use openai.ChatCompletion.create or openai.api_key = "...". Those come from the pre-1.0 library and fail on current versions. Chat Completions still works through client.chat.completions.create, but OpenAI’s docs now start with the Responses API.
Prefer no code? The Playground lets you test prompts and models in the browser, using the same credits.
Where you can use the key
- Automations: n8n, Make and Zapier have OpenAI nodes. Paste the key into a credential, never into a shared workflow.
- Coding tools and editors: many editors and CLI agents accept an OpenAI key for “bring your own key” mode.
- Chat front-ends: self-hosted UIs such as Open WebUI or LibreChat let you chat at API prices instead of a subscription.
- Your own app: call the API from your backend and pass only the answer to the browser.
ChatGPT API key not working? Common errors and fixes
| Error | What it means | Fix |
|---|---|---|
| 401 Incorrect API key provided | The key is wrong, deleted or has a stray space | Copy it again or create a new key. Check the environment variable your app actually reads. |
| 401 Invalid Authentication / not a member of an organization | The key belongs to a different org or project, or your account isn’t in one | Check the project and org, or ask the org owner to invite you. |
| 401 IP not authorized | The project has an IP allowlist | Send from an allowed IP, or update the allowlist. |
| 429 insufficient_quota / credit balance exhausted | No prepaid credits left. This is the most common “free key” error. | Add credits in Billing. New credits can take a few minutes to apply. |
| 429 spend limit reached | Your org or project hit the hard spend limit you set | Raise or remove the limit in settings. |
| 429 Rate limit reached | Too many requests or tokens per minute for your tier | Retry with backoff and respect the Retry-After header, or move up a tier. |
| Model not found / no access | The model name is old, misspelled or not enabled for your tier | Use a current model ID from the pricing table above. |
Rate limits and usage tiers
Your limits rise automatically as your total credit purchases grow, according to OpenAI’s rate limit guide:
| Tier | How you qualify | Monthly usage limit | Example limit (Sol models) |
|---|---|---|---|
| Free | Account in a supported country | $100 | Very low, testing only |
| Build | $5 total purchases | $500 | 5,000 RPM, 1M TPM |
| Launch | $100 total purchases | $5,000 | 10,000 RPM, 4M TPM |
| Grow | $500 total purchases | $200,000 | 15,000 RPM, 40M TPM |
Your exact numbers for each model are under Settings → Organization → Limits. Set a spend alert to get an email, or a hard spend limit to stop requests at a set amount.
Keep your OpenAI API key safe
- Server side only. Anyone can read a key in front-end JavaScript or a mobile app bundle, so call the API from your backend.
- Never commit it. Put
.envin.gitignore. Bots scan public repos forsk-keys within minutes. - One key per app, least privilege. Use Restricted permissions and separate projects, so a leak only exposes one app.
- Cap the damage. Set a project spend limit and turn off auto-reload, or give it a monthly limit.
- Rotate when in doubt. If a key might be exposed, delete it on the API keys page and create a new one. Deleted keys stop working immediately.
- Don’t share keys with teammates. Invite them to the org or project instead, so each person has their own key.
FAQ
Where do I find my ChatGPT API key?
On the API keys page of the OpenAI platform. You’ll only see the key’s name and last characters there. The full secret is shown once, at creation, so if you didn’t save it, create a new key.
Can I get a ChatGPT API key for free?
Creating the key is free, but using it needs credits unless your account has a credit grant. The cheapest real start is a $5 top-up.
Does ChatGPT Plus include API access?
No. ChatGPT plans and the API are billed separately, even though you use the same login.
How long does $5 of API credit last?
On GPT-6 Luna, $5 covers roughly 25,000 short chatbot replies. On GPT-6.1 Sol it’s closer to 1,250. Credits expire one year after purchase.
Why do I get “You exceeded your current quota” with a brand-new key?
Your account has no paid credits. Add a payment method, buy credits in Billing, and try again a few minutes later.
Is a ChatGPT API key the same as an OpenAI API key?
Yes. There’s no separate ChatGPT key. One OpenAI key works for every model your project has access to, including GPT-6, image and audio models.
Can I use one key in several apps?
You can, but you shouldn’t. Separate keys per app make it easy to see which app spends what, and to revoke one without breaking the others.
Found this useful? Share it with someone comparing AI tools.