Skip to content

Create an API Key

POST /api/open/v1/keys

The request body is JSON with Content-Type: application/json. Validation rules match Key creation in the console.

FieldTypeRequiredDefaultDescription
namestringYes—Name, up to 50 characters (characters, not bytes); must not be empty
remain_amountnumberNo0Available amount in the site currency, two decimals; applies when unlimited is false; must not be negative or above the maximum
unlimitedbooleanNofalseWhether the Key is unlimited
expired_timeintegerNo-1Expiration 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_enabledbooleanNofalseWhether to enable the model allowlist
model_limitsstringNo""Allowed models, comma-separated
allow_ipsstringNo—Allowed IPs, newline-separated; omitted or empty string means no restriction
Terminal window
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"
}'
{
"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.

HTTPcodeScenario
400invalid_requestThe request body is not valid JSON, or is empty / null
400invalid_requestname is missing, blank, or longer than 50 characters
400invalid_requestexpired_time is not in the future (and is not 0 / -1), or is later than 9999-12-31 (for example a millisecond timestamp)
400invalid_requestThe per-user Key limit has been reached
400invalid_requestremain_amount is negative or above the maximum while unlimited is false

For other common error codes, see Platform API errors.

  • remain_amount is ignored when unlimited is true.
  • Creating a Key through the Platform API is recorded in the audit log.