Skip to main content
POST
/
auth
/
keys
/
code
Create authorization code
curl --request POST \
  --url https://openrouter.ai/api/v1/auth/keys/code \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "callback_url": "https://myapp.com/auth/callback",
  "code_challenge": "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
  "code_challenge_method": "S256",
  "limit": 100
}
'
{
  "data": {
    "app_id": 12345,
    "created_at": "2025-08-24T10:30:00Z",
    "id": "auth_code_xyz789"
  }
}

Authorizations

Authorization
string
header
required

API key as bearer token in Authorization header

Body

application/json
callback_url
string<uri>
required

The callback URL to redirect to after authorization. Supports https URLs and localhost/127.0.0.1 URLs on any port for local CLI tools.

Example:

"https://myapp.com/auth/callback"

code_challenge
string

PKCE code challenge for enhanced security

Example:

"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"

code_challenge_method
enum<string>

The method used to generate the code challenge

Available options:
S256,
plain
Example:

"S256"

expires_at
string<date-time> | null

Optional expiration time for the API key to be created

Example:

"2027-12-31T23:59:59Z"

key_label
string

Optional custom label for the API key. Defaults to the app name if not provided.

Maximum string length: 100
Example:

"My Custom Key"

limit
number<double>

Credit limit for the API key to be created

Example:

100

spawn_agent
string

Agent identifier for spawn telemetry

Example:

"my-agent"

spawn_cloud
string

Cloud identifier for spawn telemetry

Example:

"aws-us-east-1"

usage_limit_type
enum<string>

Optional credit limit reset interval. When set, the credit limit resets on this interval.

Available options:
daily,
weekly,
monthly
Example:

"monthly"

workspace_id
string<uuid>

Optional workspace ID to associate the API key with

Response

Successfully created authorization code

data
object
required

Auth code data

Example:
{
  "app_id": 12345,
  "created_at": "2025-08-24T10:30:00Z",
  "id": "auth_code_xyz789"
}