OAuth

Create authorization code

Changed on

Create an authorization code for the PKCE flow to generate a user-controlled API key. Requires a Clerk session that completed reverification recently (Clerk lax level); otherwise the response is 403 with error.metadata.reverification set to lax, and the caller must reverify the session before retrying.

post/auth/keys/code

Request

  • Base URL
    https://openrouter.ai/api/v1
  • Auth
    HTTP bearer

Request body

object required
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.

code_challenge, string

PKCE code challenge: the base64url-encoded SHA-256 hash of your code_verifier. Send it with code_challenge_method set to S256.

code_challenge_method, 'S256' | 'plain'

The method used to generate the code challenge

expires_at, string date-time nullable

Optional ISO 8601 UTC expiration timestamp. Must include seconds (YYYY-MM-DDTHH:MM:SSZ; fractional seconds allowed); minute-precision timestamps are rejected.

key_label, string

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

limit, number double

Credit limit for the API key to be created

usage_limit_type, 'daily' | 'weekly' | 'monthly'

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

workspace_id, string uuid

Optional workspace ID to associate the API key with

Example request

{
  "callback_url": "https://myapp.com/auth/callback",
  "code_challenge": "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
  "code_challenge_method": "S256",
  "limit": 100
}

Response

Successfully created authorization code

object required
data, object required

Auth code data

Example response

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

Changes