Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Cohere ai Cohere python ModelsClient

From Leeroopedia
Knowledge Sources
Domains SDK, API_Client
Last Updated 2026-02-15 14:00 GMT

Overview

ModelsClient is a high-level client for retrieving Cohere model information, providing get() and list() methods that return deserialized response objects.

Description

The ModelsClient class provides a user-friendly interface for querying the Cohere Models API. It wraps the lower-level RawModelsClient and extracts the .data attribute from raw HTTP responses, returning clean typed response objects directly.

The module defines two client classes:

  • ModelsClient -- Synchronous client using SyncClientWrapper. Provides get(model) to fetch a single model by name and list(...) to retrieve a paginated list of available models with optional filtering.
  • AsyncModelsClient -- Asynchronous counterpart using AsyncClientWrapper. Provides the same get and list methods as async coroutines.

Both classes expose a with_raw_response property that returns the underlying RawModelsClient (or AsyncRawModelsClient) for callers who need access to the full HTTP response including headers and status codes.

Usage

Use ModelsClient (or AsyncModelsClient) when you need to query available Cohere models or retrieve details about a specific model. This is the recommended client for model information retrieval -- prefer it over RawModelsClient unless you need raw HTTP response details.

Code Reference

Source Location

Signature

class ModelsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper): ...

    @property
    def with_raw_response(self) -> RawModelsClient: ...

    def get(
        self,
        model: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetModelResponse: ...

    def list(
        self,
        *,
        page_size: typing.Optional[float] = None,
        page_token: typing.Optional[str] = None,
        endpoint: typing.Optional[CompatibleEndpoint] = None,
        default_only: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListModelsResponse: ...


class AsyncModelsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper): ...

    @property
    def with_raw_response(self) -> AsyncRawModelsClient: ...

    async def get(
        self,
        model: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetModelResponse: ...

    async def list(
        self,
        *,
        page_size: typing.Optional[float] = None,
        page_token: typing.Optional[str] = None,
        endpoint: typing.Optional[CompatibleEndpoint] = None,
        default_only: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListModelsResponse: ...

Import

from cohere.models.client import ModelsClient, AsyncModelsClient

I/O Contract

Inputs

Name Type Required Description
model (get) str Yes The name of the model to retrieve (e.g., "command-a-03-2025").
page_size (list) Optional[float] No Maximum number of models per page. Defaults to 20, min 1, max 1000.
page_token (list) Optional[str] No Page token from a previous response's next_page_token field for pagination.
endpoint (list) Optional[CompatibleEndpoint] No Filter models to only those compatible with this endpoint (e.g., "chat").
default_only (list) Optional[bool] No When True, filters to only the default model for the specified endpoint. Only valid when endpoint is provided.
request_options Optional[RequestOptions] No Request-specific configuration such as custom headers or timeouts.

Outputs

Name Type Description
get() return GetModelResponse Details of the requested model including name, endpoints, context length, finetuned status, and tokenizer URL.
list() return ListModelsResponse A paginated list of available models with a next_page_token for continuation.
with_raw_response RawModelsClient / AsyncRawModelsClient The underlying raw client that returns full HttpResponse objects with headers and status codes.

Usage Examples

from cohere import Client

client = Client(
    client_name="YOUR_CLIENT_NAME",
    token="YOUR_TOKEN",
)

# Get details for a specific model
model_info = client.models.get(model="command-a-03-2025")
print(model_info.name)

# List available models with filtering
models_response = client.models.list(
    page_size=10,
    endpoint="chat",
    default_only=True,
)
for model in models_response.models:
    print(model.name)

# Access raw HTTP response when needed
raw_response = client.models.with_raw_response.get(model="command-a-03-2025")
print(raw_response.response.status_code)
print(raw_response.data.name)

# Async usage
import asyncio
from cohere import AsyncClient

async def main():
    async_client = AsyncClient(
        client_name="YOUR_CLIENT_NAME",
        token="YOUR_TOKEN",
    )
    model_info = await async_client.models.get(model="command-a-03-2025")
    print(model_info.name)

asyncio.run(main())

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment