AI Token Price

How to Get Your First AI API Key: OpenAI, Claude, Gemini and More

An API key lets your own code, or tools like OpenClaw and Cursor, use a model directly and pay per token. Here is how to get one, what it costs to start, and how not to leak it.

Guide Published Updated 5 min read By AI Token Price

API key or subscription?

A ChatGPT, Claude or Gemini subscription gives you the chat app. An API key is different: it lets software call the model directly, and you pay for each token used. You need one to build your own app, to run self-hosted agents such as OpenClaw or Hermes Agent, or to use some coding tools with your own account. Subscriptions and API billing are separate at every provider; paying for one does not cover the other.

Not sure which is cheaper for your usage? The API vs subscription calculator compares them.

Which provider should you start with?

  • Google Gemini has a genuine free tier for the API, which makes it the easiest place to experiment.
  • OpenAI has the widest range of prices, from GPT-6 Luna at $0.10 / $0.50 to GPT-6 Astra at $10.00 / $50.00 per 1M tokens.
  • Anthropic (Claude) is a common choice for coding and agents. Claude Haiku 5.5 at $0.10 / $0.50 is the cheapest way to try it.
  • DeepSeek and xAI are worth adding once you know what you need: DeepSeek V4.1 Flash costs $0.30 / $1.20 at peak times and half that off-peak.

You can hold keys with several providers at once, and many tools let you switch between them.

Google Gemini: free to start

  1. Go to Google AI Studio and sign in with a Google account.
  2. Choose Get API key, then create a key. AI Studio can create a Google Cloud project for it if you don't have one.
  3. Copy the key and store it somewhere safe (see below).

The free tier covers Gemini 3.8 Flash, Gemini 3.6 Flash, the Flash-Lite models, Gemma 4 and the embedding, text-to-speech and transcription models. Gemini 4 Argon and Gemini 3.1 Pro are not included (see every provider's free tier). Two catches: free-tier requests are rate-limited (AI Studio shows your limits), and Google may use free-tier prompts and responses to improve its products, so don't send anything confidential. When you need higher limits or privacy, enable billing on the project and you pay the standard rates, such as $0.75 / $3.75 for Gemini 3.8 Flash until 31 December 2026.

OpenAI

  1. Sign up at platform.openai.com. This is a separate account area from ChatGPT, though you can use the same login.
  2. Open the billing settings and add a payment method. API usage is prepaid: you buy credit, and requests are charged against it.
  3. Go to API keys, create a new secret key, and copy it immediately. OpenAI shows the full key only once.

We found no free credit for new accounts on OpenAI's own pages, so plan to add a small amount, such as $5 or $10, to start. OpenAI does offer free daily tokens to eligible organisations that agree to share their API inputs and outputs for training: up to 1M tokens a day across the GPT-6 models and GPT-5.6 Sol, and up to 10M a day on GPT-5.6 Terra, Luna and the mini models, on OpenAI's Launch and Grow plans (a quarter of that on Build). Paid ChatGPT Pro and Business subscribers can also claim monthly API credits, up to $500 a month. You still need a positive balance, and you should not opt in for data you can't share. Details are in OpenAI's help article.

Anthropic (Claude)

  1. Sign up at the Claude Developer Platform. A Claude Pro subscription doesn't include API credit; Max includes $100 a month of Claude Platform API credit and Ultra $200, which you claim in the Developer Platform.
  2. Add a payment method and buy credit. Anthropic bills API usage in advance; its pricing page says new users get a small amount of free credit to test the API, so expect to add your own credit soon.
  3. Create a key under API keys and copy it.

New accounts start with lower rate limits, which rise automatically as you spend more over time. Claude's cheapest model is Haiku 5.5; Sonnet 5.5 at $2.00 / $10.00 is the usual choice for agents and coding.

xAI and DeepSeek

Both work the same way: create an account in the developer console (console.x.ai or platform.deepseek.com), add credit, and create a key. Both APIs accept requests in the same format as OpenAI's Chat Completions API, so code and tools written for OpenAI usually work after changing the base URL and model name.

Keep the key secret

Anyone with your key can spend your credit. Leaked keys are found by automated scanners within minutes of being pushed to a public repository.

  • Never put a key in front-end code (a web page, a mobile app, a browser extension). Call the API from your server, and have your app talk to your server.
  • Keep keys out of source control. Store them in environment variables or a secrets manager, and add files like .env to .gitignore.
  • Use one key per project, so you can revoke one without breaking everything else and see where spending comes from.
  • Set a spending limit or budget alert in the provider's billing settings. With prepaid credit, keep the balance modest and turn off auto-recharge until you trust your usage.
  • Revoke and replace a key the moment you suspect it has leaked.

Make your first request

Save the key as an environment variable first, for example export OPENAI_API_KEY="..." on macOS or Linux. Then, from a terminal:

OpenAI

curl https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-6-luna", "messages": [{"role": "user", "content": "Say hello in five words."}]}'

Anthropic

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{"model": "claude-haiku-5-5", "max_tokens": 200, "messages": [{"role": "user", "content": "Say hello in five words."}]}'

Google Gemini

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"contents": [{"parts": [{"text": "Say hello in five words."}]}]}'

Each response includes a usage section with the number of input and output tokens, which is exactly what you are billed for. A test like this costs a tiny fraction of a cent.

What will it cost?

For a personal project, very little. A thousand short chat messages (about 1,500 tokens in and 300 out each) cost $0.30 on GPT-6 Luna, $2.25 on Gemini 3.8 Flash and $6.00 on Claude Sonnet 5. Agents cost much more, because they resend their whole context at every step; the agent cost calculator shows how quickly that adds up. For everything else, use the token cost calculator or see how AI pricing works.

Prices in this article come from each provider’s pricing page or, for open-weight models sold by other hosts, the cheapest host listed on OpenRouter. Live prices are always on the price table; tables marked “updates automatically” use current data.

More guides

All guides