# 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](https://docs.api7.ai/ai-gateway/traffic-controls/jwt-authentication.md). 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[​](#prerequisites "Direct link to 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](https://docs.api7.ai/ai-gateway/models/provider-keys.md) and [Model Aliases](https://docs.api7.ai/ai-gateway/models/model-aliases.md) 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](https://docs.api7.ai/ai-gateway/getting-started/aisix-cloud-quickstart.md); to request AISIX Cloud access, [contact API7](https://api7.ai/contact).
* 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](https://docs.api7.ai/ai-gateway/deployment/configuration-propagation.md#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-api-key "Direct link to 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.

* AISIX Enterprise or Cloud
* AISIX OSS

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

* Dashboard
* Admin API

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](https://static.api7.ai/uploads/2026/11/18/4RoHbjuT_caller-form.webp)

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](https://static.api7.ai/uploads/2026/11/18/Egp5auRD_caller-saved.webp)

Export the ID of the model the caller may use:

```
export MODEL_ID="YOUR_MODEL_ID"
```

`MODEL_ID` is the `id` returned when you created the model alias, not the alias name.

Create the API key resource with the allowed model. The AISIX Cloud Admin API generates the plaintext key and returns it once in the create response:

```
RESPONSE=$(curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "chat-app",

    "allowed_models": ["'"$MODEL_ID"'"]

  }')



export API_KEY_ID=$(echo "$RESPONSE" | jq -r '.api_key.id')

export AISIX_API_KEY=$(echo "$RESPONSE" | jq -r '.plaintext')

echo "$RESPONSE" | jq '.api_key'
```

The command saves the resource ID and plaintext credential in shell variables and prints only the key metadata. The full API response has this structure:

```
{

  "api_key": {

    "id": "f1ad9f8a-75d0-46ae-9d8d-0cfe8d1d8387",

    "env_id": "9be9891a-6a53-4bd8-a897-a03fe38a1ca5",

    "display_name": "chat-app",

    "allowed_models": [

      "6a3f2c1d-8f4e-49b2-b6f1-3f6f24d0f9a2"

    ],

    "allow_all_models": false,

    "disabled": false,

    "status": "active",

    "created_at": "2026-06-24T12:18:39Z",

    "updated_at": "2026-06-24T12:18:39Z"

  },

  "plaintext": "sk-***"

}
```

The highlighted fields serve different purposes:

* `id` identifies the resource for later updates, rotation, or deletion. The command exports it as `API_KEY_ID`.
* `plaintext` is the caller credential. The command exports it as `AISIX_API_KEY`. Store it securely and configure the application with it; AISIX returns it only once.

AISIX sends the key configuration to attached gateways automatically.

Choose a plaintext caller credential and make it available to the gateway process:

```
export CALLER_API_KEY="YOUR_CALLER_API_KEY"

export CALLER_API_KEY_SHA256="$(printf '%s' "$CALLER_API_KEY" | sha256sum | cut -d ' ' -f 1)"
```

Add an entry to the existing [`api_keys` collection](https://docs.api7.ai/ai-gateway/reference/resources-file.md#caller-api-keys). Preserve unrelated entries and collections, and keep a single `api_keys` key in the complete file. The entry carries the key's SHA-256 digest in `key_hash`, read from `CALLER_API_KEY_SHA256`, never the plaintext:

resources.yaml (caller API key)

```
api_keys:

  - id: a31b8275-cc81-4cdc-a618-875fd28c7532

    display_name: chat-app

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - gpt-4o-prod
```

The gateway matches `allowed_models` against model `display_name` values and compares `key_hash` with the digest of the key each request presents. Validate the complete resources file before applying it. If `CALLER_API_KEY_SHA256` was already available to the running gateway process, send `SIGHUP` to reload the file. If you introduced the variable now, restart or recreate the gateway with the variable so the process can resolve it.

### Verify Access[​](#verify-access "Direct link to 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:

* AISIX Enterprise or Cloud
* AISIX OSS

- Dashboard
- Admin API

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

```
export AISIX_API_KEY="YOUR_CALLER_API_KEY"
```

The creation example already exports the plaintext value as `AISIX_API_KEY`. If you are verifying another key, export the value held by its application:

```
export AISIX_API_KEY="YOUR_CALLER_API_KEY"
```

Reuse the plaintext value assigned to the variable in the resources file:

```
export AISIX_API_KEY="$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[​](#control-model-access "Direct link to 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.

* AISIX Enterprise or Cloud
* AISIX OSS

- Dashboard
- Admin API

| Access pattern  | Configuration                                              | Use when                                                                                   |
| --------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| Specific models | Keep **Selected models** and choose aliases in the picker. | The application should call only approved model aliases.                                   |
| No model access | Keep **Selected models** and leave the picker empty.       | You want to create the key before granting model access.                                   |
| All models      | Select **All models (including ones added later)**.        | The application should reach every model in the environment, including models added later. |

Managed caller keys reference models by resource ID in the same environment:

| Access pattern  | Configuration                                                          | Use when                                                                                   |
| --------------- | ---------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| Specific models | List model resource IDs, such as `["$MODEL_ID"]`.                      | The application should call only approved model aliases.                                   |
| No model access | Use an empty `allowed_models` list.                                    | You want to create the key before granting model access.                                   |
| All models      | Enable `allow_all_models` and leave `allowed_models` empty or omit it. | The application should reach every model in the environment, including models added later. |

AISIX OSS caller keys reference model aliases in the same resources file:

| Access pattern  | Configuration                                                                                | Use when                                                                                      |
| --------------- | -------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| Specific models | List model aliases, such as `gpt-4o-prod`. Single-asterisk glob patterns are also supported. | The application should call only approved model aliases.                                      |
| No model access | Use an empty `allowed_models` list.                                                          | You want to create the key before granting model access.                                      |
| All models      | Set `allow_all_models: true`.                                                                | The application should reach every model in the resources file, 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[​](#grant-every-model "Direct link to 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`.

* AISIX Enterprise or Cloud
* AISIX OSS

- Dashboard
- Admin API

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](https://static.api7.ai/uploads/2026/11/18/pce7u60Z_caller-all-models.webp)

3. Create or save the key. Confirm that the key list or expanded details show an **All models** badge.

Export the existing key's resource ID and the model ID needed to restore selected access:

```
export API_KEY_ID="YOUR_CALLER_API_KEY_ID"

export MODEL_ID="YOUR_MODEL_ID"
```

Send `allow_all_models` instead of a model list when you create the key:

```
curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "team-a",

    "allow_all_models": true

  }'
```

The response reports `"allow_all_models": true` with an empty `allowed_models`. While `allow_all_models` is `true`, `allowed_models` must be empty or omitted; a request that sends a non-empty list with it returns `400`.

To switch an existing key to all models, update only the access mode. AISIX clears its stored model allowlist:

```
curl -sS -X PATCH "$AISIX_CP/environments/$ENV_ID/api_keys/$API_KEY_ID" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{"allow_all_models":true}'
```

To return to selected models, send `false` together with the model IDs the caller should retain:

```
curl -sS -X PATCH "$AISIX_CP/environments/$ENV_ID/api_keys/$API_KEY_ID" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "allow_all_models": false,

    "allowed_models": ["'"$MODEL_ID"'"]

  }'
```

Switching to selected models without supplying an allowlist leaves the key with no model access. Omitting the mode field leaves it unchanged. A non-empty allowlist is rejected while all-model access remains enabled.

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](https://docs.api7.ai/ai-gateway/on-premises/upgrade.md#mixed-version-behavior).

Replace the existing `allowed_models` list with `allow_all_models: true`:

resources.yaml (all-models API key)

```
api_keys:

  - id: ead743a7-d74a-47a2-9729-473caa22c166

    display_name: team-a

    key_hash: ${CALLER_API_KEY_SHA256}

    allow_all_models: true
```

Preserve the key's non-model controls and every unrelated entry and collection, but remove `allowed_models`. Validate the assembled complete resources file before reloading it. `allow_all_models` requires gateway 1.11.0 or later. An older gateway rejects the field as unknown, so upgrade it before applying this resources file.

## Import Existing Keys from Another Gateway[​](#import-existing-keys-from-another-gateway "Direct link to 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.

* AISIX Enterprise or Cloud
* AISIX OSS

Custom key values are enabled by default.

* Dashboard
* Admin API

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](https://static.api7.ai/uploads/2026/11/18/kL2k4doL_caller-import.webp)

4. Select **Create API key**. Check that **One-time view** shows the imported credential, then select **I've saved it**.
5. [Verify access](#verify-access) with the existing credential before directing application traffic to AISIX.

Export the model resource ID used by the imported key:

```
export MODEL_ID="YOUR_MODEL_ID"
```

Send the existing credential in the create request:

```
curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "imported-caller",

    "allowed_models": ["'"$MODEL_ID"'"],

    "key": "YOUR_EXISTING_CALLER_KEY"

  }'
```

A key value must be unique within its environment. Creating a key with a value that another key in the same environment already uses returns `409` with the error code `DUPLICATE_NAME`. The same value can be used in different environments, so a key can be imported into each environment that serves its traffic.

A custom role with organization write access can change the import policy through the API.

With imports disabled, a create request that includes a custom value returns HTTP 403 with `CUSTOM_KEY_DISABLED`. New keys receive generated credentials, and previously imported keys continue to work.

For a bulk control-plane import, repeat the same request for each key. Re-running an import into the same environment returns `409` with the error code `DUPLICATE_NAME`, because the `display_name` or the key value is already taken there, so the import is safe to retry.

Set `key_hash` to the lowercase hexadecimal SHA-256 digest of the existing plaintext value, as described in [Caller API Key Hashes](https://docs.api7.ai/ai-gateway/reference/resources-file.md#caller-api-key-hashes). The gateway process never receives the plaintext.

## Manage a Caller API Key[​](#manage-a-caller-api-key "Direct link to 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[​](#set-an-expiration "Direct link to 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.

* AISIX Enterprise or Cloud
* AISIX OSS

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

* Dashboard
* Admin API

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](https://static.api7.ai/uploads/2026/11/18/eAwybe8c_caller-expiration.webp)

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.

Export the model resource ID used by the new key:

```
export MODEL_ID="YOUR_MODEL_ID"
```

Set the expiration at create time:

```
curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "display_name": "expiring-caller",

    "allowed_models": ["'"$MODEL_ID"'"],

    "expires_at": "2027-01-01T00:00:00Z"

  }'
```

To change the deadline on an existing key, export its resource ID:

```
export API_KEY_ID="YOUR_CALLER_API_KEY_ID"
```

Update the deadline with `PATCH`. The update changes only the fields you send:

```
curl -sS -X PATCH "$AISIX_CP/environments/$ENV_ID/api_keys/$API_KEY_ID" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "expires_at": "2027-06-30T00:00:00Z"

  }'
```

Setting an expiration does not affect the key before the deadline. A key with a future `expires_at` authenticates normally.

To make the key permanent again, send `"expires_at": null` to clear the deadline.

Merge the deadline into the existing caller API key entry:

resources.yaml (API key expiration)

```
api_keys:

  - id: a31b8275-cc81-4cdc-a618-875fd28c7532

    display_name: chat-app

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - gpt-4o-prod

    expires_at: "2027-01-01T00:00:00Z"
```

Preserve the key's other controls and every unrelated entry and collection. Validate the assembled complete resources file before reloading it to add, change, or remove the deadline. Once loaded, the gateway evaluates the deadline on every request.

### Disable and Re-enable a Caller API Key[​](#disable-and-re-enable-a-caller-api-key "Direct link to 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](#rotate-a-caller-api-key) if the credential may have been exposed, or delete it when the application no longer needs access.

* AISIX Enterprise or Cloud
* AISIX OSS

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

* Dashboard
* Admin API

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](https://static.api7.ai/uploads/2026/11/18/s33ySpo4_caller-disable.webp)

3. 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.

Export the key's resource ID:

```
export API_KEY_ID="YOUR_CALLER_API_KEY_ID"
```

Pause access with a `PATCH` update:

```
curl -sS -X PATCH "$AISIX_CP/environments/$ENV_ID/api_keys/$API_KEY_ID" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "disabled": true

  }'
```

To re-enable the key, send the same request with `disabled` set to `false`. Other fields, such as the model allowlist and any limits, are unchanged by the update. Re-enabling a key whose owner was deactivated by [SCIM directory sync](https://docs.api7.ai/ai-gateway/cloud/scim-directory-sync.md#what-a-deactivated-member-loses) returns `400`; bind the key to an active member, or remove its `user_id`, in the same request.

Merge `disabled: true` into the existing caller API key entry:

resources.yaml (disabled API key)

```
api_keys:

  - id: a31b8275-cc81-4cdc-a618-875fd28c7532

    display_name: chat-app

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - gpt-4o-prod

    disabled: true
```

Preserve the key's other controls and every unrelated entry and collection. Validate and reload the complete resources file. Set `disabled` to `false`, or remove the field, and reload the file to restore access with the same credential.

### Rotate a Caller API Key[​](#rotate-a-caller-api-key "Direct link to Rotate a Caller API Key")

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

* AISIX Enterprise or Cloud
* AISIX OSS

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.

* Dashboard
* Admin API

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](https://static.api7.ai/uploads/2026/11/18/vF4rNmxN_caller-rotate.webp)

3. Confirm the rotation. In **One-time view**, copy and securely store the new credential, then select **I've saved it**.
4. Update the application with the new credential and [verify access](#verify-access).

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

Export the key's resource ID:

```
export API_KEY_ID="YOUR_CALLER_API_KEY_ID"
```

Rotate the API key resource. The request has no body:

```
curl -sS -X POST "$AISIX_CP/environments/$ENV_ID/api_keys/$API_KEY_ID/rotate" \

  -H "Authorization: Bearer $AISIX_TOKEN"
```

You should see a response similar to the following:

```
{

  "api_key": {

    "id": "f1ad9f8a-75d0-46ae-9d8d-0cfe8d1d8387",

    "env_id": "9be9891a-6a53-4bd8-a897-a03fe38a1ca5",

    "display_name": "chat-app",

    "allowed_models": [

      "6a3f2c1d-8f4e-49b2-b6f1-3f6f24d0f9a2"

    ],

    "allow_all_models": false,

    "disabled": false,

    "status": "active",

    "created_at": "2026-06-24T12:18:39Z",

    "updated_at": "2026-06-24T12:21:05Z"

  },

  "plaintext": "sk-***"

}
```

The `plaintext` value is returned only in the rotate response.

For an immediate switch, replace the digest supplied through `key_hash` with the digest of the new key, and restart the gateway so the process receives the new environment value. The old plaintext stops working when the replacement configuration loads.

For a gradual rotation, make both digests available, `CALLER_API_KEY_SHA256` and `NEW_CALLER_API_KEY_SHA256`, and add `chat-app-new` to `api_keys`. Keep `chat-app` unchanged during the rollout:

resources.yaml (replacement API key)

```
api_keys:

  - id: 1c8c715b-1383-4246-af74-9a4adf5813b6

    display_name: chat-app-new

    key_hash: ${NEW_CALLER_API_KEY_SHA256}

    allowed_models:

      - gpt-4o-prod
```

The replacement is a separate caller API key. Preserve the controls that the application still needs:

* Model and tool access: `allow_all_models`, `mcp_access`, `allowed_agents`, and `allowed_routes`, in addition to the model allowlist shown above.
* Expiration and attribution: `expires_at`, `team_id`, `user_id`, and `user_name`.
* Inline traffic limits: `rate_limit`.

For each rate-limit policy scoped to the old key, add a corresponding policy for the new key during the overlap period. Give it its own `id`, keep `scope: api_key`, and set `scope_ref` to the `id` of `chat-app-new`. Remove the old policy after applications stop using the old key.

Validate the complete resources file, including the replacement key and its policies. Reload the file, or restart or recreate the gateway if the new environment variable was not already available to its process. After both credentials work, update applications to use the new value, remove the old entry, and validate and reload the resources file. This sequence keeps the old credential available during the caller rollout.

## Attribute Caller Traffic[​](#attribute-caller-traffic "Direct link to 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[​](#attribute-calls-to-teams-and-members "Direct link to 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.

* AISIX Enterprise or Cloud
* AISIX OSS

- Dashboard
- Admin API

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.

Export the key, team, and membership resource IDs:

```
export API_KEY_ID="YOUR_CALLER_API_KEY_ID"

export TEAM_ID="YOUR_TEAM_ID"

export MEMBERSHIP_ID="YOUR_MEMBERSHIP_ID"
```

Bind the key to both resources:

```
curl -sS -X PATCH "$AISIX_CP/environments/$ENV_ID/api_keys/$API_KEY_ID" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "team_id": "'"$TEAM_ID"'",

    "user_id": "'"$MEMBERSHIP_ID"'"

  }'
```

`MEMBERSHIP_ID` is the membership `id` returned by the [Members](https://docs.api7.ai/ai-gateway/cloud/members.md) API, not the member's account `user_id`. A team binding does not substitute for this member attribution.

Merge the attribution values into the existing caller key entry:

resources.yaml (caller attribution)

```
api_keys:

  - id: a31b8275-cc81-4cdc-a618-875fd28c7532

    display_name: chat-app

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - gpt-4o-prod

    team_id: platform

    user_id: alice

    user_name: Alice Example
```

These are operator-chosen attribution values; a resources file does not require separate team or member entries. Use the same `team_id` or `user_id` in policies that should match the key. Preserve the key's other controls and every unrelated entry and collection, then validate the assembled complete resources file before reloading it.

### Tag a Caller API Key[​](#tag-a-caller-api-key "Direct link to 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.

* AISIX Enterprise or Cloud
* AISIX OSS

Declare each [cost attribution tag](https://docs.api7.ai/ai-gateway/cloud/cost-attribution-tags.md) before assigning it to a caller key. In AISIX Enterprise and AISIX Cloud, tags can also select matching budgets.

* Dashboard
* Admin API

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](https://static.api7.ai/uploads/2026/11/18/0bZO85tN_caller-tags.webp)

Export the key's resource ID:

```
export API_KEY_ID="YOUR_CALLER_API_KEY_ID"
```

Update the key with the complete set of tags it should carry:

```
curl -sS -X PATCH "$AISIX_CP/environments/$ENV_ID/api_keys/$API_KEY_ID" \

  -H "Authorization: Bearer $AISIX_TOKEN" \

  -H "Content-Type: application/json" \

  -d '{

    "tags": {

      "department": "rnd"

    }

  }'
```

The tag key must already be declared in the organization.

See [How a Request Resolves Its Tags](https://docs.api7.ai/ai-gateway/cloud/cost-attribution-tags.md#how-a-request-resolves-its-tags) for the complete precedence rules.

Merge `tags` into the existing caller key entry. AISIX OSS validates the tag map directly and does not require a tag-key declaration:

resources.yaml (caller API key tags)

```
api_keys:

  - id: a31b8275-cc81-4cdc-a618-875fd28c7532

    display_name: chat-app

    key_hash: ${CALLER_API_KEY_SHA256}

    allowed_models:

      - gpt-4o-prod

    tags:

      department: rnd
```

Preserve the key's other fields and every unrelated entry and collection. Validate the assembled complete resources file before reloading it.

## Next Steps[​](#next-steps "Direct link to Next Steps")

You have now configured how a caller authenticates and which model aliases it can use. Continue with [Routing and Failover](https://docs.api7.ai/ai-gateway/routing/routing-and-failover.md) when one model alias should select from multiple upstream targets.

* For AISIX Enterprise or AISIX Cloud, bind caller credentials to a team with [Teams](https://docs.api7.ai/ai-gateway/cloud/teams.md) and control spend with [Budgets](https://docs.api7.ai/ai-gateway/traffic-controls/budgets.md).
* For any product, add caller-specific limits or shared controls with [API Key and Model Rate Limits](https://docs.api7.ai/ai-gateway/traffic-controls/rate-limits.md) and [Rate Limit Policies](https://docs.api7.ai/ai-gateway/traffic-controls/rate-limit-policies.md).
