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
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | API key name for identification |
| limit | double | No | Spending limit in USD, key will be disabled when reached |
| limit_reset | enum | No | Limit 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
keyfield 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