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 ModelsRawClient

From Leeroopedia
Revision as of 12:17, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Cohere_ai_Cohere_python_ModelsRawClient.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains SDK, API_Client
Last Updated 2026-02-15 14:00 GMT

Overview

RawModelsClient is a low-level HTTP client for Cohere model information retrieval that returns full HttpResponse objects including headers and status codes.

Description

The RawModelsClient class provides direct HTTP access to the Cohere Models API endpoints, returning HttpResponse[T] wrapper objects that include both the deserialized data and the raw HTTP response metadata (status code, headers). This is the underlying transport layer used by the higher-level ModelsClient.

The module defines two client classes:

  • RawModelsClient -- Synchronous client using SyncClientWrapper and httpx. Sends HTTP GET requests to v1/models/{model} (for get) and v1/models (for list).
  • AsyncRawModelsClient -- Asynchronous counterpart using AsyncClientWrapper. Provides the same methods as async coroutines returning AsyncHttpResponse[T].

Both clients implement comprehensive error handling, mapping HTTP status codes to specific exception types:

Status Code Exception
400 BadRequestError
401 UnauthorizedError
403 ForbiddenError
404 NotFoundError
422 UnprocessableEntityError
429 TooManyRequestsError
498 InvalidTokenError
499 ClientClosedRequestError
500 InternalServerError
501 NotImplementedError
503 ServiceUnavailableError
504 GatewayTimeoutError
Other ApiError

Response deserialization uses construct_type from UncheckedBaseModel for efficient object construction without full Pydantic validation.

Usage

Use RawModelsClient when you need access to the full HTTP response metadata (headers, status codes) alongside the deserialized response data. For most use cases, prefer the higher-level ModelsClient which returns only the deserialized data. Access the raw client via ModelsClient.with_raw_response.

Code Reference

Source Location

Signature

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

    def get(
        self,
        model: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[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,
    ) -> HttpResponse[ListModelsResponse]: ...


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

    async def get(
        self,
        model: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[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,
    ) -> AsyncHttpResponse[ListModelsResponse]: ...

Import

from cohere.models.raw_client import RawModelsClient, AsyncRawModelsClient

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 HttpResponse[GetModelResponse] Wrapper containing the raw HTTP response and the deserialized GetModelResponse data.
list() return HttpResponse[ListModelsResponse] Wrapper containing the raw HTTP response and the deserialized ListModelsResponse data.
get() return (async) AsyncHttpResponse[GetModelResponse] Async wrapper containing the raw HTTP response and the deserialized GetModelResponse data.
list() return (async) AsyncHttpResponse[ListModelsResponse] Async wrapper containing the raw HTTP response and the deserialized ListModelsResponse data.

Usage Examples

from cohere import Client

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

# Access the raw client via the high-level client
raw_client = client.models.with_raw_response

# Get model details with full HTTP response metadata
response = raw_client.get(model="command-a-03-2025")
print(response.response.status_code)   # 200
print(response.response.headers)       # HTTP headers dict
print(response.data.name)              # "command-a-03-2025"

# List models with pagination and endpoint filtering
response = raw_client.list(
    page_size=10,
    endpoint="chat",
    default_only=True,
)
print(response.response.status_code)  # 200
for model in response.data.models:
    print(model.name)

# Async usage
import asyncio
from cohere import AsyncClient

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

asyncio.run(main())

Related Pages

Page Connections

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