How to Get an OpenAI API Key
Status: 🟩 COMPLETE 🟦 LIVING Section: how-to Tags: openai, api-key, developer, setup, walkthrough
What you’re doing and why
An API key is a long secret string that identifies you when an application (or a script you write) connects to OpenAI’s services. You need one if you want to:
- Build an app or website that uses ChatGPT-like AI
- Use developer tools (Cursor, Cline, Continue.dev) that talk to OpenAI’s models directly
- Run scripts that generate text, images, or audio using OpenAI’s models
- Use Whisper for transcription
- Use DALL·E for image generation programmatically
You do not need an API key if you only use ChatGPT through the website or mobile app — your account login handles that automatically.
This guide takes about 10 minutes from start to finish.
What you need
- A web browser
- An email address (you can use your existing ChatGPT account)
- A credit card or other payment method (OpenAI requires this even for low usage)
- A few minutes uninterrupted
Step-by-step
Step 1 — Go to OpenAI’s developer platform
Open https://platform.openai.com in your browser.
This is different from chat.openai.com (which is for using ChatGPT) — platform.openai.com is the developer portal.
Step 2 — Sign in
If you have a ChatGPT account, use the same login. If not, sign up. The signup is similar to the ChatGPT signup (sign-up-for-chatgpt).
Step 3 — Add a payment method
Before creating an API key, you must add billing:
- Click your name (top right) → Billing
- Click Add payment details
- Choose Individual (for personal projects) or Company (for business use)
- Enter your credit card details
- Important: Add prepaid credit (e.g., $10 USD) — OpenAI uses a prepaid model. You add money, the API draws down from it.
Tip: Start with 20 USD to test. You can always add more.
Step 4 — Set a usage limit (recommended)
This protects you from accidentally racking up huge bills if your code has a bug:
- Settings → Limits
- Set Monthly budget to something reasonable (e.g., 50)
- Set Soft limit (notification at this point) lower (e.g., $15)
- Set Hard limit (API stops working at this point) at your monthly budget
This is essential — without limits, a runaway script could rack up hundreds of dollars overnight.
Step 5 — Create your API key
- Dashboard → API keys (left sidebar)
- Click + Create new secret key
- Give it a name describing where you’ll use it (e.g., “Personal MacBook,” “My website production”)
- Optionally set Permissions (you can leave at “All” for general use)
- Click Create secret key
- CRITICAL: Copy the key shown (starts with
sk-...) and save it somewhere safe - You will NOT be able to see this key again — only the first 4 and last 4 characters are visible later
Where to save the key:
- âś… A password manager (1Password, Bitwarden, Apple Keychain)
- âś… Environment variable file on your computer (
.envfile — for developers) - ❌ Don’t email it, paste in chat, or commit to GitHub
- ❌ Don’t share with anyone
Step 6 — Test the key works
The simplest test, using the OpenAI Playground (also at platform.openai.com):
- Playground → Chat (in the left sidebar)
- Type a test message: “Hello, are you working?”
- Click Submit
- You should get a response from GPT — billed to your API account
If you’re using it in a tool (Cursor, Cline, etc.), follow that tool’s instructions for adding an OpenAI API key.
Common uses
In Cursor
Settings → Models → OpenAI API key → paste your key. Cursor will now use your OpenAI account directly for AI features.
In Cline (VS Code extension)
Click the Cline icon → Settings → API Provider: OpenAI → paste your key.
In a Python script
import openai
client = openai.OpenAI(api_key="sk-your-key-here")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)(But never hard-code your key like this — use environment variables. See add-memory-file for environment variable patterns.)
In Continue.dev or other dev tools
Each tool has settings for “OpenAI API key” — paste your key when prompted.
What does API use cost?
OpenAI charges per token (a token is roughly Âľ of a word):
| Model | Input | Output |
|---|---|---|
| GPT-4o | $2.50/million tokens | $10/million tokens |
| GPT-4o Mini | $0.15/million | $0.60/million |
| o3-mini | $1.10/million | $4.40/million |
| o3 | $10/million | $40/million |
| Whisper | $0.006/minute (audio) | — |
| DALL·E 3 | $0.04/image (standard) | — |
Practical example:
- A typical chat conversation might use 1,000 input tokens + 500 output tokens with GPT-4o = $0.0075 per turn
- Heavy daily use (100 turns/day with GPT-4o): 22.50/month
- Light use (5 turns/day): $1.13/month
Always set your monthly limit to protect against unexpected costs.
Australian-specific notes
- Currency: All API pricing is in USD. Your AUD bill will fluctuate with the exchange rate.
- GST: OpenAI charges 10% GST on Australian customers. Pricing displayed is typically pre-GST.
- Tax invoice: For business use, ensure your Billing details have your ABN — OpenAI will then issue a proper tax invoice.
- Expensing: Business use of API is generally deductible. Keep records.
Privacy considerations
- API usage is NOT used to train OpenAI’s models (this is different from free ChatGPT). API content has strong data protection.
- 30-day retention: OpenAI retains API content for 30 days for abuse monitoring, then deletes. Zero Data Retention is available for enterprise customers.
- For sensitive data: Even with API protections, don’t send extremely sensitive content unless you have appropriate enterprise agreements. The Australian Privacy Act applies if personal information is involved.
Rotating and revoking keys
You should rotate (replace) API keys periodically and immediately if you suspect compromise:
- API keys → find your key in the list
- Click the trash icon to revoke it
- Create a new key
- Update wherever the key was used
If you accidentally committed a key to GitHub (or any public location), revoke it IMMEDIATELY — OpenAI’s automated scanners often catch this and may auto-revoke, but don’t rely on that.
Common gotchas
- “Insufficient quota” error — you ran out of prepaid credit. Top up at Billing.
- Hard limit hit — adjust your monthly budget or wait until next month.
- Rate limit errors (429) — your usage exceeded OpenAI’s rate limits. Different tiers have different limits. Higher usage automatically increases your limits.
- Authentication errors (401) — key is wrong or revoked. Check your key.
- The API uses different models than ChatGPT website — e.g., GPT-4o is on both, but features like o3 reasoning may differ between Plus and API. Check the model docs.
See also
- sign-up-for-chatgpt — using ChatGPT without an API key
- openai-api — overview of the API
- get-an-anthropic-api-key — Claude’s API
- get-a-google-ai-api-key — Gemini’s API
- australian-privacy-considerations
Sources
- OpenAI Platform documentation: platform.openai.com/docs
- OpenAI pricing: platform.openai.com/docs/models#pricing
- OpenAI API Terms of Use
- Tested signup flow (June 2026)