Models - Python SDK

Models method reference

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

(models)

Overview

Model information endpoints

Available Operations

  • count - Get total count of available models
  • list - List all models and their properties
  • list_for_user - List models filtered by user provider preferences, privacy settings, and guardrails

count

Get total count of available models

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 api_key=os.getenv("OPENROUTER_API_KEY", ""),
6) as open_router:
7
8 res = open_router.models.count()
9
10 # Handle response
11 print(res)

Parameters

ParameterTypeRequiredDescription
retriesOptional[utils.RetryConfig]Configuration to override the default retry behavior of the client.

Response

components.ModelsCountResponse

Errors

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

list

List all models and their properties

Example Usage

1from openrouter import OpenRouter
2import os
3
4with OpenRouter(
5 api_key=os.getenv("OPENROUTER_API_KEY", ""),
6) as open_router:
7
8 res = open_router.models.list()
9
10 # Handle response
11 print(res)

Parameters

ParameterTypeRequiredDescriptionExample
categoryOptional[operations.Category]Filter models by use case categoryprogramming
supported_parametersOptional[str]N/A
retriesOptional[utils.RetryConfig]Configuration to override the default retry behavior of the client.

Response

components.ModelsListResponse

Errors

Error TypeStatus CodeContent Type
errors.BadRequestResponseError400application/json
errors.InternalServerResponseError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*

list_for_user

List models filtered by user provider preferences, privacy settings, and guardrails. If requesting through eu.openrouter.ai/api/v1/... the results will be filtered to models that satisfy EU in-region routing.

Example Usage

1from openrouter import OpenRouter, operations
2import os
3
4with OpenRouter() as open_router:
5
6 res = open_router.models.list_for_user(security=operations.ListModelsUserSecurity(
7 bearer=os.getenv("OPENROUTER_BEARER", ""),
8 ))
9
10 # Handle response
11 print(res)

Parameters

ParameterTypeRequiredDescription
securityoperations.ListModelsUserSecurity✔️The security requirements to use for the request.
retriesOptional[utils.RetryConfig]Configuration to override the default retry behavior of the client.

Response

components.ModelsListResponse

Errors

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