Files
openrouter-python-sdk-retry…/docs/sdks/apikeys
OpenRouter SDK Bot 5ab44f08f0 feat: regenerate SDK with updated OpenAPI spec
Speakeasy regeneration with latest schema changes including
type renames and new server tool models.
2026-03-27 15:18:14 -04:00
..

APIKeys

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_open_router_title="<value>",
    x_open_router_categories="<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_open_router_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
x_open_router_categories Optional[str] Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
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_open_router_title="<value>",
    x_open_router_categories="<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_open_router_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
x_open_router_categories Optional[str] Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
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_open_router_title="<value>",
    x_open_router_categories="<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_open_router_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
x_open_router_categories Optional[str] Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
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_open_router_title="<value>",
    x_open_router_categories="<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_open_router_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
x_open_router_categories Optional[str] Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
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_open_router_title="<value>",
    x_open_router_categories="<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_open_router_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
x_open_router_categories Optional[str] Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
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_open_router_title="<value>",
    x_open_router_categories="<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_open_router_title Optional[str] The app display name allows you to customize how your app appears in OpenRouter's dashboard.
x_open_router_categories Optional[str] Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
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 */*