API Keys

Introduction

API keys are one of the simplest and most common ways for an API provider to identify the application that is calling an API. Many APIs are not meant to be used anonymously. A provider may need to know which application is sending requests, how much traffic that application is creating, which plan the application belongs to, whether the application is allowed to use a specific endpoint, and whether the usage is within the allowed limit. An API key gives the provider a practical way to associate incoming requests with a registered client application.

An API key is usually a long, unique string generated by the API provider and assigned to a client application, developer account, merchant account, or internal service. When the client calls the API, it sends the key with the request. The server checks the key before processing the request. If the key is valid and active, the server may allow the request to continue. If the key is missing, invalid, revoked, expired, or not allowed for the requested operation, the server rejects the request with an authentication or access error.

API keys are widely used in public APIs, third-party integrations, internal APIs, cloud services, developer platforms, mapping services, weather APIs, payment gateways, communication platforms, analytics services, and many other systems. They are popular because they are easy to generate, easy to send, easy to validate, and useful for usage tracking. However, API keys are not a complete security solution for every scenario. In most cases, an API key identifies the calling application, not the individual end user. Sensitive operations often require stronger mechanisms such as OAuth 2.0, OpenID Connect, JWTs, client certificates, or additional authorization checks.

For API testers, API keys are important because many API test suites cannot even start without a valid key. Testers must understand where the key is sent, how the API validates it, what errors should be returned when the key is wrong, how rate limits are enforced, how revoked keys behave, and whether keys are protected in logs, URLs, repositories, and reports. Testing API keys is not only a happy-path setup step. It is part of authentication, security, access control, monitoring, and reliability testing.

What Is an API Key?

An API key is a unique identifier issued by an API provider to a client application. The client includes the key in each API request so the server can recognize the caller. In simple terms, an API key says, "This request is coming from this registered application." The server can then use that identity to allow or deny access, apply rate limits, count usage, enforce quotas, enable billing, monitor traffic, or troubleshoot integration problems.

An API key is often just a string. It may look random, such as `123456789abcdef`, or it may have a provider-specific format. Some keys are short enough to copy manually. Others are long tokens generated by cloud or developer portals. The visible format is less important than the function: the key is a credential and should be protected like any other secret. Anyone who obtains a valid key may be able to call the API as the associated application, subject to the provider's restrictions.

API keys are sometimes described as authentication credentials. This is true in the sense that they authenticate or identify the calling application. But they usually do not authenticate a human user. If a weather application sends an API key, the provider knows which application is making the request, not necessarily which end user is looking at the weather. If a payment system uses an API key, the key may identify the merchant application, while separate user authentication and authorization mechanisms decide which merchant user can perform which action.

This distinction matters. An API key can be good for application-level identification, usage tracking, and simple access control. It is not enough by itself for all user-level permission decisions. If an API allows every request with a valid key to access all user data, the design is weak. Good API security combines key validation with endpoint permissions, resource ownership rules, scopes, roles, or stronger identity systems when needed.

Why API Keys Are Used

API keys are used because API providers need a simple way to control access. Without a key, a public endpoint may receive anonymous traffic from anyone. That makes abuse harder to detect, rate limits harder to apply, and usage harder to attribute. With API keys, each application or developer account can be tracked separately. If one key sends too many requests, the provider can throttle that key without blocking every user of the API. If a key is compromised, it can be revoked or rotated.

API keys also support analytics. Providers can measure which applications call which endpoints, how often they call them, what error rates they produce, which regions or environments create traffic, and which features are most used. This helps with capacity planning, billing, product decisions, and support. A developer platform can show each customer their usage because requests are associated with a key.

Another reason is rate limiting. Many APIs allow a fixed number of requests per minute, hour, day, or billing period. The API key becomes the unit for enforcing that limit. A free plan may allow 1,000 requests per day, while a paid plan may allow more. Internal APIs may use keys to prevent one service from overwhelming another. Rate limiting protects system stability and prevents unfair usage.

API keys also make onboarding easy. A developer registers an application, receives a key, and can start calling the API. This is much simpler than implementing a full OAuth flow for basic public data. For APIs that expose low-risk data or application-level services, a key may be a practical first layer. For sensitive APIs, the key can still be used alongside stronger security mechanisms.

How API Keys Work

