[metadata]
apple-mobile-web-app-title: OpenRouter | Documentation
application-name: OpenRouter | Documentation
description: Create a new API key for the authenticated user. The plaintext key is returned only in this response. Treat it as a write-only, sensitive value; it cannot be retrieved later. Management key required.
generator: Mintlify
msapplication-TileColor: #7624F4
msapplication-config: /docs/_mintlify/favicons/openrouter-d02e98a0/EmhfYwFO2tvnkuV-/_generated/favicon/browserconfig.xml
og:description: Create a new API key for the authenticated user. The plaintext key is returned only in this response. Treat it as a write-only, sensitive value; it cannot be retrieved later. Management key required.
og:image: https://openrouter-d02e98a0.mintlify.app/_next/image?url=%2F_mintlify%2Fapi%2Fog%3Fdivision%3DAPI%2BKeys%26appearance%3Ddark%26title%3DCreate%2Ba%2Bnew%2BAPI%2Bkey%26description%3DCreate%2Ba%2Bnew%2BAPI%2Bkey%2Bfor%2Bthe%2Bauthenticated%2Buser.%2BThe%2Bplaintext%2B%2560key%2560%2Bis%2Breturned%2Bonly%2Bin%2Bthis%2Bresponse.%2BTreat%2Bit%2Bas%2Ba%2Bwrite-only%252C%2Bsensitive%2Bvalue%253B%2Bit%2Bcannot%2Bbe%2B%26logoLight%3Dhttps%253A%252F%252Fmintcdn.com%252Fopenrouter-d02e98a0%252FksNSeB_K7gD-BUDh%252Fassets%252Flogo-v2-light.svg%253Ffit%253Dmax%2526auto%253Dformat%2526n%253DksNSeB_K7gD-BUDh%2526q%253D85%2526s%253D690e45873843519efe02bcbe45795dac%26logoDark%3Dhttps%253A%252F%252Fmintcdn.com%252Fopenrouter-d02e98a0%252FksNSeB_K7gD-BUDh%252Fassets%252Flogo-v2-dark.svg%253Ffit%253Dmax%2526auto%253Dformat%2526n%253DksNSeB_K7gD-BUDh%2526q%253D85%2526s%253D8ba2f49b11cd9839c37dd03c62537ebd%26primaryColor%3D%25237624F4%26lightColor%3D%25237624F4%26backgroundLight%3D%2523FCFCFE%26backgroundDark%3D%252303080A&w=1200&q=100
og:image:height: 630
og:image:width: 1200
og:site_name: OpenRouter | Documentation
og:title: Create a new API key - OpenRouter | Documentation
og:type: website
og:url: https://openrouter.ai/docs/api/api-reference/api-keys/create-a-new-api-key
twitter:card: summary_large_image
twitter:description: Create a new API key for the authenticated user. The plaintext key is returned only in this response. Treat it as a write-only, sensitive value; it cannot be retrieved later. Management key required.
twitter:image: https://openrouter-d02e98a0.mintlify.app/_next/image?url=%2F_mintlify%2Fapi%2Fog%3Fdivision%3DAPI%2BKeys%26appearance%3Ddark%26title%3DCreate%2Ba%2Bnew%2BAPI%2Bkey%26description%3DCreate%2Ba%2Bnew%2BAPI%2Bkey%2Bfor%2Bthe%2Bauthenticated%2Buser.%2BThe%2Bplaintext%2B%2560key%2560%2Bis%2Breturned%2Bonly%2Bin%2Bthis%2Bresponse.%2BTreat%2Bit%2Bas%2Ba%2Bwrite-only%252C%2Bsensitive%2Bvalue%253B%2Bit%2Bcannot%2Bbe%2B%26logoLight%3Dhttps%253A%252F%252Fmintcdn.com%252Fopenrouter-d02e98a0%252FksNSeB_K7gD-BUDh%252Fassets%252Flogo-v2-light.svg%253Ffit%253Dmax%2526auto%253Dformat%2526n%253DksNSeB_K7gD-BUDh%2526q%253D85%2526s%253D690e45873843519efe02bcbe45795dac%26logoDark%3Dhttps%253A%252F%252Fmintcdn.com%252Fopenrouter-d02e98a0%252FksNSeB_K7gD-BUDh%252Fassets%252Flogo-v2-dark.svg%253Ffit%253Dmax%2526auto%253Dformat%2526n%253DksNSeB_K7gD-BUDh%2526q%253D85%2526s%253D8ba2f49b11cd9839c37dd03c62537ebd%26primaryColor%3D%25237624F4%26lightColor%3D%25237624F4%26backgroundLight%3D%2523FCFCFE%26backgroundDark%3D%252303080A&w=1200&q=100
twitter:image:height: 630
twitter:image:width: 1200
twitter:title: Create a new API key - OpenRouter | Documentation
viewport: width=device-width, initial-scale=1, viewport-fit=cover

[canonical-links]
https://openrouter.ai/docs/api/api-reference/api-keys/create-a-new-api-key

[document-links]
/docs/llms.txt: /docs/llms.txt
API Changelog: /docs/changelog
API Reference: /docs/api_reference/overview
API Versioning: /docs/api_reference/versioning
Agent SDK: /docs/agent-sdk/overview
Apps: https://openrouter.ai/apps
Authentication: /docs/api_reference/authentication
Benchmarks: https://openrouter.ai/benchmarks
Chat: https://openrouter.ai/chat
Client SDKs: /docs/client-sdks/overview
Cookbook: /docs/cookbook/get-started/quickstart
DEL Delete an API key: /docs/api/api-reference/api-keys/delete-an-api-key
Docs: /docs/quickstart
Docs: https://openrouter.ai/docs
Embeddings: /docs/api_reference/embeddings
Errors and Debugging: /docs/api_reference/errors-and-debugging
GET Get a single API key: /docs/api/api-reference/api-keys/get-a-single-api-key
GET Get current API key: /docs/api/api-reference/api-keys/get-current-api-key
GET List API keys: /docs/api/api-reference/api-keys/list-api-keys
Get a single API key: /docs/api/api-reference/api-keys/get-a-single-api-key
Limits: /docs/api_reference/limits
List API keys: /docs/api/api-reference/api-keys/list-api-keys
Management key: /docs/guides/overview/auth/management-api-keys
Models: https://openrouter.ai/models
OpenRouter | Documentation home page: https://openrouter.ai
Overview: /docs/api_reference/overview
PATCH Update an API key: /docs/api/api-reference/api-keys/update-an-api-key
POST Create a new API key: /docs/api/api-reference/api-keys/create-a-new-api-key
Parameters: /docs/api_reference/parameters
Rankings: https://openrouter.ai/rankings
Streaming: /docs/api_reference/streaming

