EnglishEN

How to get a Claude, ChatGPT and Gemini API key, and check pricing and free limits

Get an API key from each company's console with «Create key», and put it in an environment variable instead of writing it in code. Only Gemini has a free tier; ChatGPT and Claude charge for what you use.

Where to goaistudio.google.com/apikeyplatform.openai.com/api-keysplatform.claude.com/settings/keys

Steps

  1. If this is your first time, get just one key. You can follow Part 3 with a single Gemini key. For Gemini, sign in at https://aistudio.google.com/apikey and click «Create key».
    Entrance to the Google AI Studio API key screen
    Entrance to the Google AI Studio API key screen
    Entrance to the Claude Console API keys screen
    Entrance to the Claude Console API keys screen
    List of API keys made in Google AI Studio (key text hidden)
    List of API keys made in Google AI Studio (key text hidden)
    Entrance to the OpenAI API keys screen
    Entrance to the OpenAI API keys screen
  2. Many places show the long string only once, when you create it, so put it in right away as in the next step.
    Gemini API pricing table
    Gemini API pricing table
    OpenAI API pricing table
    OpenAI API pricing table
    Claude API pricing table
    Claude API pricing table
  3. Mac: open Terminal (Applications › Utilities › Terminal), put the key you got in place of YOUR_KEY_HERE, and enter it one line at a time.
    echo 'export GEMINI_API_KEY="YOUR_KEY_HERE"' >> ~/.zshrc
    source ~/.zshrc
    echo ${GEMINI_API_KEY:0:6}
    Claude Console spend limit screen (amount hidden)
    Claude Console spend limit screen (amount hidden)
  4. Windows: enter it in Command Prompt (cmd), then close the window, open a new one, and check.
    setx GEMINI_API_KEY "YOUR_KEY_HERE"
    echo %GEMINI_API_KEY%
  5. Get a first answer with one line in Terminal (Mac/Linux). It worked if the answer is inside the long block of text.
    curl -X POST "https://generativelanguage.googleapis.com/v1beta/interactions" \
      -H "x-goog-api-key: $GEMINI_API_KEY" \
      -H 'Content-Type: application/json' \
      -H "Api-Revision: 2026-05-20" \
      -d '{"model": "gemini-4-hydrogen", "input": "Say hello in French, one word only"}'
    Screen after getting the first Gemini answer in Terminal
    Screen after getting the first Gemini answer in Terminal
  6. For ChatGPT and Claude keys, only change the name to OPENAI_API_KEY or ANTHROPIC_API_KEY and set it the same way.

Where to get keys and the names programs read

  • Gemini: https://aistudio.google.com/apikey · GEMINI_API_KEY
  • ChatGPT (OpenAI): https://platform.openai.com/api-keys · OPENAI_API_KEY
  • Claude: https://platform.claude.com/settings/keys · ANTHROPIC_API_KEY

Is it free?

  • Gemini: there is a free tier. The models you can use and the daily limits are listed per model on the pricing page. The free tier is marked «content used to improve Google products», and the paid tier «not used».
  • ChatGPT (OpenAI): we could not find a free tier description on the pricing page. You pay for what you use.
  • Claude: we could not find a free tier description on the pricing page. You pay for what you use.
  • Practice on Gemini's free tier; do work that involves customer text or personal data on a paid tier or another API.

Adding a card and checking pricing

API pricing is by the «token». A token is a small piece of text, and pricing pages usually list a price «per million tokens». Text you send (input) and text you get back (output) are priced differently.

Prices change often, so this guide gives no amounts, only links to each company's pricing page. Check that day's price at the link before paying.

On the billing screen, first look for a field that sets a monthly spending cap. Setting it low at the start keeps you from spending a lot by mistake.

In the Claude Console, open the spend limit menu under spend and usage; the monthly spend limit there can be changed with the adjust limit button.

If a key leaks

  • Go back to where you got the key, delete it, and make a new one. A deleted key stops working right away.
  • Put the new key in again by the steps above.
  • Check that the key does not appear in code files, screenshots or blog posts. When posting, show only a stand-in like YOUR_KEY_HERE.

Troubleshooting

  • Permission denied on the service. (403): the request went out without the key. On a Mac, check that you ran source ~/.zshrc; on Windows, check that you opened a new window.
  • API key not valid. Please pass a valid API key.: the key was entered wrong, or spaces or quotes got in before or after it. Copy the key again and paste it in.
  • echo prints nothing: on a Mac, check that you ran source ~/.zshrc; on Windows, check that you opened a new window.
  • You entered the key line twice: on a Mac the same line goes into ~/.zshrc twice. The lower line is the one used, so you can tidy it up later.
  • You hit the free tier limit: the daily limit differs by model. Check the row for your model in the pricing table.

Source

Related posts