An API key is a personal password for software. When a program — a script, an app, a tool — talks to an AI company's servers, the key tells the company who is asking, so they know whose account to bill and can shut the key off if it's stolen. It's a long random string like sk-ant-api03-x7Kd9… that you copy once and keep secret.
You need one when software has to talk to the AI on your behalf: you're building an app or script, a tool you installed asks for a key, you want to process things in bulk, or you're wiring AI into spreadsheets and automations.
You don't need one to simply chat — the consumerchatapps are easier and often cheaper for that. Note that ChatGPT Plus, Claude Pro, and similar subscriptions are separate products: they upgrade the chat experience but include no API access. And if a random website asks you to paste your key in, that's usually a scam.
Billing is pay-per-use, not a subscription — you're charged per token (roughly ¾ of a word). Casual tinkering costs cents, but always set a spending limit: a buggy script in a loop can rack up charges. Each walkthrough below points out where.
Do I need a key?
→I just want to chat with an AI
→A tool or app is asking me for a key
→I want to write code or scripts that use AI
→I want to automate a repetitive task
→I want better answers than the free chat gives
Yes — you need an API key. Pick a provider below; most take under ten minutes. If a third-party tool asked for the key, check which providers it supports first.
Probably not. The chat apps are the better fit — paid subscriptions there upgrade chatting. API keys are for when software needs to talk to the AI.
Providers
Google Gemini
— the easiest start.
aistudio.google.com · free tier · no card · ~2 minutes
0 of 4 done — click the circles as you go
✓Sign in to Google AI Studioshowhide
Go to aistudio.google.com and sign in with any Google account — the one you use for Gmail works fine. No application, no waitlist.
✓Click “Get API key” and create a keyshowhide
Find the Get API key button (top-left or in the sidebar) and click Create API key. That's it — the key appears instantly, no card required.
The key starts with AIza and is shown once. Copy it into a password manager right away.
✓Understand the free tiershowhide
The free tier gives a daily and per-minute allowance on many Gemini models — plenty for learning. Exact limits change often; check the rate limits page.
On the free tier Google may use your prompts to improve its products. If that matters, link a Google Cloud billing account in AI Studio to go paid.
✓Test your keyshowhide
No technical skills needed: copy the address below, replace YOUR_KEY with your key, and paste it into your web browser's address bar like a normal link.
A wall of text listing model names means your key works. A short message saying "API key not valid" means a copy-paste slip — grab the key again. And if a tool asked you for the key in the first place, pasting it there is a perfectly good test too.
Comfortable with the command line? On a Mac, press ⌘ space, type Terminal, hit Enter, then paste this. (Windows: open PowerShell from the Start menu, type curl.exe instead of curl, and keep it on one line.)
Sign up at platform.openai.com with email, Google, Microsoft, or Apple. You'll verify your email and phone number.
This is not the same as ChatGPT — a ChatGPT Plus subscription includes no API access, and API charges are billed separately.
✓Add a payment method and buy creditsshowhide
Go to Settings → Billing, add a card, and load at least about $5 of prepaid credit. There are no free trial credits these days — without credit, requests fail or are heavily limited.
✓Set a spending limitshowhide
Still in Billing, set a monthly budget. This is the safety net against a runaway script — $5–10 a month is plenty for learning.
The key starts with sk- and is shown once. Lost it? Delete it and make a new one — keys are free.
✓Test your keyshowhide
The easiest test: paste the key into the tool or app that asked for it — if it starts responding, you're done. To check your account is live, you can also chat in the Playground, which runs on your credits right in the browser.
Comfortable with the command line? On a Mac, press ⌘ space, type Terminal, hit Enter, then paste this. (Windows: open PowerShell, type curl.exe instead of curl, one line.)
Sign up at console.anthropic.com with email or Google and verify your email. There's no approval queue — access is immediate.
The API is separate from the claude.ai chat app; a Claude Pro subscription includes no API credits.
✓Add billing and buy creditsshowhide
In Settings → Billing, add a card. Anthropic runs on prepaid credits — a small top-up like $5 goes a long way for learning. Auto-reload is optional and off by default.
The key starts with sk-ant- and is shown once — copy it before closing the dialog.
✓Try the Workbench (optional)showhide
The console includes a Workbench — a playground where you chat with Claude models on your credits, tweak settings, then export the exact code for what you built. A nice way to learn before writing any code.
✓Test your keyshowhide
The easiest test: paste the key into the tool or app that asked for it — if it starts responding, you're done. The Workbench from the previous step is the other friendly check: if you can chat there, your account and credits are working.
Comfortable with the command line? On a Mac, press ⌘ space, type Terminal, hit Enter, then paste this. (Windows: open PowerShell, type curl.exe instead of curl, one line.)
console.x.ai · promo credits to start · card later · ~5 minutes
0 of 4 done
✓Create an account at console.x.aishowhide
Sign up at console.x.ai with email, Google, or your X account. Accept the terms and finish the short onboarding.
✓Check your promo creditsshowhide
New accounts have typically received around $25 in promotional credits, often expiring after ~30 days — enough to try Grok without a card. xAI has also offered monthly credits in exchange for letting them train on your API traffic; read the fine print before opting in.
Promo offers change frequently — whatever the console shows you today is the truth.
✓Create an API keyshowhide
In the console sidebar, open API Keys → Create API Key. Name it, optionally restrict which endpoints and models it can reach, and create.
The key starts with xai- and is shown once. While you're in settings, set a monthly spending cap.
✓Test your keyshowhide
The easiest test: paste the key into the tool or app that asked for it — if it starts responding, you're done. You can also chat with Grok in the console's playground to confirm your credits are working.
Comfortable with the command line? On a Mac, press ⌘ space, type Terminal, hit Enter, then paste this. (Windows: open PowerShell, type curl.exe instead of curl, one line.)
Llama models are open-weight — Meta releases them for anyone to run. Meta's own hosted Llama API has been gated behind a waitlist and focused on US users. The good news: because the models are open, many other companies host them, often with instant signup and free tiers.
✓Option A — join Meta's official waitlistshowhide
Visit llama.developer.meta.com, sign in with a Meta account, and request access. Once approved, create a key in the dashboard. The endpoint is OpenAI-SDK compatible via api.llama.com/compat/v1/.
✓Option B — use a hosting provider (recommended)showhide
These give you Llama models today, no waitlist: Groq (famous for speed, free tier), OpenRouter (one key for hundreds of models, including some free Llama variants), and Together AI (big open-model catalog, pay-as-you-go).
Each follows the same recipe you've seen: sign up → maybe add billing → create key → copy it once → keep it secret.
✓Test your key (Groq example)showhide
The easiest test: paste the key into the tool or app that asked for it — if it starts responding, you're done. On Groq, the console's playground also lets you chat with Llama models right in the browser, confirming your account works.
Comfortable with the command line? On a Mac, press ⌘ space, type Terminal, hit Enter, then paste this. (Windows: open PowerShell, type curl.exe instead of curl, one line.)
Model names vary by host — check their model list pages.
At a glance
Google Geminifree tier, no cardAIza…
OpenAI~$5 prepaid, card requiredsk-…
Anthropicprepaid credits, card requiredsk-ant-…
xAI Grok~$25 promo credits, card laterxai-…
Meta Llamawaitlist — or free via Groq / OpenRoutervaries
Keeping keys safe
Treat a key like a credit card number — anyone who has it can spend your money. Never put keys in code you share; bots scan public repositories and find leaked keys within minutes. Use environment variables or a .env file instead, set spending limits before writing any code, and use one key per project so a leak only costs you that one. If a key does leak, revoke it in the console and make a new one — it takes thirty seconds.
# the standard safe pattern (Mac/Linux terminal)
export OPENAI_API_KEY="sk-..."
export ANTHROPIC_API_KEY="sk-ant-..."
export GEMINI_API_KEY="AIza..."
export XAI_API_KEY="xai-..."
# most tools and SDKs find these automatically