OAuth
Exchange authorization code for API key
Changed onExchange an authorization code from the PKCE flow for a user-controlled API key
post/auth/keys
Request
- Base URLhttps://openrouter.ai/api/v1
- AuthHTTP bearer
Request body
object required
code, string required
The authorization code received from the OAuth redirect
code_challenge_method, 'S256' | 'plain' | 'null' nullable
The method used to generate the code challenge
code_verifier, string
The code_verifier whose SHA-256 hash was sent as code_challenge in the authorization request.
Example request
{
"code": "auth_code_abc123def456",
"code_challenge_method": "S256",
"code_verifier": "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
}Response
Successfully exchanged code for an API key
object required
key, string required
The API key to use for OpenRouter requests
user_id, string nullable required
User ID associated with the API key
Example response
{
"key": "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",
"user_id": "user_2yOPcMpKoQhcd4bVgSMlELRaIah"
}Changes
- breaking
the request property
code_challenge_methodbecame not nullable
- breaking
- info
added the optional property
openrouter_metadatato the response with the status - info
added the optional property
openrouter_metadatato the response with the status
1 more change in this revision
- info