Skip to main content
API keys allow your applications to access the LLM Gateway. They can be scoped to specific projects and have usage limits and IAM rules applied.

Create API Key

API keys are prefixed with llmgtwy_ in production and llmgdev_ in development.
description
string
required
Human-readable description of the API key (1-255 characters)
projectId
string
required
ID of the project this key belongs to
usageLimit
string | null
Maximum spend limit for this key in USD (e.g., “100.00”). Null for unlimited.
apiKey
object
The created API key object with the full token (only shown once)
curl -X POST https://api.llmgateway.io/keys/api \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Production API Key",
    "projectId": "proj_abc123",
    "usageLimit": "100.00"
  }'
{
  "apiKey": {
    "id": "key_xyz789",
    "token": "llmgtwy_abcdef1234567890",
    "description": "Production API Key",
    "status": "active",
    "usageLimit": "100.00",
    "usage": "0",
    "projectId": "proj_abc123",
    "createdBy": "user_123",
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-15T10:30:00Z",
    "creator": {
      "id": "user_123",
      "name": "John Doe",
      "email": "[email protected]"
    },
    "iamRules": []
  }
}
The full API key token is only returned once during creation. Store it securely - you won’t be able to retrieve it again.

List API Keys

Retrieve all API keys you have access to.
projectId
string
Filter keys by project ID
filter
'mine' | 'all'
Filter by creator:
  • mine: Only your API keys
  • all: All keys in accessible projects (requires admin/owner role)
apiKeys
array
Array of API key objects (with masked tokens)
planLimits
object | undefined
Plan limits information (only when projectId is specified)
userRole
'owner' | 'admin' | 'developer'
Your role in the organization
curl https://api.llmgateway.io/keys/api?projectId=proj_abc123&filter=mine \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN"
{
  "apiKeys": [
    {
      "id": "key_xyz789",
      "maskedToken": "llmgtwy_...7890",
      "description": "Production API Key",
      "status": "active",
      "usageLimit": "100.00",
      "usage": "24.50",
      "projectId": "proj_abc123",
      "createdBy": "user_123",
      "createdAt": "2024-01-15T10:30:00Z",
      "updatedAt": "2024-01-15T10:30:00Z",
      "creator": {
        "id": "user_123",
        "name": "John Doe",
        "email": "[email protected]"
      },
      "iamRules": []
    }
  ],
  "planLimits": {
    "currentCount": 3,
    "maxKeys": 20,
    "plan": "pro"
  },
  "userRole": "owner"
}

Update API Key Status

Activate or deactivate an API key.
id
string
required
API key ID
status
'active' | 'inactive'
required
New status for the API key
curl -X PATCH https://api.llmgateway.io/keys/api/key_xyz789 \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"status": "inactive"}'
{
  "message": "API key status updated to inactive",
  "apiKey": {
    "id": "key_xyz789",
    "maskedToken": "llmgtwy_...7890",
    "status": "inactive",
    "description": "Production API Key",
    "usageLimit": "100.00",
    "usage": "24.50",
    "projectId": "proj_abc123",
    "createdBy": "user_123",
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-16T14:20:00Z"
  }
}

Update Usage Limit

Modify the spending limit for an API key.
id
string
required
API key ID
usageLimit
string | null
required
New usage limit in USD, or null for unlimited
curl -X PATCH https://api.llmgateway.io/keys/api/limit/key_xyz789 \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"usageLimit": "200.00"}'

Delete API Key

Soft-delete an API key. The key will be marked as deleted and can no longer be used.
id
string
required
API key ID
Developers can only delete their own API keys. Admins and owners can delete any key in their organization.
curl -X DELETE https://api.llmgateway.io/keys/api/key_xyz789 \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN"
{
  "message": "API key deleted successfully"
}

IAM Rules

IAM rules allow fine-grained access control for API keys.

Rule Types

  • allow_models: Whitelist specific models
  • deny_models: Blacklist specific models
  • allow_pricing: Restrict to free or paid models
  • deny_pricing: Exclude free or paid models
  • allow_providers: Whitelist specific providers
  • deny_providers: Blacklist specific providers

Create IAM Rule

id
string
required
API key ID
ruleType
string
required
Type of IAM rule (see Rule Types above)
ruleValue
object
required
Rule configuration based on type
status
'active' | 'inactive'
default:"active"
Initial status of the rule
curl -X POST https://api.llmgateway.io/keys/api/key_xyz789/iam \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "ruleType": "allow_models",
    "ruleValue": {
      "models": ["gpt-4o", "claude-3-5-sonnet-20241022"]
    },
    "status": "active"
  }'
{
  "message": "IAM rule created successfully",
  "rule": {
    "id": "rule_123",
    "apiKeyId": "key_xyz789",
    "ruleType": "allow_models",
    "ruleValue": {
      "models": ["gpt-4o", "claude-3-5-sonnet-20241022"]
    },
    "status": "active",
    "createdAt": "2024-01-15T10:30:00Z",
    "updatedAt": "2024-01-15T10:30:00Z"
  }
}

List IAM Rules

curl https://api.llmgateway.io/keys/api/key_xyz789/iam \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN"

Update IAM Rule

curl -X PATCH https://api.llmgateway.io/keys/api/key_xyz789/iam/rule_123 \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"status": "inactive"}'

Delete IAM Rule

curl -X DELETE https://api.llmgateway.io/keys/api/key_xyz789/iam/rule_123 \
  -H "Authorization: Bearer YOUR_SESSION_TOKEN"

Error Responses

{
  "message": "API key limit reached. Maximum 20 API keys per project."
}

Build docs developers (and LLMs) love