Files
openrouter-python-sdk-retry…/docs/sdks/apikeys
OpenRouter Team 1cad51abb6 Commits included in this export:
- 6ddaaa6989d725bbe966e45f7aed0c1bd72f9153
  - 4779741b6ba710b1299612b82e8544516bd9dd6a
  - 22083fcc8f58884d8212d6f3314b231c4ddd21cd
  - a925a620f97196d509e073a163caac053bd82316
  - 5c05d8829784601ffd151acef1a6978c266f913d
  - 6f4fff535fbf4274255c255ae23620b8e00e614f
  - ef358e96cb01e469b77d44683603a602b0813116
  - e6299b4ebfe5c2eed6c598771f0fd99f84555401
  - 24d3f0ee1c2aa19a62f7902836034080b9246813
  - 68922847c2969b773887310eb7aa9a814e199c5a
  - 729ee2338c39df22461526153e7f4ba868fd498e
  - e1074ff86fccf5e48406b7595298873106d3cc5a
  - 123bbdaf841d299162a82ee2573adfbb70a45b8f
  - ac457b8a8dad98fdf5ddcae8dd4711361cea3084
  - ea825199f4c59dd68fec01cf8d18a582963c9f25
  - 4d48e4f6bb936e785787314a965298da6b78fea0
  - 718729a573ee98893a4408d5a52ab4686661fe54
  - b867adcde6b64f3f2a11c4626254b39098e4b0b4
  - 21912c097b4066d109766c6b4492826595cd57c5
  - bc1ed85adc976a4634ca8a41b82e4fc2c39a864f
  - d145c89c941937a312ed1357590d2bfda9a3603d
  - 12f05b5dee397ead47cfcd545a7a2e3c7ff57524
  - dd28f75a19a015809797c7abf3f8758f7c37262e
  - c96e569781e07ab44172d9c69940ec17bafd81f4
  - c9d5a90e3c2b5077a2bdd49773f1a46d1a5a79c7
  - 58b08f87116ceab9076de2fdc0a4c74c919b44c4

GitOrigin-RevId: 6ddaaa6989d725bbe966e45f7aed0c1bd72f9153
2026-02-05 23:15:21 +00:00
..
2026-02-05 23:15:21 +00:00

APIKeys

(api_keys)

Overview

API key management endpoints

Available Operations

list

List all API keys for the authenticated user. Management key required.

Example Usage

from openrouter import OpenRouter
import os


with OpenRouter(
    http_referer="<value>",
    x_title="<value>",
    api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:

    res = open_router.api_keys.list(include_disabled="false", offset="0")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
http_referer Optional[str] The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
x_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
include_disabled Optional[str] Whether to include disabled API keys in the response false
offset Optional[str] Number of API keys to skip for pagination 0
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

operations.ListResponse

Errors

Error Type Status Code Content Type
errors.UnauthorizedResponseError 401 application/json
errors.TooManyRequestsResponseError 429 application/json
errors.InternalServerResponseError 500 application/json
errors.OpenRouterDefaultError 4XX, 5XX */*

create

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

Example Usage

from openrouter import OpenRouter
import os


with OpenRouter(
    http_referer="<value>",
    x_title="<value>",
    api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:

    res = open_router.api_keys.create(name="My New API Key")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
name str ✔️ Name for the new API key My New API Key
http_referer Optional[str] The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
x_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
limit OptionalNullable[float] Optional spending limit for the API key in USD 50
limit_reset OptionalNullable[operations.CreateKeysLimitReset] 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. monthly
include_byok_in_limit Optional[bool] Whether to include BYOK usage in the limit true
expires_at date Optional ISO 8601 UTC timestamp when the API key should expire. Must be UTC, other timezones will be rejected 2027-12-31T23:59:59Z
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

operations.CreateKeysResponse

Errors

Error Type Status Code Content Type
errors.BadRequestResponseError 400 application/json
errors.UnauthorizedResponseError 401 application/json
errors.TooManyRequestsResponseError 429 application/json
errors.InternalServerResponseError 500 application/json
errors.OpenRouterDefaultError 4XX, 5XX */*

update

Update an existing API key. Management key required.

Example Usage

from openrouter import OpenRouter
import os


with OpenRouter(
    http_referer="<value>",
    x_title="<value>",
    api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:

    res = open_router.api_keys.update(hash="f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
hash str ✔️ The hash identifier of the API key to update f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943
http_referer Optional[str] The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
x_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
name Optional[str] New name for the API key Updated API Key Name
disabled Optional[bool] Whether to disable the API key false
limit OptionalNullable[float] New spending limit for the API key in USD 75
limit_reset OptionalNullable[operations.UpdateKeysLimitReset] New limit reset type for the API key (daily, weekly, monthly, or null for no reset). Resets happen automatically at midnight UTC, and weeks are Monday through Sunday. daily
include_byok_in_limit Optional[bool] Whether to include BYOK usage in the limit true
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

operations.UpdateKeysResponse

Errors

Error Type Status Code Content Type
errors.BadRequestResponseError 400 application/json
errors.UnauthorizedResponseError 401 application/json
errors.NotFoundResponseError 404 application/json
errors.TooManyRequestsResponseError 429 application/json
errors.InternalServerResponseError 500 application/json
errors.OpenRouterDefaultError 4XX, 5XX */*

delete

Delete an existing API key. Management key required.

Example Usage

from openrouter import OpenRouter
import os


with OpenRouter(
    http_referer="<value>",
    x_title="<value>",
    api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:

    res = open_router.api_keys.delete(hash="f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
hash str ✔️ The hash identifier of the API key to delete f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943
http_referer Optional[str] The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
x_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

operations.DeleteKeysResponse

Errors

Error Type Status Code Content Type
errors.UnauthorizedResponseError 401 application/json
errors.NotFoundResponseError 404 application/json
errors.TooManyRequestsResponseError 429 application/json
errors.InternalServerResponseError 500 application/json
errors.OpenRouterDefaultError 4XX, 5XX */*

get

Get a single API key by hash. Management key required.

Example Usage

from openrouter import OpenRouter
import os


with OpenRouter(
    http_referer="<value>",
    x_title="<value>",
    api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:

    res = open_router.api_keys.get(hash="f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
hash str ✔️ The hash identifier of the API key to retrieve f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943
http_referer Optional[str] The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
x_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

operations.GetKeyResponse

Errors

Error Type Status Code Content Type
errors.UnauthorizedResponseError 401 application/json
errors.NotFoundResponseError 404 application/json
errors.TooManyRequestsResponseError 429 application/json
errors.InternalServerResponseError 500 application/json
errors.OpenRouterDefaultError 4XX, 5XX */*

get_current_key_metadata

Get information on the API key associated with the current authentication session

Example Usage

from openrouter import OpenRouter
import os


with OpenRouter(
    http_referer="<value>",
    x_title="<value>",
    api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:

    res = open_router.api_keys.get_current_key_metadata()

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
http_referer Optional[str] The app identifier should be your app's URL and is used as the primary identifier for rankings.
This is used to track API usage per application.
x_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

operations.GetCurrentKeyResponse

Errors

Error Type Status Code Content Type
errors.UnauthorizedResponseError 401 application/json
errors.InternalServerResponseError 500 application/json
errors.OpenRouterDefaultError 4XX, 5XX */*