For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://modelgates.ai/docs/_mcp/server.

APIKeys - Python SDK

The Python SDK and docs are currently in beta. Report issues on GitHub.

Overview

API key management endpoints

Available Operations

get_current_key_metadata

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

Example Usage

python
from modelgates import ModelGatesimport os with ModelGates(    http_referer="<value>",    x_open_router_title="<value>",    x_open_router_categories="<value>",    api_key=os.getenv("MODELGATES_API_KEY", ""),) as open_router:     res = open_router.api_keys.get_current_key_metadata()     # Handle response    print(res)

Parameters

ParameterTypeRequiredDescription
http_refererOptional[str]:heavy_minus_sign: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_titleOptional[str]:heavy_minus_sign:The app display name allows you to customize how your app appears in ModelGates's dashboard.
x_open_router_categoriesOptional[str]:heavy_minus_sign:Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
retriesOptional[utils.RetryConfig]:heavy_minus_sign:Configuration to override the default retry behavior of the client.

Response

operations.GetCurrentKeyResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.InternalServerResponseError500application/json
errors.ModelGatesDefaultError4XX, 5XX*/*

list

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

Example Usage

python
from modelgates import ModelGatesimport os with ModelGates(    http_referer="<value>",    x_open_router_title="<value>",    x_open_router_categories="<value>",    api_key=os.getenv("MODELGATES_API_KEY", ""),) as open_router:     res = open_router.api_keys.list()     # Handle response    print(res)

Parameters

ParameterTypeRequiredDescriptionExample
http_refererOptional[str]:heavy_minus_sign: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_titleOptional[str]:heavy_minus_sign:The app display name allows you to customize how your app appears in ModelGates's dashboard.
x_open_router_categoriesOptional[str]:heavy_minus_sign:Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
include_disabledOptional[bool]:heavy_minus_sign:Whether to include disabled API keys in the responsefalse
offsetOptional[int]:heavy_minus_sign:Number of API keys to skip for pagination0
workspace_idOptional[str]:heavy_minus_sign:Filter API keys by workspace ID. By default, keys in the default workspace are returned.0df9e665-d932-5740-b2c7-b52af166bc11
retriesOptional[utils.RetryConfig]:heavy_minus_sign:Configuration to override the default retry behavior of the client.

Response

operations.ListResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.TooManyRequestsResponseError429application/json
errors.InternalServerResponseError500application/json
errors.ModelGatesDefaultError4XX, 5XX*/*

create

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

Example Usage

python
from modelgates import ModelGatesfrom modelgates.utils import parse_datetimeimport os with ModelGates(    http_referer="<value>",    x_open_router_title="<value>",    x_open_router_categories="<value>",    api_key=os.getenv("MODELGATES_API_KEY", ""),) as open_router:     res = open_router.api_keys.create(name="My New API Key", expires_at=parse_datetime("2027-12-31T23:59:59Z"), include_byok_in_limit=True, limit=50, limit_reset="monthly")     # Handle response    print(res)

Parameters

ParameterTypeRequiredDescriptionExample
namestr:heavy_check_mark:Name for the new API keyMy New API Key
http_refererOptional[str]:heavy_minus_sign: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_titleOptional[str]:heavy_minus_sign:The app display name allows you to customize how your app appears in ModelGates's dashboard.
x_open_router_categoriesOptional[str]:heavy_minus_sign:Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
creator_user_idOptionalNullable[str]:heavy_minus_sign:Optional user ID of the key creator. Only meaningful for organization-owned keys where a specific member is creating the key.user_2dHFtVWx2n56w6HkM0000000000
expires_atdate:heavy_minus_sign:Optional ISO 8601 UTC timestamp when the API key should expire. Must be UTC, other timezones will be rejected2027-12-31T23:59:59Z
include_byok_in_limitOptional[bool]:heavy_minus_sign:Whether to include BYOK usage in the limittrue
limitOptionalNullable[float]:heavy_minus_sign:Optional spending limit for the API key in USD50
limit_resetOptionalNullable[operations.CreateKeysLimitReset]:heavy_minus_sign: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
workspace_idOptional[str]:heavy_minus_sign:The workspace to create the API key in. Defaults to the default workspace if not provided.0df9e665-d932-5740-b2c7-b52af166bc11
retriesOptional[utils.RetryConfig]:heavy_minus_sign:Configuration to override the default retry behavior of the client.

Response