The typical API key flow begins when a developer or client application registers with the API provider. The provider creates a unique key and associates it with the application. The key may also have metadata such as owner, environment, allowed domains, allowed IP addresses, product plan, quota, scopes, enabled endpoints, creation date, expiration date, and status. The developer stores the key and includes it in API requests.

When the server receives a request, it extracts the key from the expected location. Some APIs expect the key in a request header. Some expect it in a query parameter. Some allow it in the request body. The server then looks up the key in its key store or validates it through an API gateway. If the key exists, is active, belongs to the correct environment, and is allowed for the requested API, the request can continue. If not, the request is rejected.

After validation, the server may apply additional checks. It may verify whether the key has exceeded its rate limit, whether the calling IP address is allowed, whether the referrer domain is allowed, whether the endpoint is included in the key's plan, and whether the key is restricted to read-only usage. If these checks pass, the API processes the request. If any check fails, the API may return `401 Unauthorized`, `403 Forbidden`, or `429 Too Many Requests` depending on the reason.

In many production systems, API key validation happens at an API gateway before the request reaches the backend service. The gateway can reject invalid keys, enforce quotas, apply throttling, collect analytics, and route traffic. This reduces duplicated security logic in individual services. Testers should understand where validation happens because gateway behavior may differ from backend behavior.

API Key Generation

API key generation should produce values that are unique, unpredictable, and difficult to guess. A key should not be a simple sequence, a username, a company name, or a readable identifier. It should be generated using a secure random process. The provider may show the key only once and ask the developer to store it safely. Some platforms store only a hashed version of the key so the raw key cannot be recovered if the database is exposed.

A basic onboarding flow usually looks like this: the developer creates an account, registers an application, selects an API product or plan, receives an API key, configures allowed domains or IP addresses if required, stores the key securely, and sends the key with API requests. If the key is compromised, the developer can revoke it and generate a replacement. Good platforms support multiple keys per application so migration can happen without downtime.

From a testing perspective, key generation is relevant when the product includes a developer portal or admin interface. Testers may need to verify that new keys are unique, key names are saved, key status changes work, disabled keys fail immediately, rotated keys behave correctly, deleted keys cannot be reused, and users cannot view or manage keys belonging to other accounts. If key management is part of the product, it deserves its own test coverage.

Where API Keys Are Sent

API keys are commonly sent in three places: request headers, query parameters, and request bodies. Headers are usually preferred because they keep credentials separate from URL paths and query strings. A request header may look like this:

GET /employees
x-api-key: 123456789abcdef

Some APIs use a custom header called `x-api-key`, while others use `api-key`, `X-API-Key`, `Authorization`, or a provider-specific name. Header names are generally case-insensitive in HTTP, but API documentation should define the expected convention. Testers should follow the contract and also validate how the API behaves when the key is missing or sent in the wrong header.

Some APIs accept keys in query parameters:

GET /employees?apiKey=123456789abcdef

This is easy for beginners because the key is visible in the URL, but it has security drawbacks. URLs may be logged by browsers, proxies, load balancers, web servers, monitoring tools, analytics systems, or referrer headers. If a key appears in logs or browser history, it is easier to leak. For that reason, many providers recommend request headers instead of query parameters for sensitive keys.

A less common approach is sending the key in the request body:

{
  "apiKey": "123456789abcdef"
}

This may be used in specific designs, but it is not the most common pattern. It also does not work naturally for GET requests because GET requests usually do not have a body. Testers should not invent the location. They should use the provider's documentation and then test incorrect locations as negative scenarios if the behavior is defined.

Successful and Failed API Key Requests

A successful request with a valid key may return `200 OK`, `201 Created`, `204 No Content`, or another success status depending on the operation. For example:

GET /employees
x-api-key: validKey123

HTTP/1.1 200 OK

If the key is invalid, the API should reject the request. Many APIs return `401 Unauthorized` because the caller failed authentication. Some APIs return `403 Forbidden` when the key is recognized but not allowed for that endpoint or plan. The exact behavior should be documented. For example:

GET /employees
x-api-key: invalidKey

HTTP/1.1 401 Unauthorized

If the key is missing, the API should also reject the request:

GET /employees

HTTP/1.1 401 Unauthorized

If the key is valid but has exceeded the allowed request quota, the API should usually return `429 Too Many Requests`:

GET /employees
x-api-key: validKey123

HTTP/1.1 429 Too Many Requests

