# API key

> An API key is a secret string that identifies and authenticates the caller of an API. You include it with each request, usually in an HTTP header, and the service uses it to decide whether to accept the request, which account to bill and which limits apply. Anyone who holds the key can act as you, so it must be stored and handled like a password.

Source: https://similariq.ai/glossary/api-key · Updated 2026-11-25

## What an API key is

An API key is a long, random-looking string issued by a service to a customer or an application. When your code calls the service, it sends the key along. The service looks the key up, finds the account it belongs to and treats the request as coming from that account. If the key is missing, unknown or revoked, the request is refused, normally with an HTTP 401 status.

A key does two jobs at once. It identifies: it tells the service who is calling. It authenticates: possession of the secret is taken as proof that the caller is allowed to act for that account. Unlike a username and password pair, a key is designed for programs, not people. It is generated by the service, never chosen by the user, and is meant to be pasted into configuration, not memorised or typed at a login screen.

## Why API keys matter

Any service that costs money to run, holds private data or needs to prevent abuse has to know who is on the other end of a request. A key is the simplest way to provide that. With it, a provider can meter usage, charge the right account, apply [rate limiting](https://similariq.ai/glossary/rate-limiting) per customer and cut off a caller that misbehaves without affecting anyone else.

For the customer, a key is what makes automation possible. A person can sign in through a browser, but a scheduled job, a server or an unattended agent cannot click through a login page. A key lets that software authenticate without a human present. It also gives the customer control: a separate key per application means one can be withdrawn while the others keep working.

## How API keys work

The lifecycle has four stages. You create a key in the provider's dashboard or through a management endpoint. The provider shows you the full value, often only once, and from then on displays just a prefix or the last few characters so you can tell keys apart. You store the value somewhere your application can read it. On each request, your application attaches it, and the provider checks it before doing any work.

Keys are usually sent in an HTTP header, not in the URL. Two conventions are common: a custom header such as `X-API-Key`, or the standard `Authorization` header with the `Bearer` scheme. Headers are preferred because URLs tend to end up in logs, browser history and analytics. Many providers add a recognisable prefix to their keys, which helps people spot the key type and helps automated scanners detect a key that has been committed to a code repository by mistake.

- Create: generate the key in the provider's app or API.
- Store: place it in an environment variable or a secrets manager.
- Send: attach it to each request in a header over HTTPS.
- Rotate: replace it periodically or after any suspected exposure.
- Revoke: delete it when the application or person no longer needs access.

## A hypothetical example

Suppose a developer is building a nightly job that pulls exchange rates from a currency service. She signs in to the service, creates a key named nightly-rates and copies the value into her deployment platform's secret store under the name `RATES_API_KEY`. Her code reads that variable at start-up and adds it to the header of each request. The key never appears in the source code or the repository.

Three months later a contractor leaves the project. He had access to the staging environment, which used a different key. The developer revokes the staging key and issues a new one. Production is untouched because it never shared a credential with staging. Had both environments used one key, she would have had to replace it everywhere at once and accept a short outage while the change rolled out.

## API keys compared with OAuth tokens

API keys and OAuth tokens both authorise requests, but they suit different situations. A key is static. It is issued once, lasts until revoked and usually carries the full permissions of the account or of whatever scope the provider allows. That simplicity is ideal for server-to-server calls you control. The drawback is that a leaked key works for whoever has it until someone notices.

OAuth is a delegation protocol. A user signs in with the provider and approves a specific application, which then receives tokens that are typically short-lived and can be refreshed. The application never sees the user's password, and access can be withdrawn per application. That makes OAuth the better fit when a third-party tool acts for a user, such as an AI assistant connecting to a [remote MCP server](https://similariq.ai/glossary/remote-mcp-server). Many services offer both and let you choose by context.

## Common mistakes

The most common mistake is putting a key where others can read it. Keys get hard-coded into source files and pushed to shared repositories, embedded in front-end or mobile code where any user can extract them, pasted into chat messages and tickets, or printed in application logs. A key in client-side code should be assumed public. Calls that need a secret belong on a server you control.

The second group of mistakes is about scope. One key is shared across every environment and every teammate, so nobody can tell whose usage is whose and revoking it breaks everything. Keys are never rotated. Old keys for retired projects stay active for years. And when a leak is suspected, people hesitate. The correct response is to revoke first and investigate afterwards, because a replacement key takes minutes and an abused one can cost far more.

## How to evaluate key handling

For your own practice, ask a few direct questions. Can you list every active key and say what uses it? Is each one stored in a secrets manager or environment variable, not in code? Could you revoke any single key today without an outage elsewhere? Do you watch usage per key, so an unexpected spike is visible? If the answer to any of these is no, that is the place to start.

For a provider, look at what its key system lets you do. Useful properties include showing the secret only once, letting you revoke a key immediately, accepting keys in headers instead of query strings, returning a clear error for a bad key, and offering spend limits so that a leaked key has a bounded cost. A balance or usage endpoint is valuable too, because it lets your own monitoring catch surprises early.

## How it shows up in SimilarIQ

SimilarIQ keys begin with `sk-live-`. You create them in the app, the value is shown once, and a key can be revoked at any time with immediate effect. A request carries the key either as `X-API-Key: sk-live-...` or as `Authorization: Bearer sk-live-...`. A missing or invalid key returns 401. One key works across the [REST API](https://similariq.ai/features/rest-api), the SDKs, the CLI and the MCP server, and the CLI and SDKs can read it from the `SIMILARIQ_API_KEY` environment variable. See the [API keys feature page](https://similariq.ai/features/api-keys) and the [docs](https://similariq.ai/docs).

Because app searches, API calls and MCP tool calls draw on one balance at $0.25 per search, a key is effectively a way to spend that balance. Two controls bound the exposure. Auto-refill is optional, and a monthly cap you set is a hard ceiling on what your card can be charged, as described under [spend controls](https://similariq.ai/features/spend-controls). Assistants that support it can use OAuth 2.1 instead of a key.

## Related terms

API keys sit among several terms about calling services safely. Rate limiting is the control a provider applies per key to keep usage fair. A bearer token is any credential that grants access to whoever presents it, which describes both API keys and OAuth access tokens. A secrets manager is the system that stores such values and hands them to applications at run time.

In agent contexts, a key is often what lets an AI agent call a tool on your behalf, and [OAuth for assistants](https://similariq.ai/features/oauth-for-assistants) is the alternative when a person is present to approve access. Key rotation is the routine replacement of a key, and least privilege is the principle of granting each key only the access its job requires.

## Frequently asked questions

### What is an API key used for?

It identifies and authenticates the program calling an API. The service uses it to accept or reject the request, attribute usage to the right account, apply limits and bill correctly. It lets software authenticate without a person signing in.

### Is an API key the same as a password?

It plays a similar role and deserves the same care, but it is meant for programs. A key is generated by the service, sent with every request and can usually be revoked or replaced independently of your login. Anyone who obtains it can act as your account.

### Where should I store an API key?

In an environment variable or a dedicated secrets manager that your application reads at run time. Do not put it in source code, a public repository, client-side code, a URL or a chat message. Limit who can view the stored value.

### What should I do if my API key is leaked?

Revoke it straight away and create a new one, then update the applications that used it. After that, review recent usage for activity you do not recognise and find out how the leak happened so it does not recur.

### What is the difference between an API key and an OAuth token?

An API key is a long-lived static secret tied to an account. An OAuth token is issued after a user approves a specific application, is usually short-lived and can be revoked per application. Keys suit your own servers; OAuth suits third-party tools acting for a user.

### Does one SimilarIQ API key work everywhere?

Yes. A single `sk-live-` key works with the REST API, the Node and Python SDKs, the CLI and the MCP server. All of them draw on the same pay-as-you-go balance at the same price per search.
