Skip to content

Create Keys

Overview

Programmatically create API keys via API, commonly used in SaaS applications to automatically create unique API keys for each customer instance.

Use Cases

SaaS Applications

Automatically create unique API keys for each customer instance to achieve customer-level resource isolation and billing.

Key Management

Programmatically manage keys, supporting creation, rotation, deletion and other operations to meet security compliance requirements.

API Request

Request Example

bash
curl -X POST https://ai-tokenhub.com/v1/keys \
  -H "Authorization: Bearer <YOUR_MANAGEMENT_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-api-key",
    "limit": 10.00,
    "limit_reset": "daily"
  }'

Request Parameters

ParameterTypeRequiredDescription
namestringYesAPI key name for identification
limitdoubleNoSpending limit in USD, key will be disabled when reached
limit_resetenumNoLimit reset period: daily, weekly, monthly, or null (no reset)

Response Example

json
{
  "id": "sk_or_xxx",
  "name": "my-api-key",
  "hash": "xxx",
  "key": "sk_or_xxx|xxx",
  "enabled": true,
  "limit": 10.00,
  "limit_reset": "daily",
  "created_at": "2024-01-01T00:00:00Z"
}

Important Notes

  • The key field is only shown once when created, please keep it safe
  • Management API Key cannot be used for OpenRouter completion endpoints, only for administrative operations
  • It is recommended to create separate keys for different purposes for easier management and monitoring