Deutsch

API key

Checked 26 October 2026 · by A.Frick

In shortAn API key is a secret code that lets a program call an AI service on your account, and the usage is billed to you.

In plain words

An API key is a long string of letters and digits. When a program sends a request to an AI service, it adds the key. The provider reads it, knows which account or project to charge, and answers. The key works like a password and a credit card in one: whoever holds it can use your quota and run up your bill.

An API key is not the same as a chat subscription. A paid chat plan and an API account are billed separately. The page subscription vs API explains the difference, and AI subscriptions lists the plans.

Why it matters

What to do:

  1. Keep the key out of your code, screenshots, chats and public repositories. Use an environment variable or a secret manager.
  2. Use one key per project, so you can revoke one without breaking the rest.
  3. Never put a key in a web page or mobile app that users can inspect. Call the AI service from your own server instead.
  4. Set a spending limit. Anthropic, for example, lets you set your own monthly spend limit below your tier's cap, and once it is reached, requests fail until the limit is raised or the month turns. See how to create an API key with a spending limit.
  5. If a key leaks, revoke it at once, create a new one and check your usage.

Example

A developer commits a small script to a public code site. The script contains the key as plain text. Within hours, automated scanners find it and use it. The developer sees an unexpected bill. A key read from an environment variable, with a low spending limit, would have limited the damage.

Common misconceptions

Questions and answers

What is an API key used for?

It identifies your account to an AI service so that software can send requests and the provider can bill the use to you.

What should I do if my API key leaks?

Revoke it in the provider's console right away, create a new key, update your apps and check recent usage for charges you did not make.

How do I limit what an API key can cost?

Set a spending limit in the provider's billing settings, use one key per project and watch the usage page. See the guide linked above.

Read next

  • Rate limit

    A rate limit caps how many requests or tokens you may send to an AI API in a set time; going over returns an error, usually HTTP 429.

  • Price per million tokens

    Price per million tokens is the usual way AI APIs state their rates: what you pay for each million tokens sent in or generated.

  • Create an API key and set a spending limit

    Create a key, keep it out of your code, cap your monthly spend and know how to switch it off, with steps for OpenAI, Anthropic and Google.

  • Subscription or API: what is cheaper for you?

    A flat $20 plan or pay per token: one formula and three examples show where each wins, plus the limits and privacy settings that count beyond cost.

  • What not to paste into AI chatbots

    Passwords, client data, IDs and secrets do not belong in a chatbot: a traffic-light checklist, provider data rules, Swiss and EU basics, and safer options.

Sources

  1. OpenAI — Production best practices (API keys)
  2. Google — Using Gemini API keys
  3. Anthropic — Rate limits

Was this page helpful?

Ask a question, report an error or suggest a topic

Stored only to answer or improve this page. No newsletter, no sharing. Privacy