Good API error responses should be consistent and useful. They should tell the caller that authentication failed, the key is missing, the key is invalid, access is denied, or rate limit has been exceeded. At the same time, they should not expose sensitive information, such as whether a specific key exists in the database, the full key value, internal lookup details, or security configuration.

API Key vs Password

An API key and a password are both credentials, but they are used differently. A password usually identifies and authenticates a human user. A user chooses or manages the password, and the system validates it during login. Password-based authentication often includes additional protections such as multi-factor authentication, lockout rules, password reset flows, and password strength policies.

An API key usually identifies an application, integration, developer account, or service. It is generated by the API provider and used by software when sending API requests. A key is often longer and more random than a user password. It may be used continuously by an application rather than manually entered by a human. It should be stored in environment variables, secret managers, server configuration, or secure deployment settings rather than typed into a login form.

PointAPI KeyPassword
Primary identityApplication or clientHuman user
CreationGenerated by providerChosen or reset by user
UsageSent with API requestsUsed for login
StorageSecrets manager or environment configurationPassword hash on server and password manager for user
Security controlsRotation, revocation, restrictions, rate limitsMFA, lockout, reset, strength rules

Testers should treat API keys as secrets. They should not paste real production keys into screenshots, bug reports, public documentation, Git repositories, or shared chat logs. If a real key is accidentally exposed, it should be rotated or revoked.

API Key vs Bearer Token

API keys and bearer tokens are also different. An API key is often long-lived and identifies an application. A bearer token often represents an authenticated user or client session and may be short-lived. Bearer tokens are commonly used with OAuth 2.0 and OpenID Connect. They may include scopes, user claims, issuer, audience, expiry, and other information. A bearer token can support richer authorization decisions than a simple API key.

An API key may be enough for simple public data APIs, such as weather lookup, map usage, or low-risk service access. A bearer token is usually better for user-specific data or sensitive operations because it can represent who the user is and what permissions they have. Some systems use both. For example, an API key may identify the application, while an OAuth token identifies the user. The API can then apply both application-level and user-level controls.

PointAPI KeyBearer Token
Common purposeIdentifies the applicationRepresents authenticated access
LifespanOften long-livedOften short-lived
Authorization detailUsually limitedCan include scopes and claims
Typical usePublic APIs and developer platformsOAuth, OIDC, user/session access
Risk if leakedAbuse of application access or quotaAccess as represented user or client until expiry/revocation

During testing, do not assume API keys and bearer tokens are interchangeable. If documentation requires `x-api-key`, send that header. If documentation requires `Authorization: Bearer`, use a bearer token. If both are required, test missing and invalid cases for each credential separately.

Advantages of API Keys

API keys are easy to implement. A provider can generate a key, store it, and check incoming requests against it. A client can copy the key into configuration and start making requests. This simplicity makes API keys useful for developer platforms, quick integrations, internal service access, and APIs where application-level identification is enough.

API keys are lightweight. They do not require a browser redirect, login consent page, authorization code exchange, token refresh flow, or identity provider integration. For low-risk APIs, this keeps onboarding fast. A developer can obtain a key and call the API from a backend service, command-line tool, or test client.

API keys are also useful for usage tracking and rate limiting. The provider can measure traffic per key, apply quotas per plan, detect unusual spikes, and disable abusive keys. This makes API keys valuable even when they are not the only security mechanism. They are often part of API management platforms and gateways because they give the provider a stable way to identify consuming applications.

Limitations of API Keys

The biggest limitation of an API key is that it usually identifies the application, not the user. If many users share the same application key, the server cannot use the key alone to know which user is making a request. This is fine for some APIs but risky for user-specific or sensitive data. A key may tell the API that the request came from a registered application, but it does not automatically prove that the end user is authorized to access a specific resource.

API keys can also be compromised. If a key is hardcoded in client-side JavaScript, mobile application code, public repositories, logs, screenshots, or error messages, attackers may copy it. Once copied, the attacker may be able to consume quota, access data, or abuse the API. For this reason, production keys should be stored securely and rotated when exposed.

Another limitation is long lifespan. Many API keys remain valid until manually revoked. That can be convenient, but it increases risk if a key is leaked and nobody notices. Providers can reduce this risk by supporting expiration, rotation, restrictions, monitoring, and alerts. Testers should verify these controls when they are part of the product.

Security Best Practices

