Skip to main content
Version: Dev

Caller API Keys

A caller API key identifies an application that sends requests through the AISIX gateway. Use the key to control which models the application can call and which traffic policies apply. The application sends the plaintext key, and AISIX stores its SHA-256 hash.

Caller keys authenticate application traffic; they do not grant operator access. In AISIX Enterprise and AISIX Cloud, operators manage caller keys through the dashboard or AISIX Cloud Admin API. In AISIX OSS, operators configure them through a resources file or etcd. The resources-file examples below load the credential from an environment variable or a precomputed hash.

For applications with short-lived credentials from an identity provider, see JWT Authentication. AISIX maps a verified JWT to a caller key and applies its model access and traffic controls. In AISIX Enterprise and AISIX Cloud, matching budgets apply as well.

Prerequisites​

Before starting, prepare the following:

  • A model alias the caller should be allowed to use. If you have not created one yet, configure Provider Keys and Model Aliases first.
  • To verify access, a running gateway connected to the environment or using the resources file. The examples call the chat model alias gpt-4o-prod.
  • For the request examples, install curl.
  • For AISIX Enterprise or AISIX Cloud, prepare an account with permission to manage API keys in the target environment. For AISIX Enterprise, follow the AISIX Enterprise getting-started guide; to request AISIX Cloud access, contact API7.
  • If you use the Dashboard to configure AISIX Enterprise or AISIX Cloud, sign in and confirm that you can enter the target environment.
  • If you use the Admin API to configure AISIX Enterprise or AISIX Cloud, prepare a write-scoped admin token, the target environment ID, and jq.
  • For AISIX OSS, prepare a complete resources file that contains the model alias and that you can validate and reload. See Reload a Resources File.

If you use the Admin API to configure AISIX Enterprise or AISIX Cloud, export the reusable connection values:

# AISIX_CP is the Admin API base URL; include /api and omit a trailing slash.
# The local AISIX Enterprise quickstart uses http://localhost:8080/api.
export AISIX_CP="YOUR_AISIX_CONTROL_PLANE_API_URL"
export AISIX_TOKEN="YOUR_ADMIN_TOKEN"
export ENV_ID="YOUR_ENVIRONMENT_ID"

Create a Caller API Key​

Create a caller key named chat-app, grant it access to gpt-4o-prod, and save the plaintext credential for verification.

Set the key's model access when you create it in the environment that serves those models.

  1. In Environments, select Enter for the environment that contains the model. Open API keys, then select New API key.

  2. Enter a Display name, such as chat-app.

  3. Keep Selected models, open Select models… under Allowed models, and select the alias this caller should use. This example grants access to gpt-4o-prod.

    New API key form with gpt-4o-prod selected in Selected models mode
  4. Select Create API key. In One-time view, select Copy and store the plaintext credential securely.

  5. Select I've saved it to dismiss the one-time view. In API keys, expand the new key and check that it is Active and lists the intended alias.

Saved chat-app key expanded in the API keys list with gpt-4o-prod allowed

Verify Access​

Export the gateway origin:

# AISIX_PROXY is the gateway origin; omit a trailing slash and endpoint path.
# The local quickstarts use http://127.0.0.1:3000.
export AISIX_PROXY="YOUR_AISIX_GATEWAY_URL"

Set the caller credential for the workflow you used:

Export the plaintext value copied from the one-time view:

export AISIX_API_KEY="YOUR_CALLER_API_KEY"

The caller sends the model alias name and the plaintext key:

curl -sS -X POST "$AISIX_PROXY/v1/chat/completions" \
-H "Authorization: Bearer ${AISIX_API_KEY}" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o-prod",
"messages": [
{"role": "user", "content": "Hello from AISIX."}
]
}'

A successful request reaches the upstream model and returns a chat-completions response. If the proxy returns 401 or 403, check that the application is using the plaintext key and an allowed model alias.

List the models visible to the caller and confirm that the configured alias appears:

curl -sS "$AISIX_PROXY/v1/models" \
-H "Authorization: Bearer ${AISIX_API_KEY}"

Control Model Access​

The model allowlist is the authorization boundary for a caller API key. Choose the narrowest value that matches how the key will be used.

Access patternConfigurationUse when
Specific modelsKeep Selected models and choose aliases in the picker.The application should call only approved model aliases.
No model accessKeep Selected models and leave the picker empty.You want to create the key before granting model access.
All modelsSelect All models (including ones added later).The application should reach every model in the environment, including models added later.

The model list endpoint uses the same allowlist. It returns every concrete direct or virtual alias available to the caller API key, including routing, semantic, and ensemble aliases. Wildcard aliases are not returned because they are patterns rather than concrete model names.

Grant Every Model​

Enable all-model access when an application should be able to call every model available to the key, including models added later. This covers direct and embedding models, routing groups, semantic routers, ensembles, and wildcard entries.

All-model access also makes the members of a routing group, semantic router, or ensemble directly callable. Granting access only to a group allows calls to the group, not direct calls to its members.

