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 BatchesClient

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

Overview

The BatchesClient and AsyncBatchesClient classes provide a high-level interface for managing batch operations in the Cohere API, wrapping the underlying RawBatchesClient to return deserialized response objects instead of raw HTTP responses.

Description

This file is auto-generated by Fern from the Cohere API definition. It contains two classes:

  • BatchesClient -- The synchronous high-level client for batch operations. Wraps RawBatchesClient and exposes methods for listing, creating, retrieving, and canceling batches. Each method delegates to the corresponding raw client method and extracts the .data attribute from the HttpResponse wrapper, returning only the typed response object.
  • AsyncBatchesClient -- The asynchronous counterpart that wraps AsyncRawBatchesClient and provides the same methods as async coroutines.

Both classes expose a with_raw_response property that gives access to the underlying raw client for cases where the caller needs the full HTTP response (status code, headers, etc.) in addition to the parsed data.

The batch operations interact with the Cohere v2/batches API endpoint and support creating batches from uploaded datasets, retrieving batch status, listing batches with pagination, and canceling in-progress batches.

Usage

Use BatchesClient when you need to perform batch inference operations through the Cohere API. It is accessed as a sub-client via client.batches on a cohere.Client instance and is not typically instantiated directly.

Code Reference

Source Location

Signature

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

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

    def list(
        self,
        *,
        page_size: typing.Optional[int] = None,
        page_token: typing.Optional[str] = None,
        order_by: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ListBatchesResponse: ...

    def create(
        self,
        *,
        request: Batch,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateBatchResponse: ...

    def retrieve(
        self,
        id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetBatchResponse: ...

    def cancel(
        self,
        id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CancelBatchResponse: ...


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

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

    async def list(...) -> ListBatchesResponse: ...
    async def create(...) -> CreateBatchResponse: ...
    async def retrieve(...) -> GetBatchResponse: ...
    async def cancel(...) -> CancelBatchResponse: ...

Import

from cohere.batches.client import BatchesClient, AsyncBatchesClient

I/O Contract

Inputs

list()

Name Type Required Description
page_size typing.Optional[int] No Maximum number of batches to return. Default is 50; maximum is 1000. Values above 1000 are coerced to 1000.
page_token typing.Optional[str] No A page token received from a previous ListBatches call. Used for pagination.
order_by typing.Optional[str] No Ordering field. Use created_at for creation time or updated_at for last updated time.
request_options typing.Optional[RequestOptions] No Request-specific configuration (timeouts, headers, etc.).

create()

Name Type Required Description
request Batch Yes The batch definition object containing name, input_dataset_id, and model.
request_options typing.Optional[RequestOptions] No Request-specific configuration.

retrieve()

Name Type Required Description
id str Yes The batch ID to retrieve.
request_options typing.Optional[RequestOptions] No Request-specific configuration.

cancel()

Name Type Required Description
id str Yes The batch ID to cancel.
request_options typing.Optional[RequestOptions] No Request-specific configuration.

Outputs

Method Type Description
list() ListBatchesResponse A response containing a list of batch objects for the current user.
create() CreateBatchResponse A response confirming the batch was created and execution started.
retrieve() GetBatchResponse A response containing the details of the requested batch.
cancel() CancelBatchResponse A response confirming the batch was canceled.

Usage Examples

from cohere import Client
from cohere.batches import Batch

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

# List batches with pagination
response = client.batches.list(
    page_size=10,
    page_token="page_token",
    order_by="created_at",
)

# Create a new batch
create_response = client.batches.create(
    request=Batch(
        name="my-batch-job",
        input_dataset_id="input_dataset_id",
        model="command",
    ),
)

# Retrieve a specific batch
batch = client.batches.retrieve(id="batch-id-123")

# Cancel an in-progress batch
cancel_response = client.batches.cancel(id="batch-id-123")

# Access raw HTTP response when needed
raw_response = client.batches.with_raw_response.list(page_size=5)
print(raw_response.status_code)
print(raw_response.data)

Related Pages

Page Connections

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