Skip to main content

Create API Key

Create a new API key for the authenticated user. The key_value will only be returned on creation.

Request Body

object
required
API key object
string
required
Descriptive name for the key
string
required
Type of key: ‘private’ or ‘public’
array
Array of allowed CORS origins
array
Array of assistant IDs the key can access
boolean
default:"false"
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

status
object
Response status information
code
integer
HTTP status code (201)
message
string
Status message
data
object
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

401
object
Unauthorized - Invalid or missing authentication
422
object
Validation error - Invalid request body