Always use HTTPS when sending API keys. Without HTTPS, keys can be intercepted in transit. Avoid sending keys in query parameters when a header-based approach is available because URLs are commonly logged and stored. Store keys in environment variables, secure configuration, CI/CD secrets, cloud secret managers, or vault systems. Never hardcode production keys in source code.

Use different keys for development, testing, staging, and production. This prevents test traffic from affecting production usage and limits damage if a non-production key is exposed. Restrict keys by IP address, domain, referrer, application, environment, scope, or endpoint when the provider supports it. A key used only by a backend service should not be valid from any random public IP if tighter restrictions are possible.

Rotate keys regularly and revoke compromised keys immediately. Good rotation allows two keys to exist during migration so the application can switch from old to new without downtime. Logs should mask or redact full key values. Monitoring should detect unusual traffic, repeated authentication failures, sudden quota spikes, requests from unexpected locations, and access to unusual endpoints.

API Keys in API Testing

API key testing should cover both functional access and security behavior. A valid key should allow permitted requests. An invalid key should fail. A missing key should fail. A revoked key should fail. An expired key should fail if the API supports expiration. A key for one environment should not work in another environment if environments are separated. A read-only key should not perform write operations if key-level permissions exist.

Testers should also verify rate limits. A key may be allowed only a certain number of requests per minute or day. Tests should confirm that requests within the limit succeed and requests beyond the limit return the documented `429 Too Many Requests` response. The response may include headers such as remaining limit, reset time, or retry-after information. These headers help clients behave correctly after throttling.

Error responses should be checked carefully. A missing key and invalid key may both return `401`, but the response body should be consistent with documentation. The response should not reveal full internal validation details. It should not echo the full key. It should not expose whether a specific secret exists. It should be helpful enough for legitimate clients to debug integration issues without giving attackers unnecessary information.

Example Test Cases

ScenarioExpected ResultTesting Purpose
Valid API key in expected header200 OK or expected success statusConfirms valid application access
Missing API key401 Unauthorized or documented auth errorConfirms protected endpoint rejects anonymous calls
Invalid API key401 Unauthorized or 403 ForbiddenConfirms unknown keys are rejected
Revoked API key401 Unauthorized or documented revoked-key errorConfirms disabled keys cannot be used
Expired API key401 Unauthorized or documented expiry errorConfirms expiration enforcement
Valid key exceeds quota429 Too Many RequestsConfirms rate limiting
Key sent in wrong locationAuthentication failureConfirms contract enforcement
Test key used against production endpointRejected if environment isolation is requiredConfirms environment separation

These tests should be automated where practical, but testers must avoid putting real keys into committed test code. Use environment variables or secret management in the test pipeline. Mask keys in reports. If test output includes request headers, ensure secrets are redacted before reports are shared.

REST Assured Example

In REST Assured, sending an API key in a header is straightforward:

given()
  .header("x-api-key", "123456789abcdef")
.when()
  .get("/employees")
.then()
  .statusCode(200);

A missing-key scenario can be written by omitting the header:

given()
.when()
  .get("/employees")
.then()
  .statusCode(401);

An invalid-key scenario can use a known invalid value:

given()
  .header("x-api-key", "invalid-key")
.when()
  .get("/employees")
.then()
  .statusCode(401);

In a real framework, the valid key should not be hardcoded. It should come from an environment variable, configuration file that is not committed, CI/CD secret, or secure runtime setting. The framework can provide a helper method for adding the key, but tests should still make the scenario intent clear. A test named "missing API key returns 401" should not accidentally add the default key through a shared setup method.

Postman Example

In Postman, a tester can add an API key manually as a request header. The key might be `x-api-key`, and the value might be stored in an environment variable such as `{{api_key}}`. Postman also provides an API Key authorization type where the tester can configure the key name, value, and location. Depending on the API, Postman can place the key in the header or query parameter automatically.

Postman environments are useful for separating development, testing, staging, and production keys. A tester can create variables for base URL and API key, then switch environments without editing every request. However, environment exports should be handled carefully because exported files may include secrets. Teams should avoid sharing real production keys through exported collections or public workspaces.

Postman tests can assert expected status codes and error responses. For example, a missing-key request should return the documented authentication error. A rate-limit test may verify `429` and check `Retry-After` if the API returns that header. These checks help document API security behavior and catch regressions when gateway policies change.

Karate Example

