API key
An API key is a secret string an application sends with each request so that a service can tell which account is calling, apply its limits and bill it. Anyone holding the key can usually use it.
Also called: API token, secret key
By Divya Sharma · Checked Nov 15, 2026 · How we review
Almost every hosted model, from the big labs to inference providers, is reached with an API key. You create it in the provider's console and send it in a request header. The provider uses it to find your account, apply your rate limits and charge your usage at its token prices.
What a key does and does not prove
A basic API key identifies a project or account, not a person. Google's documentation says so directly: a standard key does not authenticate a principal. Whoever has the string can spend your money and, depending on the service, read your data. That makes a key closer to a password than a username.
Keeping keys safe
Keep keys on the server, in environment variables or a secrets manager, and never in front-end code, mobile apps or a public repository. Use separate keys per environment or project so one can be revoked without breaking the rest. Where the provider allows it, restrict a key to certain APIs, IP addresses or workspaces, set an expiry, and set a spending limit. Google warns that unrestricted keys are insecure. Rotate any key that may have leaked.
API keys and agents
Coding agents and MCP servers often need keys for the tools they call. Passing a long-lived key into an agent's context or config gives the agent, and anything that can inject a prompt into it, the same power. Delegated, scoped tokens through OAuth are the safer pattern where a service supports them. An LLM gateway can also hold provider keys centrally and hand out its own keys with tighter limits.
Related terms
- OAuth for AI agents
- OAuth for AI agents is the use of the OAuth authorization standard to let an agent or MCP client act on a user's behalf with a limited, revocable access token, instead of holding the user's password or a broad API key.
- Rate limit (API)
- A rate limit caps how much an account can use an API in a time window, typically as requests per minute (RPM) and tokens per minute (TPM). Requests over the limit are rejected, usually with an HTTP 429 error.
- LLM gateway
- An LLM gateway is a proxy server between your applications and model providers that exposes one API and handles keys, routing, fallbacks, rate limits, logging and spend tracking in a single place.
- Token pricing
- Token pricing is how most AI model APIs charge: a set price per million input tokens you send and a separate, usually higher, price per million output tokens the model generates, with discounts for cached input and batch jobs.
- Prompt injection
- Prompt injection is an attack where text fed to a language model, typed by a user or hidden in a web page, file or tool result, changes the model's behaviour in ways its developer did not intend.