---
title: "Create authorization code"
method: POST
path: "/auth/keys/code"
tags: ["OAuth"]
---

# Create authorization code

`POST /auth/keys/code`

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

## Request body

- object
  - `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 for enhanced security
  - `code_challenge_method` 'S256' | 'plain' — The method used to generate the code challenge
  - `expires_at` string, date-time, nullable — Optional expiration time for the API key to be created
  - `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
  - `spawn_agent` string — Agent identifier for spawn telemetry
  - `spawn_cloud` string — Cloud identifier for spawn telemetry
  - `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

## Response `200`

Successfully created authorization code

- object
  - `data` object, required — Auth code data
    - `app_id` integer, required — The application ID associated with this auth code
    - `created_at` string, required — ISO 8601 timestamp of when the auth code was created
    - `id` string, required — The authorization code ID to use in the exchange request

## Other responses

- `400` — Bad Request - Invalid request parameters or malformed input
- `401` — Unauthorized - Authentication required or invalid credentials
- `403` — Forbidden - Authentication successful but insufficient permissions
- `409` — Conflict - Resource conflict or concurrent modification
- `500` — Internal Server Error - Unexpected server error

---

[API](https://skmtc.net/openrouterteam/apis/openrouter-api.md) · [All operations](https://skmtc.net/openrouterteam/apis/openrouter-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/openrouterteam/openrouter-api/versions/9d1da2c7d2c3/schema)
