Create an API Key
POST /api/open/v1/keysRequest parameters
Section titled “Request parameters”The request body is JSON with Content-Type: application/json. Validation rules match Key creation in the console.
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | Yes | — | Name, up to 50 characters (characters, not bytes); must not be empty |
remain_amount | number | No | 0 | Available amount in the site currency, two decimals; applies when unlimited is false; must not be negative or above the maximum |
unlimited | boolean | No | false | Whether the Key is unlimited |
expired_time | integer | No | -1 | Expiration time, unix seconds; omitted, 0, and -1 all mean never expires; otherwise it must be in the future and no later than 9999-12-31 |
model_limits_enabled | boolean | No | false | Whether to enable the model allowlist |
model_limits | string | No | "" | Allowed models, comma-separated |
allow_ips | string | No | — | Allowed IPs, newline-separated; omitted or empty string means no restriction |
Request example
Section titled “Request example”curl -X POST https://www.routeapi.ai/api/open/v1/keys \ -H "Authorization: Bearer $ROUTEAPI_MANAGEMENT_KEY" \ -H "Content-Type: application/json" \ -d '{ "name": "bot", "remain_amount": 5.00, "unlimited": false, "expired_time": -1, "model_limits_enabled": true, "model_limits": "gpt-4o" }'Response example
Section titled “Response example”{ "success": true, "message": "", "data": { "id": 13, "name": "bot", "key": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "status": 1, "created_time": 1729000000, "accessed_time": 1729000000, "expired_time": -1, "remain_amount": 5.00, "unlimited": false, "used_amount": 0.00, "model_limits_enabled": true, "model_limits": "gpt-4o", "allow_ips": "" }}For field descriptions, see Key object.
Errors
Section titled “Errors”| HTTP | code | Scenario |
|---|---|---|
| 400 | invalid_request | The request body is not valid JSON, or is empty / null |
| 400 | invalid_request | name is missing, blank, or longer than 50 characters |
| 400 | invalid_request | expired_time is not in the future (and is not 0 / -1), or is later than 9999-12-31 (for example a millisecond timestamp) |
| 400 | invalid_request | The per-user Key limit has been reached |
| 400 | invalid_request | remain_amount is negative or above the maximum while unlimited is false |
For other common error codes, see Platform API errors.
remain_amountis ignored whenunlimitedistrue.- Creating a Key through the Platform API is recorded in the audit log.