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
      • GETGet current API key
      • GETList API keys
      • POSTCreate a new API key
      • GETGet a single API key
      • DELDelete an API key
      • PATCHUpdate an API key
LogoLogo
ModelsChatRankingsDocs
API ReferenceAPI Keys

Create a new API key

POST
https://openrouter.ai/api/v1/keys
POST
/api/v1/keys
$curl -X POST https://openrouter.ai/api/v1/keys \
> -H "Authorization: Bearer <token>" \
> -H "Content-Type: application/json" \
> -d '{
> "name": "Analytics Service Key",
> "expires_at": "2029-11-30T23:59:59Z",
> "include_byok_in_limit": false,
> "limit": 100,
> "limit_reset": "weekly"
>}'
1{
2 "data": {
3 "byok_usage": 12,
4 "byok_usage_daily": 1,
5 "byok_usage_monthly": 45,
6 "byok_usage_weekly": 10,
7 "created_at": "2024-06-15T09:00:00Z",
8 "creator_user_id": "user_7a9XvLq3pZ8bN1cD0000000000",
9 "disabled": false,
10 "hash": "a3f5b7c9d8e1f23456789abcdef0123456789abcdef0123456789abcdef0123",
11 "include_byok_in_limit": false,
12 "label": "sk-or-v1-analytics-1a2b3c",
13 "limit": 100,
14 "limit_remaining": 88,
15 "limit_reset": "weekly",
16 "name": "Analytics Service Key",
17 "updated_at": "2024-06-20T14:45:00Z",
18 "usage": 12,
19 "usage_daily": 1,
20 "usage_monthly": 50,
21 "usage_weekly": 12,
22 "workspace_id": "3f9e665d-d932-5740-b2c7-b52af166bc11",
23 "expires_at": "2029-11-30T23:59:59Z"
24 },
25 "key": "sk-or-v1-7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b"
26}

Create a new API key for the authenticated user. Management key required.

Was this page helpful?
Previous

Get a single API key

Next
Built with

Authentication

AuthorizationBearer
API key as bearer token in Authorization header

Request

This endpoint expects an object.
namestringRequired>=1 character
Name for the new API key
creator_user_idstring or nullOptional>=1 character

Optional user ID of the key creator. Only meaningful for organization-owned keys where a specific member is creating the key.

expires_atdatetime or nullOptional
Optional ISO 8601 UTC timestamp when the API key should expire. Must be UTC, other timezones will be rejected
include_byok_in_limitbooleanOptional
Whether to include BYOK usage in the limit
limitdouble or nullOptional
Optional spending limit for the API key in USD
limit_resetenum or nullOptional

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.

Allowed values:
workspace_idstringOptionalformat: "uuid"
The workspace to create the API key in. Defaults to the default workspace if not provided.

Response

API key created successfully
dataobject
The created API key information
keystring

The actual API key string (only shown once)

Errors

400
Bad Request Error
401
Unauthorized Error
403
Forbidden Error
429
Too Many Requests Error
500
Internal Server Error