Karate can send an API key using a header step:

Given header x-api-key = '123456789abcdef'
When method GET
Then status 200

For maintainability, the key should usually come from configuration:

Given header x-api-key = apiKey
When method GET
Then status 200

Karate is useful for API key testing because it can express positive and negative scenarios clearly. A scenario for invalid key can set `x-api-key` to a bad value and assert `401`. A scenario for missing key can avoid setting the header. A scenario for restricted key can use a key with limited access and assert `403` for disallowed operations. The readable style helps keep authentication behavior visible in the test suite.

Real-World Examples

Mapping APIs commonly use API keys to identify which application is loading maps, geocoding addresses, or calculating routes. The provider can track usage and bill the developer account. Keys may be restricted by domain so they work only from approved websites. Testers should verify that allowed domains work and disallowed domains fail when domain restrictions are part of the design.

Weather APIs often use API keys because the data may be public or semi-public, but the provider still needs to control usage. A free key may allow a limited number of requests per day. A paid key may allow more requests or additional endpoints. Testers should validate plan-based restrictions, rate limits, invalid keys, and correct error messages.

Payment gateways may use API keys to identify the merchant application. However, payment operations are sensitive, so the key may be combined with signatures, OAuth, secret keys, idempotency keys, webhooks, environment separation, or dashboard permissions. Testers must avoid treating the API key as the only security layer. They should validate both merchant identity and operation-level authorization.

Internal company APIs may issue keys to backend services so each service can be monitored separately. This helps platform teams identify traffic sources and apply service-level limits. If an internal key is compromised or misused, it can be revoked without disabling every internal caller. Testers should verify that internal APIs still reject missing or invalid keys, even if the network is private.

Rate Limiting and Quotas

Rate limiting is one of the most practical uses of API keys. Because each request carries a key, the provider can count requests per application. If the key exceeds the configured threshold, the API returns a throttling response. This protects the platform from abuse, accidental loops, misconfigured clients, and unfair consumption. It also supports business plans where higher tiers receive higher quotas.

A good rate-limit response should be predictable. It may include `429 Too Many Requests`, a message explaining that the limit was exceeded, and headers such as `Retry-After`, `X-RateLimit-Limit`, `X-RateLimit-Remaining`, or `X-RateLimit-Reset`. Testers should validate the documented behavior. If the API returns random failures, vague errors, or inconsistent throttling, client applications will be harder to build and troubleshoot.

Testing rate limits must be done carefully because aggressive tests can affect shared environments. Coordinate with the team before generating high request volumes. Use dedicated test keys and test environments when possible. If real rate limits are too high to test directly, the team may provide lower limits for test keys or expose a controlled test endpoint. The goal is to verify behavior without disrupting other users.

Key Rotation and Revocation

Key rotation means replacing an old API key with a new one. Rotation reduces long-term risk because a key that has existed for years may have been copied into many places. A good system allows the application to create a new key, deploy it, confirm it works, and then revoke the old key. This prevents downtime during migration.

Revocation means disabling a key so it can no longer access the API. Revocation is necessary when a key is leaked, an application is retired, a developer leaves, a customer cancels, or suspicious activity is detected. Revocation should take effect quickly. If a revoked key continues to work for a long time due to caching or gateway propagation delays, the risk should be documented and controlled.

Testers should verify key status changes. An active key should work. A revoked key should fail. A rotated key should allow the new key and reject the old key after revocation. Deleted keys should not reappear. Users should not be able to revoke keys owned by other accounts unless they have administrative permission. Key management audit logs should show who created, rotated, disabled, or deleted keys if auditing is part of the product.

Common Mistakes

Hardcoding API keys is a common mistake. Developers may place keys directly in source code, test files, mobile apps, frontend JavaScript, or configuration files that are committed to Git. Once a real key is committed to a repository, it should be considered exposed. Even private repositories can be copied, logged, or shared. Production keys should be moved to secure secret storage.

Sending API keys over HTTP is another serious mistake. If HTTPS is not used, the key can be intercepted in transit. Testers should verify that production APIs require HTTPS and that HTTP requests are rejected or redirected safely according to the design. Sensitive credentials should never be transmitted over plaintext connections.

Logging full API keys is also dangerous. Request logs, error logs, access logs, gateway logs, and monitoring tools may capture headers or URLs. If full keys appear in logs, anyone with log access can misuse them. Logs should mask keys by showing only a small prefix or suffix, such as `abcd****7890`. Testers should inspect logs and reports where possible to confirm secrets are not exposed.

