API keys · Guide
How to get an OpenAI API key
Creating an OpenAI API key is free and takes a few minutes, but using it isn’t: new API accounts use prepaid billing, with a $5 minimum top-up. Here’s how to get a key, what you actually pay, and how to keep the key safe.
- Billing
- Prepaid credit
- Minimum top-up
- $5
- Key shown
- Once
- Credits expire
- After 1 year
Steps
Get your key
- Sign in or create an account on the OpenAI API platform.
- Open the API keys page and create a new secret key. Choose the project it belongs to; every organisation has a Default project.
- Pick its permissions: All (the default), Restricted or Read Only. A restricted key needs Read access to Models for the checker on this page to work. OpenAI strongly recommends setting an expiration date.
- Copy the key straight away. OpenAI shows the full secret key only when you create it; if you lose it, create a new one.
- Add credit in the billing settings of your organisation: the minimum purchase is $5 and the default is $10.
- Paste the key into the box on this page to check it works and see which models it can use.
Source: OpenAI’s developer quickstart.
Test your key
Your key goes from your browser straight to OpenAI, never to this site, and isn’t saved. Checking several keys or providers? Use the API key checker.
Billing
What it costs: prepaid credit
OpenAI’s help centre says: “New API accounts use prepaid billing.” You buy credit first, and each request is paid from it. OpenAI’s quickstart says “Congrats on running a free test API request!” in its “Add credits to keep building” step, but OpenAI doesn’t document any general free credit (its billing article only says free credits on an account are used before purchased ones), so plan on buying at least $5.
- Top-ups: the minimum purchase is $5 and the default is $10. Auto-reload is turned on by default during setup, with a minimum recharge of $5; turn it off or set a limit if you don’t want automatic charges.
- Expiry and refunds: purchased credits expire after one year and are non-refundable except in the cases OpenAI lists.
- When credit runs out, requests fail with a 429 error and the code
credit_balance_exhausted. Spend limits you set return 429s too. - Usage tiers rise automatically with your total credit purchases: Free (users in an allowed country, $100 a month usage limit), Build ($5 purchased, $500 a month), Launch ($100, $5,000 a month) and Grow ($500, $200,000 a month). Higher tiers also get higher rate limits.
- Rate limits are counted in requests and tokens per minute (and some per day), per organisation and project; yours are on the limits page.
- Countries: OpenAI only serves the supported countries and territories and warns that using it elsewhere may get the account blocked.
Use it
Call the API with your key
Save the key as an environment variable called OPENAI_API_KEY: every OpenAI SDK reads it automatically. On macOS or Linux run export OPENAI_API_KEY="your_api_key_here"; on Windows, setx OPENAI_API_KEY "your_api_key_here". Then send a request with the key in the Authorization header:
curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"input": "Write a one-sentence bedtime story about a unicorn."
}'This is the example from OpenAI’s text generation guide, unchanged. It is paid from your credit balance. To use another model, copy its ID from our OpenAI model IDs list and check what it costs with the LLM cost calculator.
Security
Keep your key safe
- Give each person their own key; OpenAI says sharing keys is against its terms of use.
- Set an expiry date and rotate keys. Use the narrowest permissions that work.
- OpenAI says: “Never deploy your key in client-side environments like browsers or mobile apps.” Call the API from your own backend.
- Never commit a key to a repository. OpenAI is a GitHub secret scanning partner, and GitHub has said OpenAI automatically disables keys found in public code.
- Set a hard spend limit and watch your usage, so a leaked key can’t empty your balance.
FAQ
Frequently asked questions
Is the OpenAI API key free?
Creating a key is free, but using the API isn’t. New API accounts use prepaid billing: you add credit first (at least $5) and requests are paid from it. OpenAI doesn’t document a general free credit for new accounts, so don’t count on the “$5 of free credit” that older articles promise.
How much do I need to add to start using the OpenAI API?
The minimum purchase is $5, and the default is $10. Buying $5 in total also moves your organisation to the Build usage tier. Auto-reload is on by default when you set up billing, so check its settings if you want to control spending. Purchased credits expire after one year.
Can I see my OpenAI API key again after creating it?
No. OpenAI shows the full secret key only when you create it. If you lost it or didn’t save it, create a new key on the API keys page and delete the old one.
The checker says my key is valid, so why do my requests fail?
A valid key only means OpenAI recognises it. Real requests also need credit: with a zero balance they fail with credit_balance_exhausted. They can also fail when you hit a spend limit, a rate limit for your usage tier, or when a restricted key lacks permission for that endpoint. The error code says which.
What are OpenAI’s usage tiers?
Tiers are set by your total credit purchases and upgrade automatically: Free (users in an allowed country, $100 a month), Build ($5 purchased, $500 a month), Launch ($100, $5,000 a month) and Grow ($500, $200,000 a month). Higher tiers get higher rate limits. Many older guides describe “Tier 1 to 5”; OpenAI’s rate-limits page now lists only these four.
What should I do if my OpenAI key leaks?
Delete it on the API keys page straight away and create a new one; OpenAI says revocations take effect within a few seconds. Then check your usage for anything you don’t recognise. Keys pushed to public GitHub repositories are reported to OpenAI through secret scanning, but don’t rely on that.
Related