operations.CreateKeysResponse

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.ForbiddenResponseError403application/json
errors.TooManyRequestsResponseError429application/json
errors.InternalServerResponseError500application/json
errors.ModelGatesDefaultError4XX, 5XX*/*

delete

Delete an existing API key. Management key required.

Example Usage

python
from modelgates import ModelGatesimport os with ModelGates(    http_referer="<value>",    x_open_router_title="<value>",    x_open_router_categories="<value>",    api_key=os.getenv("MODELGATES_API_KEY", ""),) as open_router:     res = open_router.api_keys.delete(hash="f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943")     # Handle response    print(res)

Parameters

ParameterTypeRequiredDescriptionExample
hashstr:heavy_check_mark:The hash identifier of the API key to deletef01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943
http_refererOptional[str]:heavy_minus_sign: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_titleOptional[str]:heavy_minus_sign:The app display name allows you to customize how your app appears in ModelGates's dashboard.
x_open_router_categoriesOptional[str]:heavy_minus_sign:Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
retriesOptional[utils.RetryConfig]:heavy_minus_sign:Configuration to override the default retry behavior of the client.

Response

operations.DeleteKeysResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.TooManyRequestsResponseError429application/json
errors.InternalServerResponseError500application/json
errors.ModelGatesDefaultError4XX, 5XX*/*

get

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

Example Usage

python
from modelgates import ModelGatesimport os with ModelGates(    http_referer="<value>",    x_open_router_title="<value>",    x_open_router_categories="<value>",    api_key=os.getenv("MODELGATES_API_KEY", ""),) as open_router:     res = open_router.api_keys.get(hash="f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943")     # Handle response    print(res)

Parameters

ParameterTypeRequiredDescriptionExample
hashstr:heavy_check_mark:The hash identifier of the API key to retrievef01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943
http_refererOptional[str]:heavy_minus_sign: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_titleOptional[str]:heavy_minus_sign:The app display name allows you to customize how your app appears in ModelGates's dashboard.
x_open_router_categoriesOptional[str]:heavy_minus_sign:Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
retriesOptional[utils.RetryConfig]:heavy_minus_sign:Configuration to override the default retry behavior of the client.

Response

operations.GetKeyResponse

Errors

Error TypeStatus CodeContent Type
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.TooManyRequestsResponseError429application/json
errors.InternalServerResponseError500application/json
errors.ModelGatesDefaultError4XX, 5XX*/*

update

Update an existing API key. Management key required.

Example Usage

python
from modelgates import ModelGatesimport os with ModelGates(    http_referer="<value>",    x_open_router_title="<value>",    x_open_router_categories="<value>",    api_key=os.getenv("MODELGATES_API_KEY", ""),) as open_router:     res = open_router.api_keys.update(hash="f01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943", disabled=False, include_byok_in_limit=True, limit=75, limit_reset="daily", name="Updated API Key Name")     # Handle response    print(res)

Parameters

ParameterTypeRequiredDescriptionExample
hashstr:heavy_check_mark:The hash identifier of the API key to updatef01d52606dc8f0a8303a7b5cc3fa07109c2e346cec7c0a16b40de462992ce943
http_refererOptional[str]:heavy_minus_sign: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_titleOptional[str]:heavy_minus_sign:The app display name allows you to customize how your app appears in ModelGates's dashboard.
x_open_router_categoriesOptional[str]:heavy_minus_sign:Comma-separated list of app categories (e.g. "cli-agent,cloud-agent"). Used for marketplace rankings.
disabledOptional[bool]:heavy_minus_sign:Whether to disable the API keyfalse
include_byok_in_limitOptional[bool]:heavy_minus_sign:Whether to include BYOK usage in the limittrue
limitOptionalNullable[float]:heavy_minus_sign:New spending limit for the API key in USD75
limit_resetOptionalNullable[operations.UpdateKeysLimitReset]:heavy_minus_sign: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
nameOptional[str]:heavy_minus_sign:New name for the API keyUpdated API Key Name
retriesOptional[utils.RetryConfig]:heavy_minus_sign:Configuration to override the default retry behavior of the client.

Response

operations.UpdateKeysResponse

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.UnauthorizedResponseError401application/json
errors.NotFoundResponseError404application/json
errors.TooManyRequestsResponseError429application/json
errors.InternalServerResponseError500application/json
errors.ModelGatesDefaultError4XX, 5XX*/*