Key takeaways
- You create an OpenAI API key on the API keys page of a project, and OpenAI shows the full key only once, when you create it.
- New API accounts use prepaid billing: the minimum credit purchase is $5, and purchased credits expire after one year, as of November 25, 2026.
- A 429 error with insufficient_quota is a billing problem, so retrying won't help: add credits or raise your spend limit.
To get an OpenAI API key, sign in to the OpenAI API Platform, open the API keys page, create a new secret key in a project and copy it at once, because OpenAI shows the full key only when you create it. To use the key beyond a free test request, add prepaid credits in billing; the minimum purchase is $5, as of November 25, 2026.
This guide takes you from no account to a stored key, credits and a first curl request, with fixes for the 401 and 429 errors. Every step comes from OpenAI's API quickstart, its API docs and its help center.
What you need first
- An account on the OpenAI API Platform at platform.openai.com. A ChatGPT Plus subscription comes with no API credits; only eligible Pro and Business plans do.
- A payment card, unless you only want to send a test request or you have free credits from a ChatGPT Pro or Business plan (more on that below).
- A terminal with curl, or Python or Node.js if you prefer an SDK.
- You must be in a country OpenAI supports. Requests from elsewhere fail with a 403 error, according to OpenAI's error codes guide.
How organizations and projects work
Every API account sits in an organization, and every organization has projects. OpenAI's help article on managing projects says each organization comes with a Default project that can't be deleted, and that "each project has its own API keys". Projects also carry their own rate limits, model permissions and spend limits.
For a first key, the Default project is fine. Only organization owners can create new projects: open the project selector, choose to create a project, give it a name and pick a data residency option. OpenAI's production best practices suggest separate projects for staging and production once you ship something.
How to get an OpenAI API key, step by step
- Sign in at platform.openai.com and pick the organization and project you want the key to belong to.
- Open the API keys page. You can also reach it from the project's settings under API Keys.
- Select + Create new secret key.
- Choose the key's permissions (see the next section). The default is All.
- Set an expiration date. OpenAI "strongly recommend[s]" one in its production guide, along with a regular rotation schedule.
- Create the key and copy it immediately. OpenAI's help center says: "For security, a full secret key is only shown when you create it." If you lose it, you can't view it again. Create a new one and update your code.
To delete a key, select the trash icon next to it on the same page. Anything that uses that key stops working. OpenAI's authentication docs say a revoked key stops working within a few seconds.
Choose key permissions: All, Restricted or Read Only
OpenAI's help article on API key permissions lists three levels for a project key:
| Permission | What the key can do |
|---|---|
| All | Full access to the project's API resources. This is the default. |
| Restricted | Only the resources and endpoints you pick, each set to None, Read, Write or a request-specific permission. |
| Read Only | Read access to every endpoint, and nothing else. |
A restricted key suits an app that needs only one or two endpoints. Scopes never grant more than the key's owner has: OpenAI's API keys and service accounts guide says an unrestricted key "still operates within its owner's effective permissions".
The same guide says to use your own project key for local development and a service account key for a deployed app or CI job, so the app doesn't depend on one developer's account.
How to add billing and credits
New API accounts pay in advance. OpenAI's help article on prepaid billing says you buy credits first and your balance goes down as you use the API. As of November 25, 2026:
- Go to your organization's billing overview.
- Select Add payment details, enter a card and choose a starting amount. The minimum is $5 and the default is $10.
- Decide whether to keep auto-reload on. It is on by default. It tops up your balance when it drops below a threshold you set, by at least $5 a time, with an optional monthly cap.
- Confirm. The balance can take a few minutes to update.
Purchased credits expire after one year. OpenAI's help center adds that credits bought in Japan after November 13, 2026 expire after 180 days.
Your total purchases also set your usage tier, which sets your rate limits and the most you can spend in a month. From OpenAI's rate limits guide, as of November 25, 2026:
| Tier | How you qualify | Monthly usage limit |
|---|---|---|
| Free | Be in an allowed geography | $100 |
| Build | $5 in total credit purchases | $500 |
| Launch | $100 in total credit purchases | $5,000 |
| Grow | $500 in total credit purchases | $200,000 |
The tier upgrades on its own as your purchases cross each threshold. You can see your per-model limits under Settings > Organization > Limits. To see what each model costs per token, check OpenAI's pricing page or the side-by-side AI API pricing table.
It is worth setting a hard spend limit before you start. OpenAI's spend limits guide explains how: under Organization limits or a project's Limits, select Edit spend limit, enter a monthly amount and turn on Enforce a hard limit. Without that switch, a spend limit only sends alerts.
Is there a free OpenAI API key
There is no special free key. Every key comes from the same API keys page, and what a key can do depends on the credits and tier of its organization. OpenAI's own docs mention these free options, as of November 25, 2026:
- A free test request. The quickstart calls a first call a "free test API request" and points to billing for "higher limits". The rate limits guide lists a Free tier with a $100 monthly usage limit for users in an allowed geography. The docs do not say how much free usage a new account gets, so plan on buying the $5 minimum for any real work.
- ChatGPT Pro and Business credits. OpenAI's guide to API credits for ChatGPT subscribers says eligible Pro plans get $100, $200 or $500 a month in API credits, and Business workspaces get $20 per Standard seat or $100 per Premium seat, capped at $500 a month. The subscription must be paid and at least seven days old, and you must own both it and the API organization. Plus, Go and Free plans don't qualify, and unused credits expire at the end of each billing cycle.
- Researcher grants. OpenAI's Researcher Access Program lets researchers with an academic or research affiliation apply for up to $1,000 in API credits, valid for 12 months. Applications are reviewed each quarter.
OpenAI's docs list no student API key. A "free key" posted on another site belongs to someone else's account, and OpenAI's key safety rules say each person should use their own key and never share it.
Store the key in an environment variable
Don't paste the key into your code. OpenAI's help article on API key safety recommends an environment variable named OPENAI_API_KEY, which every OpenAI SDK reads on its own.
On macOS or Linux:
export OPENAI_API_KEY="your_api_key_here"
On Windows, in PowerShell:
setx OPENAI_API_KEY "your_api_key_here"
The quickstart suggests keeping the key somewhere safe, such as your .zshrc file, before you export it.
The same help article sets the other rules: never put the key in a browser or mobile app, never commit it to a repository, give each team member their own key, and rotate a key at once if you think it leaked.
Make a first test call with curl
This request comes from OpenAI's text generation guide. It was not run for this article, because no API key was available:
curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6.2-astra",
"input": "Write a one-sentence bedtime story about a unicorn."
}'
The key goes in the Authorization: Bearer header. If it works, the reply is JSON with the model's text inside its output field. If you belong to more than one organization, add OpenAI-Organization and OpenAI-Project headers so the request is billed to the right place; the authentication docs say you can find both IDs in your dashboard settings.
Common errors and how to fix them
OpenAI's error codes guide lists what each one means:
| Error | What it means | Fix |
|---|---|---|
| 401 Incorrect API key provided | The key has a typo or an extra space, belongs to another organization or project, was deleted, or an old key is cached | Check the variable, copy the key again, or create a new one |
| 401 Invalid Authentication | The key and the organization in the request don't match | Send the right key, and the right OpenAI-Organization header if you use one |
| 401 You must be a member of an organization | Your account isn't in any organization | Ask an organization owner to invite you, or request a new one through help.openai.com |
429 with insufficient_quota |
A billing problem, not traffic | Read error.code: credit_balance_exhausted means add credits; a spend limit code means raise the limit |
| 429 Rate limit reached | Too many requests or tokens per minute | Slow down and follow the Retry-After header |
| 403 Country not supported | You are calling from an unsupported region | Call from a supported country |
The 429 insufficient_quota error is the one most new users hit. The error guide says the broad error.type can still be insufficient_quota, and the specific error.code tells you why: credit_balance_exhausted, organization_spend_limit_exceeded, project_spend_limit_exceeded or organization_usage_limit_exceeded. OpenAI is blunt about retries: "Retrying billing, spend, or quota errors won't restore API access." Add credits or raise the limit, then send the request again.
Where to go next
Once the curl request works, install the SDK for your language (pip install openai or npm install openai) and follow the rest of OpenAI's quickstart. If you use more than one provider, the steps are similar for a Claude API key and a Gemini API key, and an OpenRouter API key reaches OpenAI's models and others through one account.
Frequently asked questions
Is there a free OpenAI API key?
No special free key exists; every key comes from the API keys page, and its use depends on the organization's credits. OpenAI's quickstart offers a free test request, eligible ChatGPT Pro and Business plans include $100 to $500 a month in API credits, and researchers can apply for up to $1,000 in credits.
Is there a free OpenAI API key for students?
OpenAI's API docs and help center list no student API key or student credits. The closest program is the Researcher Access Program, which offers up to $1,000 in API credits to researchers with an academic or research affiliation.
How does OpenAI API billing work?
New accounts buy prepaid credits in the billing overview, starting at $5 with a $10 default, and usage is deducted from that balance. When the balance runs out, requests fail with a 429 error and the code credit_balance_exhausted.
Where is the OpenAI API dashboard and login?
The API dashboard is at platform.openai.com, where you sign in to manage keys at platform.openai.com/api-keys and credits at platform.openai.com/account/billing/overview.
Sources
- Developer quickstartOpenAI
- API keys and service accountsOpenAI
- AuthenticationOpenAI
- Rate limitsOpenAI
- Error codesOpenAI
- Spend limitsOpenAI
- Production best practicesOpenAI
- Text generationOpenAI
- API credits for ChatGPT subscribersOpenAI
- API pricingOpenAI
- Where do I find my OpenAI API key?OpenAI Help Center
- Assign API key permissionsOpenAI Help Center
- Managing projects in the API platformOpenAI Help Center
- What is prepaid billing?OpenAI Help Center
- Best practices for API key safetyOpenAI Help Center
- Researcher Access Program FAQOpenAI Help Center

