How to Get an OpenAI API Key in 2026: Dashboard, Billing, Environment Variable and First Call
APIsQuick answer: Sign in at platform.openai.com, open the API keys page (platform.openai.com/api-keys) and create a secret key. Save it as OPENAI_API_KEY, install the official SDK and send one request to the Responses API. OpenAI lets you run a free test request; after that, add credits on the billing page. Per-token rates are on OpenAI’s pricing page (accessed October 25, 2026).
What do you need before you start?
An account on the OpenAI platform (platform.openai.com). API billing is separate from ChatGPT: a ChatGPT Plus or Pro subscription does not include API usage. See OpenAI API pricing for how the model tiers compare.
How do you create an OpenAI API key, step by step?
- Sign in at platform.openai.com.
- Open the API keys page (
platform.openai.com/api-keys) and create a new secret key. Pick the project it should belong to; usage is tracked per project. - Copy the key right away and keep it somewhere safe, such as a password manager or secret store.
- Export it as an environment variable, as OpenAI’s quickstart shows:
# macOS / Linux
export OPENAI_API_KEY="your_api_key_here"
# Windows PowerShell
setx OPENAI_API_KEY "your_api_key_here"
- Make a first call with the official Python SDK (
pip install openai):
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY from the environment
response = client.responses.create(
model="gpt-6-astra",
input="Say hi in five words.",
)
print(response.output_text)
The quickstart uses gpt-6-astra. For a cheap smoke test you can swap in a lower tier from the pricing page. Node.js works the same way with npm install openai.
- Add credits on the billing page (
platform.openai.com/account/billing/overview) once the free test request is done.
How do you call the API without an SDK?
Send the key as a Bearer token. OpenAI’s API reference shows:
curl https://api.openai.com/v1/models \
-H "Authorization: Bearer $OPENAI_API_KEY"
If you belong to more than one organization, or use a legacy user key, add the OpenAI-Organization and OpenAI-Project headers so usage lands in the right place. You can find both IDs in your dashboard settings.
Which kind of key do you need?
OpenAI’s reference lists three ways to authenticate:
| Credential | Use it for |
|---|---|
| Standard API key | Normal application requests (most people) |
| Admin API key | Administration endpoints: users, invites, projects, API keys, audit logs |
| Workload identity federation | Short-lived access tokens for cloud workloads, instead of a long-lived key |
Can you get an OpenAI API key for free?
The key costs nothing, and the quickstart includes a free test request. Real use is pay as you go, billed per token. Avoid “free OpenAI API keys” posted online: a key is tied to its owner’s billing account, leaked keys get revoked, and using someone else’s key can break OpenAI’s terms.
What if the key doesn’t work?
- 401 “Incorrect API key provided”: re-copy the key, and check that an old
OPENAI_API_KEYin your shell or system environment is not overriding your.envfile. - 429 or
insufficient_quota: you are out of credits or over your rate limit. Add credits or slow down. - Key was just revoked or changed: revocations apply within seconds; other auth changes can take up to about 15 minutes to propagate.
Full fixes for every status code are in how to fix OpenAI and Claude API errors.
How do you keep the key safe?
OpenAI’s rule: your key is a secret, so “don’t share it with others or expose it in any client-side code such as browsers or apps.” Load it on the server from an environment variable or a key management service, never commit it to Git, and revoke and replace it if it ever leaks.
Using other providers too? See how to get a Claude API key and how to get a Gemini API key.
FAQ
Is the OpenAI API key free?
Creating a key is free. OpenAI's quickstart lets you run a free test request, then asks you to add credits on the billing page for real use. API usage is billed per token; rates are on OpenAI's pricing page.
Does ChatGPT Plus include an OpenAI API key?
No. ChatGPT subscriptions and the API platform are billed separately. You create API keys and pay for API usage on platform.openai.com.
Where do I find my OpenAI API key?
On the API keys page at platform.openai.com/api-keys. Copy a new key as soon as you create it and store it in a password manager or secret store; if you lose it, create a new key and revoke the old one.
How long does it take for a revoked key to stop working?
OpenAI's API reference says revocations take effect within a few seconds, while most other changes that affect a key's authentication propagate within 15 minutes.
Why do I get 'Incorrect API key provided' with a brand-new key?
Usually an old OPENAI_API_KEY value in your shell or system environment is overriding the one in your .env file, or the key was copied with extra characters. Check which value your code actually loads.
Sources
- OpenAI: Developer quickstart (accessed 2026-10-25)
- OpenAI API reference: Authentication (accessed 2026-10-25)
- OpenAI API: Pricing (accessed 2026-10-25)