Overview
The RawBatchesClient and AsyncRawBatchesClient classes provide the low-level HTTP client for batch operations against the Cohere v2/batches API endpoint, returning typed HttpResponse wrappers that include both the parsed data and raw HTTP response metadata.
Description
This file is auto-generated by Fern from the Cohere API definition. It contains two classes:
RawBatchesClient -- The synchronous low-level client that directly issues HTTP requests to the Cohere batch API. Each method constructs the HTTP request using the underlying SyncClientWrapper, sends it via httpx, parses the JSON response into typed models using construct_type, and returns an HttpResponse[T] wrapper. Error responses are mapped to specific exception types based on HTTP status code.
AsyncRawBatchesClient -- The asynchronous counterpart that wraps AsyncClientWrapper and provides the same methods as async coroutines, returning AsyncHttpResponse[T].
The raw client handles the following HTTP error mappings:
- 400 --
BadRequestError
- 401 --
UnauthorizedError
- 403 --
ForbiddenError
- 404 --
NotFoundError
- 500 --
InternalServerError
- 503 --
ServiceUnavailableError
For any other non-2xx status code, a generic ApiError is raised.
Usage
The raw client is typically not used directly by end users. Instead, it is wrapped by BatchesClient which extracts the .data attribute for convenience. Use the raw client directly when you need access to HTTP response metadata such as status codes and headers, accessible via client.batches.with_raw_response.
Code Reference
Source Location
Signature
class RawBatchesClient:
def __init__(self, *, client_wrapper: SyncClientWrapper): ...
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,
) -> HttpResponse[ListBatchesResponse]: ...
def create(
self,
*,
request: Batch,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[CreateBatchResponse]: ...
def retrieve(
self,
id: str,
*,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[GetBatchResponse]: ...
def cancel(
self,
id: str,
*,
request_options: typing.Optional[RequestOptions] = None,
) -> HttpResponse[CancelBatchResponse]: ...
class AsyncRawBatchesClient:
def __init__(self, *, client_wrapper: AsyncClientWrapper): ...
async def list(...) -> AsyncHttpResponse[ListBatchesResponse]: ...
async def create(...) -> AsyncHttpResponse[CreateBatchResponse]: ...
async def retrieve(...) -> AsyncHttpResponse[GetBatchResponse]: ...
async def cancel(...) -> AsyncHttpResponse[CancelBatchResponse]: ...
Import
from cohere.batches.raw_client import RawBatchesClient, AsyncRawBatchesClient
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. Serialized to JSON via convert_and_respect_annotation_metadata.
|
| request_options |
typing.Optional[RequestOptions] |
No |
Request-specific configuration.
|
retrieve()
| Name |
Type |
Required |
Description
|
| id |
str |
Yes |
The batch ID. Encoded into the URL path as v2/batches/{id}.
|
| request_options |
typing.Optional[RequestOptions] |
No |
Request-specific configuration.
|
cancel()
| Name |
Type |
Required |
Description
|
| id |
str |
Yes |
The batch ID. Encoded into the URL path as v2/batches/{id}/cancel.
|
| request_options |
typing.Optional[RequestOptions] |
No |
Request-specific configuration.
|
Outputs
| Method |
Type |
Description
|
list() |
HttpResponse[ListBatchesResponse] |
HTTP response wrapper containing parsed ListBatchesResponse data and raw response metadata.
|
create() |
HttpResponse[CreateBatchResponse] |
HTTP response wrapper containing parsed CreateBatchResponse data and raw response metadata.
|
retrieve() |
HttpResponse[GetBatchResponse] |
HTTP response wrapper containing parsed GetBatchResponse data and raw response metadata.
|
cancel() |
HttpResponse[CancelBatchResponse] |
HTTP response wrapper containing parsed CancelBatchResponse data and raw response metadata.
|
HTTP Endpoints
| Method |
HTTP Verb |
Endpoint
|
list() |
GET |
v2/batches
|
create() |
POST |
v2/batches
|
retrieve() |
GET |
v2/batches/{id}
|
cancel() |
POST |
v2/batches/{id}/cancel
|
Error Handling
| HTTP Status |
Exception Class
|
| 400 |
BadRequestError
|
| 401 |
UnauthorizedError
|
| 403 |
ForbiddenError
|
| 404 |
NotFoundError
|
| 500 |
InternalServerError
|
| 503 |
ServiceUnavailableError
|
| Other non-2xx |
ApiError
|
Usage Examples
from cohere import Client
client = Client(
client_name="YOUR_CLIENT_NAME",
token="YOUR_TOKEN",
)
# Access the raw client via the with_raw_response property
raw_response = client.batches.with_raw_response.list(page_size=10)
# Access HTTP metadata
print(raw_response.status_code)
print(raw_response.headers)
# Access the parsed data
batches_data = raw_response.data
print(batches_data)
Related Pages