How to Get an OpenAI API Key and Make Your First Call
How to get an OpenAI API key and make your first call: add $5 in credits, create a key, run a short Python script. Pricing and limits as of 16 Oct 2026.
Quick answer: Sign in to the OpenAI API platform, add at least $5 in credits, create a secret key, save it as OPENAI_API_KEY, then run a short Python script. Free? No. OpenAI's prepaid billing article says the minimum purchase is $5.
A ChatGPT subscription does not give you an API key. OpenAI's Help Center says ChatGPT and the API platform have separate billing systems. Details below are as of 16 October 2026.
What do you need before you start?
You need an OpenAI account for the API platform, a payment method, and Python installed on your computer. The API is billed separately from ChatGPT, so a Plus or Business plan does not help here. OpenAI's billing guide says to set up API billing separately from ChatGPT.
Checklist:
- An account at the API platform (platform.openai.com), not just chatgpt.com.
- A card to buy prepaid credits. The minimum is $5.
- A supported country. OpenAI's error codes guide lists a 403 "Country, region, or territory not supported" error for unsupported locations.
- Permission to create projects, if you work in a company. Only organization owners can create a project.
How do you get an OpenAI API key? (Method 1: dashboard and Python)
Create the key in the API platform dashboard, then export it as an environment variable and run the official Python SDK. The official quickstart uses exactly this route.
- Go to the API platform at platform.openai.com and sign in or create an account. Verify this step: the sign-up screens may differ by region and login method.
- Add credits. Open the billing page at
platform.openai.com/settings/organization/billing, which OpenAI's error codes guide links for adding credits. Buy at least $5. Verify this step: the button label may differ. - Open the API keys page at
platform.openai.com/api-keys, the link the quickstart labels Create an API Key. - Click + Create new secret key. OpenAI's project guide uses this button name.
- Name the key and choose its permission. The three options are All (the default), Restricted and Read Only. For a first test, All works. Use Restricted later for real apps.
- Copy the key and store it somewhere safe. The quickstart suggests a
.zshrcfile or another text file on your computer. - Set the environment variable (next section).
- Install the SDK and run the script (below).
How do you set the OPENAI_API_KEY variable?
Export the key in your terminal. The quickstart gives these commands, and official SDKs read the variable automatically.
macOS or Linux:
export OPENAI_API_KEY="your_api_key_here"
Windows PowerShell:
setx OPENAI_API_KEY "your_api_key_here"
Replace your_api_key_here with your real key. On Windows, setx applies to future windows only. OpenAI's key safety guide says you must open a new command prompt to use the variable.
How do you run your first call in Python?
Install the SDK with pip install openai, save the script below as example.py, and run python example.py. The structure matches the quickstart, which uses the Responses API.
pip install openai
from openai import OpenAI
client = OpenAI() # Reads OPENAI_API_KEY from your environment. Do not paste the key here.
response = client.responses.create(
model="gpt-6-luna",
input="Say hello in one short sentence.",
)
print(response.output_text)
If it works, you will see one short sentence printed in your terminal. The quickstart's own example uses the model gpt-6-astra. This script uses gpt-6-luna because, on OpenAI's pricing page, it is the lowest-priced of the three flagship models listed (as of 16 October 2026).
Method 2: How do you call the API with curl?
Send a POST request to https://api.openai.com/v1/responses with your key in an Authorization: Bearer header. The quickstart's curl example uses this form, and the authentication reference confirms the bearer header.
curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-luna",
"input": "Say hello in one short sentence."
}'
This is written for macOS and Linux style shells. Windows PowerShell handles quotes and line breaks differently, so Windows users should use Method 1.
Method 3: Can ChatGPT or Codex create the key for you?
OpenAI describes a plugin for this, but you still own the key. The quickstart says the OpenAI Developers plugin connects ChatGPT and Codex to the OpenAI Platform and creates project API keys when your application needs one (a company claim from OpenAI's docs). If you want to try Codex first, see our beginner's guide to OpenAI Codex.
Which method should you choose?
| Method | Cost | Difficulty | Limits | Best for |
|---|---|---|---|---|
| 1. Dashboard + Python SDK | $5 minimum credits | Easy | Needs Python installed | Most beginners |
| 2. curl | $5 minimum credits | Easy to medium | Quoting differs on Windows | Quick tests, any language later |
| 3. OpenAI Developers plugin | $5 minimum credits | Easy | Plugin behaviour is described by OpenAI only | Users already working in ChatGPT or Codex |
What's free and what costs money?
The API costs money from the first real call, and the minimum credit purchase is $5. As of 16 October 2026, OpenAI's prepaid billing article says new accounts are enrolled in prepaid billing, with a $5 minimum and a $10 default.
| Item | What OpenAI's docs say (as of 16 October 2026) |
|---|---|
| Minimum credit purchase | $5, default $10 (prepaid billing) |
| Free credits | Used before paid credits, if you have any |
| Credit expiry | Purchased credits expire after 1 year and are non-refundable |
| Auto-recharge | Minimum $5 |
| gpt-6-luna price | $0.10 per 1M input tokens, $0.50 per 1M output tokens (Standard, short context) |
| gpt-6.1-sol price | $2.00 input, $10.00 output per 1M tokens |
| gpt-6-astra price | $10.00 input, $50.00 output per 1M tokens |
Prices come from OpenAI's pricing page. A token is a small chunk of text, roughly a word fragment. As a worked example, a call with 50 input tokens and 100 output tokens on gpt-6-luna costs 50 x $0.10 / 1,000,000 plus 100 x $0.50 / 1,000,000, which is $0.000055. That is arithmetic from the listed rates, not a measured bill.
What are the usage tiers and rate limits?
OpenAI now has three paid tiers: Build, Launch and Grow. In an announcement dated 6 October 2026, OpenAI said five paid tiers became three and that Grow needs $500 in total API payments. Paid organizations move to their new tier automatically.
| Tier | Qualification | Monthly usage limit |
|---|---|---|
| Free | 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 |
Source: OpenAI rate limits guide, as of 16 October 2026. In the same guide, the Build tier's standard limit for Luna is 5,000 requests per minute and 2,000,000 tokens per minute. A first test will not come close.
How do you stop surprise bills?
Set a hard spend limit. OpenAI's spend limits guide gives these steps:
- Go to Organization limits.
- In Spend, select Edit spend limit.
- Enter the Monthly spend limit.
- Turn on Enforce a hard limit.
- Select Save.
Once the limit is hit, affected requests return a 429 error. The guide also warns that enforcement is not instant, so recorded spend can slightly exceed your cap. A spend alert only sends a notification and does not stop traffic.
What can go wrong, and how do you fix it?
Most first-call failures are a wrong key, no credits or a missing environment variable. OpenAI's error codes guide lists the fixes for the API errors below.
| Error | Likely cause | Fix |
|---|---|---|
| 401 Incorrect API key provided | The key is wrong | Check the key, or generate a new one on the API keys page |
| 401 You must be a member of an organization | Your account is not in an organization | Ask your organization manager to invite you |
| 403 Country, region, or territory not supported | Unsupported location | See OpenAI's supported countries page |
| 429 Credit balance exhausted | No prepaid credits left | Add credits on the billing page |
| 429 Rate limit reached for requests | Sending requests too fast | Slow down and follow the Retry-After header |
| 429 Organization or project spend limit reached | Your own hard limit was hit | Raise or remove the limit |
Two more tips. If a Python script says it cannot find the key, you probably set the variable in a different terminal window. Open a fresh one and run the command again. If you pasted the key into code and shared it, revoke it. OpenAI says revocations take effect within a few seconds.
Retrying will not fix a billing, spend or quota error. The error codes guide says to update credits or limits first.
Is this allowed, and how do you keep the key safe?
Using your own key for your own app is allowed. Sharing it is not. OpenAI's key safety guide says sharing API keys is against the Terms of Use. Invite teammates so each gets their own key.
Rules from OpenAI's docs:
- Never put the key in a browser or mobile app. OpenAI warns that others could use it and run up charges on your account. Route requests through your own backend.
- Never commit the key to a repository, even a private one.
- Use the
OPENAI_API_KEYenvironment variable. - Consider setting an expiration date. Project keys can be created with one, and OpenAI strongly recommends it.
If you want to connect the API to spreadsheets later, see how to use ChatGPT inside Google Sheets and how to pull API data into Google Sheets.
What's still unclear?
Some details are not spelled out in OpenAI's public documentation.
- The Free tier. The rate limits guide lists a Free tier for users in an allowed geography with a $100 monthly limit. It does not say whether you can make calls with no payment at all. The prepaid billing article says new accounts are enrolled in prepaid billing, which points to buying credits first.
- Old wording. The prepaid billing article still talks about "trust tiers" and says more information is coming. The rate limits guide now uses Build, Launch and Grow. Treat the rate limits guide as current.
- Sign-up screens. OpenAI's docs do not give the exact wording of the sign-up and billing screens. Steps 1 and 2 above carry a "verify" note for that reason.
- Prices change. The model names and prices above are from the pricing page on 16 October 2026. Check the page before you budget.
Last checked: 16 October 2026.
Frequently asked questions
Is the OpenAI API free?
No, not in a way you can rely on. OpenAI's prepaid billing article says new accounts are enrolled in prepaid billing, with a $5 minimum purchase and a $10 default. If you have free credits, they are used before paid credits. The rate-limits guide also lists a Free tier for allowed geographies, but it does not say whether calls work without any payment.
Does my ChatGPT Plus subscription include an API key?
No. OpenAI's Help Center says ChatGPT and the API platform have separate billing systems. To start paid API usage you add a payment method in your API billing settings. Your ChatGPT subscription does not cover API charges, because API usage is billed separately.
Where do I store my OpenAI API key?
Store it in an environment variable named OPENAI_API_KEY on the machine that runs your code. OpenAI's key safety guide says never to put the key in browsers or mobile apps and never to commit it to a repository. Official SDKs read OPENAI_API_KEY automatically, so the key never needs to appear in your script.
Why do I get a 429 error on my first call?
A 429 can mean three different things. OpenAI's error codes guide lists exhausted prepaid credits (credit_balance_exhausted), a rate limit reached, and an enforced spend limit. Check your balance first. Retrying will not fix a billing, spend or quota error. Add credits or raise the limit, then call again.
How much does one test call cost?
On OpenAI's pricing page as of 16 October 2026, gpt-6-luna costs $0.10 per 1M input tokens and $0.50 per 1M output tokens (Standard, short context). A test call with about 50 input tokens and 100 output tokens works out to roughly $0.000055, a small fraction of a cent. Your $5 minimum purchase covers a very large number of such calls.
Can I share one API key with my team?
OpenAI says no. Its key safety article states that sharing API keys is against the Terms of Use and that OpenAI does not support it. Invite each person from the Members page instead, so each gets their own key. You can also set permissions on individual keys.
Sources
- Developer quickstart, OpenAI API docs (2026-10-16)
- What is prepaid billing?, OpenAI Help Center (2026-10-16)
- Managing billing for ChatGPT and the API platform, OpenAI Help Center (2026-10-16)
- Managing projects in the API platform, OpenAI Help Center (2026-10-16)
- Best Practices for API Key Safety, OpenAI Help Center (2026-10-16)
- API Overview (authentication), OpenAI API docs (2026-10-16)
- Rate limits, OpenAI API docs (2026-10-16)
- Update to OpenAI API Rate Limits, OpenAI Developer Community (2026-10-06)
- Pricing, OpenAI API docs (2026-10-16)
- Spend limits, OpenAI API docs (2026-10-16)
- Error codes, OpenAI API docs (2026-10-16)