How to Get an API Key: Claude, OpenAI, Gemini, Grok
Step-by-step: how to get an API key from Claude, OpenAI, Gemini, Grok and DeepSeek, what each one costs to use, and how to keep the key safe. Every step is checked against the provider's own docs.
How to get an API key from Claude (Anthropic)
- Sign up or sign in at the Claude Console (platform.claude.com).
- Open Settings > API keys (platform.claude.com/settings/keys) and create a key.
- Add credit under billing, then set it as ANTHROPIC_API_KEY in your terminal.
Open the Claude (Anthropic) key page. Using it costs from $8 per million input tokens on Claude Fable 5.2; see Claude API pricing.
How to get an API key from OpenAI
- Sign in at the OpenAI Platform and open the API keys page (platform.openai.com/api-keys).
- Create a key and store it somewhere safe; you won't see it again.
- Export it as OPENAI_API_KEY. Add credits to go beyond a first test request.
Open the OpenAI key page. Using it costs from $8 per million input tokens on GPT-6.2 Astra Pro; see OpenAI API pricing.
How to get an API key from Gemini (Google)
- Sign in to Google AI Studio. New users get a project and key created automatically.
- Copy it from the API keys page, or click Create API key for a new one.
- Export it as GEMINI_API_KEY. The free tier works straight away; set up billing for higher limits.
Open the Gemini (Google) key page. Using it costs from $3 per million input tokens on Gemini 4 Neon; see Gemini API pricing.
How to get an API key from Grok (SpaceXSI)
- Sign up at console.x.ai and load credits.
- Create a key on the API Keys page.
- Export it as XAI_API_KEY. It works with the OpenAI SDK at https://api.x.ai/v1.
Open the Grok (SpaceXSI) key page. Using it costs from $2 per million input tokens on Grok 4.7; see Grok API pricing.
How to get an API key from DeepSeek
- Sign up on the DeepSeek Platform and top up your balance.
- Create a key under API keys.
- Use it with the OpenAI SDK at https://api.deepseek.com, model deepseek-flash.
Open the DeepSeek key page. Using it costs from $0.3 per million input tokens on DeepSeek V4.1 Flash 1017; see DeepSeek API pricing.
Want one key for every model?
OpenRouter gives you one key that reaches models from all of these labs at the same prices, plus a 5.5% fee on credit purchases, and has free models too. See how to get a free LLM API key for the steps.
Keep your key safe
- Never put a key in a website or app people can downloadAnyone can read it and spend your credit. Call the API from your own server.
- Store it as an environment variableThe official SDKs read OPENAI_API_KEY, ANTHROPIC_API_KEY and GEMINI_API_KEY automatically.
- Don't commit it to GitHubLeaked keys get found by bots within minutes. If one leaks, delete it and make a new one.
- Set a spend limitThe Claude Console and other dashboards let you cap monthly spend.
Steps checked against each provider's quickstart on 22 November 2026.
Next: compare prices
Ready to pick a model? See the LLM API pricing table for all 360 models, the cheapest LLM APIs, and the cost calculator. By lab: Claude, OpenAI, Gemini, DeepSeek, Grok, Mistral, Qwen, Kimi, Meta Llama.
Questions
Is an API key free?
Creating a key is free everywhere. Using it costs money per token, except on free tiers such as Gemini's or OpenRouter's free models.
How do I get a Claude API key?
Sign in at platform.claude.com, open Settings > API keys, and create a key. Add credit to start making requests.
How do I get an OpenAI API key?
Sign in at platform.openai.com, open the API keys page and create a key, then export it as OPENAI_API_KEY.
How do I get a Gemini API key?
Sign in to Google AI Studio: new users get a key automatically on the API keys page, and the free tier works without billing.
Is a ChatGPT or Claude subscription the same as an API key?
No. Subscriptions are for the chat apps; the API is billed separately per token through the developer console.
Get this in your inbox at 7am
One free email each morning with the AI repos, models and stories that are picking up speed, including new free models. Your own time zone, no spam.