For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
ModelsChatRankingsDocs
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
DocsAPI ReferenceClient SDKsAgent SDKCookbookChangelog
  • API Guides
    • Overview
    • Streaming
    • Embeddings
    • Limits
    • Authentication
    • Parameters
    • Errors and Debugging
  • API Reference
      • POSTExchange authorization code for API key
      • POSTCreate authorization code
LogoLogo
ModelsChatRankingsDocs
API ReferenceOAuth

Create authorization code

POST
https://openrouter.ai/api/v1/auth/keys/code
POST
/api/v1/auth/keys/code
$curl -X POST https://openrouter.ai/api/v1/auth/keys/code \
> -H "Authorization: Bearer <token>" \
> -H "Content-Type: application/json" \
> -d '{
> "callback_url": "https://myapp.com/auth/callback",
> "code_challenge": "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM",
> "code_challenge_method": "S256",
> "limit": 100
>}'
1{
2 "data": {
3 "app_id": 12345,
4 "created_at": "2025-08-24T10:30:00Z",
5 "id": "auth_code_xyz789"
6 }
7}

Create an authorization code for the PKCE flow to generate a user-controlled API key

Was this page helpful?
Previous

Create speech

Next
Built with

Authentication

AuthorizationBearer
API key as bearer token in Authorization header

Request

This endpoint expects an object.
callback_urlstringRequiredformat: "uri"
The callback URL to redirect to after authorization. Note, only https URLs on ports 443 and 3000 are allowed.
code_challengestringOptional
PKCE code challenge for enhanced security
code_challenge_methodenumOptional
The method used to generate the code challenge
Allowed values:
expires_atdatetime or nullOptional
Optional expiration time for the API key to be created
key_labelstringOptional<=100 characters
Optional custom label for the API key. Defaults to the app name if not provided.
limitdoubleOptional
Credit limit for the API key to be created
usage_limit_typeenumOptional
Optional credit limit reset interval. When set, the credit limit resets on this interval.
Allowed values:

Response

Successfully created authorization code
dataobject
Auth code data

Errors

400
Bad Request Error
401
Unauthorized Error
409
Conflict Error
500
Internal Server Error