The grant covers models only. Configure A2A agent access, passthrough route access, and MCP tool access separately through allowed_agents, allowed_routes, and mcp_access.

  1. Open API keys in the environment. Select New API key, or select Edit on an existing key.

  2. Under Allowed models, select All models (including ones added later). Selected models is the default and grants only the aliases in the picker; leaving its picker empty grants no model access.

    All models access selected with the model picker disabled
  3. Create or save the key. Confirm that the key list or expanded details show an All models badge.

All-model access requires gateway 1.11.0 or later. When an older gateway is registered in the environment, saving the key returns a compatibility warning that identifies the ignored field. Upgrade those gateways before relying on the key there. See Mixed-Version Behavior.

Import Existing Keys from Another Gateway​

When moving from another AI gateway, import existing caller API keys so applications can keep using the same credentials after moving to AISIX. AISIX authenticates a request by hashing the incoming bearer token, so existing key values do not need an AISIX-specific prefix, length, or character set.

Custom key values are enabled by default.

If Import an existing key (optional) is unavailable, ask an organization owner or admin to open Settings, select Policies, and enable Allow custom API key values under API key import. Clear that option to disable imports across the organization.

  1. Open the target environment, select API keys, then select New API key.
  2. Enter a Display name, such as imported-caller, and select the models the application may call.
  3. Expand Import an existing key (optional) and enter the existing credential in Custom key value.
Expanded Import an existing key section with the Custom key value field
  1. Select Create API key. Check that One-time view shows the imported credential, then select I've saved it.
  2. Verify access with the existing credential before directing application traffic to AISIX.

Manage a Caller API Key​

Update the key's lifecycle without changing how applications identify it, unless you deliberately rotate the credential.

Set an Expiration​

Caller API keys have no expiration by default. Set a deadline to stop a key from authenticating after a specified time. In API requests and resources files, the deadline is an RFC 3339 timestamp in expires_at.

After the deadline passes, the proxy rejects the key with 401 and the error code api_key_expired. AISIX evaluates expiration on every request, so the key becomes invalid after the deadline passes without a restart or configuration change.

Set a deadline when creating the key, or update the existing key without changing its credential.

For a new key, set Expiration (optional) in New API key before creating it. Copy and store the credential from the one-time view.

Expiration field in the New API key form with a June 30, 2027 deadline

To change an existing key:

  1. Open the environment and select API keys.
  2. Select Edit on the key row.
  3. Set Expiration, or clear it to remove the deadline.
  4. Select Save changes. Confirm that the row shows the intended deadline, or no deadline if you cleared it.

The key reports Expired after its deadline passes.

Disable and Re-enable a Caller API Key​

Disabling pauses a key without deleting it. The proxy rejects a disabled key with 401 and the error code api_key_disabled. The key value is preserved, so re-enabling restores the exact credential the application already holds.

Disable a key to suspend application access temporarily. Rotate it if the credential may have been exposed, or delete it when the application no longer needs access.

Change the key's enabled state through the dashboard or an API update.

  1. Open the environment and select API keys.
  2. Select Disable on the key row and confirm the action.
Confirmation dialog explaining that disabling the caller key blocks authentication
  1. Confirm that the key reports Disabled.

To restore access, select Enable on the same row. AISIX keeps the existing credential and does not display a new plaintext value. An expired key still needs a future deadline or no deadline before it can authenticate.

Rotate a Caller API Key​

Use key rotation when an existing caller API key needs a new plaintext value.

Rotation replaces only the credential. The key resource is preserved: its name, model access, limits, bindings, tags, expiration, and disabled state carry over. Store the new plaintext securely and update the application; the old plaintext stops authenticating when the rotated resource reaches the gateway.

  1. Open the environment and select API keys.
  2. Select Rotate on the key row. Review the confirmation before proceeding: the old credential will stop working after the gateway receives the update.
Rotation confirmation warning that applications must switch to the new caller credential
  1. Confirm the rotation. In One-time view, copy and securely store the new credential, then select I've saved it.
  2. Update the application with the new credential and verify access.

The key retains its Active, Expired, or Disabled status. Lifecycle changes are recorded in the organization audit log.

Attribute Caller Traffic​

Attach team, member, and tag context to the key so AISIX can attribute usage and apply matching controls.

Attribute Calls to Teams and Members​

Caller-key bindings attribute requests to a team, a member, or both. They also determine which team and member controls apply.

To bind a key to a team and member:

  1. Open API keys in the environment.
  2. Create a key or select Edit on an existing key.
  3. Choose its Team and Owner, then save.

A team binding does not substitute for the member binding used by member attribution and controls.

Tag a Caller API Key​

Caller-key tags attribute the key's traffic for cost analysis and policy matching. A value read from a JWT claim takes precedence over the key's value. The key's value otherwise takes precedence over the same tag on its team or member.

Declare each cost attribution tag before assigning it to a caller key. In AISIX Enterprise and AISIX Cloud, tags can also select matching budgets.

To add a cost-attribution tag:

  1. Open API keys in the environment.
  2. Create a key or select Edit on an existing key.
  3. Under Cost-attribution tags, add the declared key and its value.
  4. Save the caller key.
Cost-attribution tags field with a Department value

See How a Request Resolves Its Tags for the complete precedence rules.

Next Steps​

You have now configured how a caller authenticates and which model aliases it can use. Continue with Routing and Failover when one model alias should select from multiple upstream targets.