API Keys

Programmatically create, list, update, and delete API keys.

Overview

The Keys API allows you to manage API keys programmatically. This is useful for creating keys for sub-users, rotating keys, and enforcing per-key budgets and scopes.

All key management endpoints require a management key (allroutes_mgmt_) or a secret key with the keys:manage scope.

Create a Key

POST https://api.allroutes.ai/v1/keys

Request Body

FieldTypeRequiredDescription
namestringYesHuman-readable label for the key
scopesarrayNoPermission scopes (defaults to all scopes)
rate_limit_rpmintegerNoRequests per minute limit
daily_budget_usdfloatNoMaximum daily spend in USD
monthly_budget_usdfloatNoMaximum monthly spend in USD
allowed_modelsarrayNoRestrict key to specific model IDs
expires_atstringNoISO 8601 expiration timestamp

Example

curl -X POST https://api.allroutes.ai/v1/keys \
  -H "Authorization: Bearer allroutes_mgmt_..." \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production Backend",
    "scopes": ["chat:completions", "embeddings", "models:read"],
    "rate_limit_rpm": 600,
    "daily_budget_usd": 50.00,
    "monthly_budget_usd": 1000.00,
    "allowed_models": ["gpt-4o", "claude-sonnet-4-20250514"],
    "expires_at": "2026-12-31T23:59:59Z"
  }'

Response

{
  "id": "key_abc123",
  "key": "allroutes_sk_live_a1b2c3d4e5f6...",
  "name": "Production Backend",
  "scopes": ["chat:completions", "embeddings", "models:read"],
  "rate_limit_rpm": 600,
  "daily_budget_usd": 50.00,
  "monthly_budget_usd": 1000.00,
  "allowed_models": ["gpt-4o", "claude-sonnet-4-20250514"],
  "expires_at": "2026-12-31T23:59:59Z",
  "created_at": "2026-04-05T10:00:00Z",
  "is_active": true
}

The key field is only returned once at creation time. Store it securely.

List Keys

GET https://api.allroutes.ai/v1/keys

Returns all API keys for your organization (key values are masked).

Query Parameters

ParameterTypeDescription
activebooleanFilter by active/inactive status
limitintegerMax results per page (default: 50)
offsetintegerPagination offset

Example

curl https://api.allroutes.ai/v1/keys \
  -H "Authorization: Bearer allroutes_mgmt_..."

Response

{
  "data": [
    {
      "id": "key_abc123",
      "name": "Production Backend",
      "key_prefix": "allroutes_sk_live_a1b2...",
      "scopes": ["chat:completions", "embeddings", "models:read"],
      "rate_limit_rpm": 600,
      "daily_budget_usd": 50.00,
      "monthly_budget_usd": 1000.00,
      "usage_today_usd": 12.34,
      "usage_month_usd": 456.78,
      "is_active": true,
      "created_at": "2026-04-05T10:00:00Z",
      "last_used_at": "2026-04-05T14:30:00Z"
    }
  ],
  "total": 1
}

Update a Key

PATCH https://api.allroutes.ai/v1/keys/:id

Update key properties. Only fields included in the request body are modified.

Request Body

FieldTypeDescription
namestringUpdated label
scopesarrayUpdated permission scopes
rate_limit_rpmintegerUpdated RPM limit
daily_budget_usdfloatUpdated daily budget
monthly_budget_usdfloatUpdated monthly budget
allowed_modelsarrayUpdated model restrictions
expires_atstringUpdated expiration
is_activebooleanEnable or disable the key

Example

curl -X PATCH https://api.allroutes.ai/v1/keys/key_abc123 \
  -H "Authorization: Bearer allroutes_mgmt_..." \
  -H "Content-Type: application/json" \
  -d '{
    "rate_limit_rpm": 1200,
    "monthly_budget_usd": 2000.00
  }'

Delete a Key

DELETE https://api.allroutes.ai/v1/keys/:id

Permanently revokes and deletes an API key. This action cannot be undone.

curl -X DELETE https://api.allroutes.ai/v1/keys/key_abc123 \
  -H "Authorization: Bearer allroutes_mgmt_..."

Response

{
  "id": "key_abc123",
  "deleted": true
}

Error Codes

StatusDescription
400Invalid request body
401Missing or invalid authentication
403Key does not have keys:manage scope
404Key not found
409Key name already exists in organization

See Also