[content]
Create a new API key - OpenRouter | Documentation
Documentation Index
Fetch the complete documentation index at:
/docs/llms.txt
Use this file to discover all available pages before exploring further.
Skip to main content
OpenRouter | Documentation
home page
Search...
⌘
K
Ask Assistant
Models
Benchmarks
Chat
Rankings
Apps
Docs
Search...
Navigation
API Keys
Create a new API key
Docs
API Reference
Client SDKs
Agent SDK
Cookbook
API Guides
Overview
Streaming
Embeddings
Limits
Authentication
Parameters
Errors and Debugging
Responses API
Versioning
API Versioning
API Changelog
API Reference
Analytics
TTS
STT
OAuth
Benchmarks
BYOK
Chat
Classifications
Credits
Datasets
Embeddings
Endpoints
Generations
Guardrails
Images
API Keys
GET
Get current API key
GET
List API keys
POST
Create a new API key
GET
Get a single API key
DEL
Delete an API key
PATCH
Update an API key
Anthropic Messages
Models
Observability
Organization
Presets
Providers
Rerank
Responses
SCIM
Video Generation
Workspaces
Create a new API key
cURL
curl --request POST \ --url https://openrouter.ai/api/v1/keys \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data ' { "expires_at": "2027-12-31T23:59:59Z", "include_byok_in_limit": true, "limit": 50, "limit_reset": "monthly", "name": "My New API Key" } '
import requests url = "https://openrouter.ai/api/v1/keys" payload = { "expires_at": "2027-12-31T23:59:59Z", "include_byok_in_limit": True, "limit": 50, "limit_reset": "monthly", "name": "My New API Key" } headers = { "Authorization": "Bearer <token>", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.text)
const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: JSON.stringify({ expires_at: '2027-12-31T23:59:59Z', include_byok_in_limit: true, limit: 50, limit_reset: 'monthly', name: 'My New API Key' }) }; fetch('https://openrouter.ai/api/v1/keys', options) .then(res => res.json()) .then(res => console.log(res)) .catch(err => console.error(err));
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://openrouter.ai/api/v1/keys", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode([ 'expires_at' => '2027-12-31T23:59:59Z', 'include_byok_in_limit' => true, 'limit' => 50, 'limit_reset' => 'monthly', 'name' => 'My New API Key' ]), CURLOPT_HTTPHEADER => [ "Authorization: Bearer <token>", "Content-Type: application/json" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://openrouter.ai/api/v1/keys" payload := strings.NewReader("{\n \"expires_at\": \"2027-12-31T23:59:59Z\",\n \"include_byok_in_limit\": true,\n \"limit\": 50,\n \"limit_reset\": \"monthly\",\n \"name\": \"My New API Key\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer <token>") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) }
HttpResponse<String> response = Unirest.post("https://openrouter.ai/api/v1/keys") .header("Authorization", "Bearer <token>") .header("Content-Type", "application/json") .body("{\n \"expires_at\": \"2027-12-31T23:59:59Z\",\n \"include_byok_in_limit\": true,\n \"limit\": 50,\n \"limit_reset\": \"monthly\",\n \"name\": \"My New API Key\"\n}") .asString();
require 'uri' require 'net/http' url = URI("https://openrouter.ai/api/v1/keys") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer <token>' request["Content-Type"] = 'application/json' request.body = "{\n \"expires_at\": \"2027-12-31T23:59:59Z\",\n \"include_byok_in_limit\": true,\n \"limit\": 50,\n \"limit_reset\": \"monthly\",\n \"name\": \"My New API Key\"\n}" response = http.request(request) puts response.read_body
201
400
401
403
429
500
{ "data": { "byok_usage": 0, "byok_usage_daily": 0, "byok_usage_monthly": 0, "byok_usage_weekly": 0, "created_at": "2025-08-24T10:30:00Z", "creator_user_id": "user_2dHFtVWx2n56w6HkM0000000000", "disabled": false, "expires_at": "2027-12-31T23:59:59Z", "hash": "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", "include_byok_in_limit": true, "label": "My New API Key", "limit": 50, "limit_remaining": 50, "limit_reset": "monthly", "name": "My New API Key", "updated_at": null, "usage": 0, "usage_daily": 0, "usage_monthly": 0, "usage_weekly": 0, "workspace_id": "0df9e665-d932-5740-b2c7-b52af166bc11" }, "key": "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" }
{ "error": { "code": 400, "message": "Invalid request parameters" } }
{ "error": { "code": 401, "message": "Missing Authentication header" } }
{ "error": { "code": 403, "message": "Only management keys can perform this operation" } }
{ "error": { "code": 429, "message": "Rate limit exceeded" } }
{ "error": { "code": 500, "message": "Internal Server Error" } }
API Keys
Create a new API key
Copy page
Copy page
Create a new API key for the authenticated user. The plaintext
key
is returned only in this response. Treat it as a write-only, sensitive value; it cannot be retrieved later.
Management key
required.
Copy page
Copy page
POST
/
keys
Try it
Create a new API key
cURL
curl --request POST \ --url https://openrouter.ai/api/v1/keys \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data ' { "expires_at": "2027-12-31T23:59:59Z", "include_byok_in_limit": true, "limit": 50, "limit_reset": "monthly", "name": "My New API Key" } '
import requests url = "https://openrouter.ai/api/v1/keys" payload = { "expires_at": "2027-12-31T23:59:59Z", "include_byok_in_limit": True, "limit": 50, "limit_reset": "monthly", "name": "My New API Key" } headers = { "Authorization": "Bearer <token>", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.text)
const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: JSON.stringify({ expires_at: '2027-12-31T23:59:59Z', include_byok_in_limit: true, limit: 50, limit_reset: 'monthly', name: 'My New API Key' }) }; fetch('https://openrouter.ai/api/v1/keys', options) .then(res => res.json()) .then(res => console.log(res)) .catch(err => console.error(err));
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://openrouter.ai/api/v1/keys", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => json_encode([ 'expires_at' => '2027-12-31T23:59:59Z', 'include_byok_in_limit' => true, 'limit' => 50, 'limit_reset' => 'monthly', 'name' => 'My New API Key' ]), CURLOPT_HTTPHEADER => [ "Authorization: Bearer <token>", "Content-Type: application/json" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://openrouter.ai/api/v1/keys" payload := strings.NewReader("{\n \"expires_at\": \"2027-12-31T23:59:59Z\",\n \"include_byok_in_limit\": true,\n \"limit\": 50,\n \"limit_reset\": \"monthly\",\n \"name\": \"My New API Key\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer <token>") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(string(body)) }
HttpResponse<String> response = Unirest.post("https://openrouter.ai/api/v1/keys") .header("Authorization", "Bearer <token>") .header("Content-Type", "application/json") .body("{\n \"expires_at\": \"2027-12-31T23:59:59Z\",\n \"include_byok_in_limit\": true,\n \"limit\": 50,\n \"limit_reset\": \"monthly\",\n \"name\": \"My New API Key\"\n}") .asString();
require 'uri' require 'net/http' url = URI("https://openrouter.ai/api/v1/keys") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer <token>' request["Content-Type"] = 'application/json' request.body = "{\n \"expires_at\": \"2027-12-31T23:59:59Z\",\n \"include_byok_in_limit\": true,\n \"limit\": 50,\n \"limit_reset\": \"monthly\",\n \"name\": \"My New API Key\"\n}" response = http.request(request) puts response.read_body
201
400
401
403
429
500
{ "data": { "byok_usage": 0, "byok_usage_daily": 0, "byok_usage_monthly": 0, "byok_usage_weekly": 0, "created_at": "2025-08-24T10:30:00Z", "creator_user_id": "user_2dHFtVWx2n56w6HkM0000000000", "disabled": false, "expires_at": "2027-12-31T23:59:59Z", "hash": "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", "include_byok_in_limit": true, "label": "My New API Key", "limit": 50, "limit_remaining": 50, "limit_reset": "monthly", "name": "My New API Key", "updated_at": null, "usage": 0, "usage_daily": 0, "usage_monthly": 0, "usage_weekly": 0, "workspace_id": "0df9e665-d932-5740-b2c7-b52af166bc11" }, "key": "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" }
{ "error": { "code": 400, "message": "Invalid request parameters" } }
{ "error": { "code": 401, "message": "Missing Authentication header" } }
{ "error": { "code": 403, "message": "Only management keys can perform this operation" } }
{ "error": { "code": 429, "message": "Rate limit exceeded" } }
{ "error": { "code": 500, "message": "Internal Server Error" } }
Authorizations
​
Authorization
string
header
required
API key as bearer token in Authorization header
Body
application/json
​
name
string
required
Name for the new API key
Minimum string length:
1
Example
:
"My New API Key"
​
creator_user_id
string | null
Optional user ID of the key creator. Only meaningful for organization-owned keys where a specific member is creating the key.
Minimum string length:
1
Example
:
"user_2dHFtVWx2n56w6HkM0000000000"
​
expires_at
string<date-time> | null
Optional ISO 8601 UTC timestamp when the API key should expire. Must be UTC, other timezones will be rejected
Example
:
"2027-12-31T23:59:59Z"
​
include_byok_in_limit
boolean
Whether to include BYOK usage in the limit
Example
:
true
​
limit
number<double> | null
Optional spending limit for the API key in USD
Example
:
50
​
limit_reset
enum<string> | null
Type of limit reset for the API key (daily, weekly, monthly, or null for no reset). Resets happen automatically at midnight UTC, and weeks are Monday through Sunday.
Available options
:
daily
,
weekly
,
monthly
,
null
Example
:
"monthly"
​
workspace_id
string<uuid>
The workspace to create the API key in. Defaults to the default workspace if not provided.
Example
:
"0df9e665-d932-5740-b2c7-b52af166bc11"
Response
201
application/json
API key created successfully
​
data
object
required
The created API key information
Show
child attributes
Example
:
{ "byok_usage": 17.38, "byok_usage_daily": 17.38, "byok_usage_monthly": 17.38, "byok_usage_weekly": 17.38, "created_at": "2025-08-24T10:30:00Z", "creator_user_id": "user_2dHFtVWx2n56w6HkM0000000000", "disabled": false, "expires_at": "2027-12-31T23:59:59Z", "hash": "f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", "include_byok_in_limit": false, "label": "sk-or-v1-0e6...1c96", "limit": 100, "limit_remaining": 74.5, "limit_reset": "monthly", "name": "My Production Key", "updated_at": "2025-08-24T15:45:00Z", "usage": 25.5, "usage_daily": 25.5, "usage_monthly": 25.5, "usage_weekly": 25.5, "workspace_id": "0df9e665-d932-5740-b2c7-b52af166bc11" }
​
key
string
required
The actual API key string (only shown once)
Example
:
"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"
List API keys
Get a single API key
⌘
I
Assistant
Responses are generated using AI and may contain mistakes.
