Create authorization code
Changed onCreate 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.
Request
- Base URLhttps://openrouter.ai/api/v1
- AuthHTTP bearer
Request body
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.
PKCE code challenge: the base64url-encoded SHA-256 hash of your code_verifier. Send it with code_challenge_method set to S256.
The method used to generate the code challenge
Optional ISO 8601 UTC expiration timestamp. Must include seconds (YYYY-MM-DDTHH:MM:SSZ; fractional seconds allowed); minute-precision timestamps are rejected.
Optional custom label for the API key. Defaults to the app name if not provided.
Credit limit for the API key to be created
Optional credit limit reset interval. When set, the credit limit resets on this interval.
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
Auth code data
Example response
{
"data": {
"app_id": 12345,
"created_at": "2025-08-24T10:30:00Z",
"id": "auth_code_xyz789"
}
}Changes
- info
added the non-success response with the status
- info
- warning
removed the request property
spawn_agent - warning
removed the request property
spawn_cloud
- warning