Another mistake is assuming API keys alone provide complete security. API keys are useful, but sensitive systems need stronger controls. User-specific data requires user authentication and authorization. High-risk operations may require scopes, signatures, short-lived tokens, multi-factor authentication, or additional policy checks. API keys are a building block, not a universal security solution.

Best Practices

Use API keys for application identification, access control, rate limiting, analytics, and simple API onboarding. Use HTTPS for every request. Prefer headers over query parameters when possible. Store keys in secure configuration, not in source code. Use separate keys for each environment and application. Restrict keys by domain, IP address, scope, endpoint, or plan when supported. Rotate keys regularly and revoke compromised keys immediately.

Design clear error handling. Missing keys, invalid keys, revoked keys, expired keys, restricted keys, and rate-limited keys should return documented responses. Clients should understand whether they need to provide a key, correct a key, wait before retrying, upgrade a plan, or request permission. At the same time, errors should avoid exposing sensitive internal details.

For testing, keep valid keys out of committed code and shared reports. Use environment variables, CI/CD secrets, or secured configuration. Mask keys in logs. Create dedicated test keys for automation. Include negative tests for missing, invalid, revoked, expired, restricted, and rate-limited keys. Review API key behavior whenever gateway configuration, authentication middleware, billing plans, or endpoint permissions change.

Interview Questions

A common interview question is: what is an API key? A strong answer is that an API key is a unique identifier issued by an API provider to a client application. The client sends the key with API requests so the server can identify the application, control access, track usage, and enforce rate limits.

Another question is: where can an API key be sent? API keys are commonly sent in request headers, query parameters, or sometimes the request body. Headers are generally preferred because query parameters can appear in logs, browser history, and referrer information. The exact location depends on the API contract.

Interviewers may ask whether an API key is authentication or authorization. A practical answer is that an API key is primarily an authentication or identification mechanism for the calling application. Authorization decisions may still require roles, permissions, scopes, ownership rules, or user tokens. A key can identify the client, but it does not always prove what an individual user is allowed to do.

Another common question is why API keys must be protected. Anyone who obtains a valid key may be able to make requests as the associated application. That can lead to quota abuse, billing issues, data exposure, or unauthorized access depending on the API. API keys should be protected with HTTPS, secure storage, rotation, revocation, restrictions, monitoring, and masking in logs.

For testing questions, explain that testers should validate valid keys, invalid keys, missing keys, revoked keys, expired keys, wrong key location, rate limits, secure transmission, access restrictions, correct status codes, and safe error messages. Mention that production keys should never be hardcoded in automation or exposed in reports.

Interview-Ready Explanation

An API key is a unique identifier generated by an API provider and assigned to a client application. The client includes the key in API requests, usually in a request header, query parameter, or occasionally the request body. The server validates the key before processing the request so it can identify the calling application, control access, monitor usage, enforce quotas, and apply rate limits.

API keys are simple and widely used in public APIs, third-party integrations, cloud services, internal APIs, developer platforms, mapping APIs, weather APIs, payment systems, and service integrations. They are easy to implement and useful for application-level identification. However, an API key usually identifies the application rather than the individual user, so sensitive APIs often combine API keys with OAuth 2.0, JWTs, bearer tokens, signatures, roles, scopes, or other authorization mechanisms.

During API testing, testers should verify that valid keys are accepted and invalid, missing, revoked, or expired keys are rejected with documented responses. They should also test rate limiting, access restrictions, environment separation, HTTPS enforcement, key rotation, key revocation, and safe logging. API keys must be treated as secrets because anyone who obtains a valid key may be able to make requests as the associated application.

Key Takeaway

API keys are simple credentials used to identify and control client applications that call APIs. They help providers manage access, track usage, enforce quotas, apply rate limits, and troubleshoot integrations. They are common because they are lightweight and easy to use, but they are not always enough for user-level security or sensitive operations.

For API testers, the practical rule is to test the key as a security control, not only as a setup value. Verify valid, invalid, missing, revoked, expired, restricted, and rate-limited keys. Check whether keys are sent in the correct place, protected by HTTPS, excluded from logs, and stored securely. A well-tested API key implementation improves security, reliability, observability, and developer experience.