Create API Key
Create a new API key for the authenticated user. The key_value will only be returned on creation.
Request Body
API key objectDescriptive name for the key
Type of key: ‘private’ or ‘public’
Array of allowed CORS origins
Array of assistant IDs the key can access
Whether the key supports transient assistants
curl -X POST "https://api.example.com/api/v1/api_keys" \
-H "X-API-Key: your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"api_key": {
"name": "Production API Key",
"key_type": "private",
"allowed_origins": ["https://example.com"],
"allowed_assistants": ["123"],
"transient_assistant": false
}
}'
Response
Response status information
Created API key object (includes key_value only on creation)
{
"status": {
"code": 201,
"message": "API key created successfully"
},
"data": {
"id": 1,
"key_type": "private",
"name": "Production API Key",
"key_value": "sk_live_abc123xyz789",
"allowed_origins": ["https://example.com"],
"allowed_assistants": ["123"],
"transient_assistant": false,
"user_id": 1,
"user_email": "[email protected]",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z"
}
}
The key_value is only returned when creating a new API key. Store it securely immediately as it cannot be retrieved later.
Error Responses
Unauthorized - Invalid or missing authentication
Validation error - Invalid request body