Implementation:Cohere ai Cohere python RequestOptions
| Knowledge Sources | |
|---|---|
| Domains | SDK, Configuration |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Defines a TypedDict for per-request configuration options that override default client settings.
Description
The RequestOptions class is a TypedDict (with total=False) that provides a structured way to pass request-specific configuration to any Cohere SDK method call. It supports overriding the timeout, maximum retry count, and injecting additional HTTP headers, query parameters, and body parameters on a per-call basis. It also includes a chunk_size field for controlling the chunk size used when streaming file downloads.
Usage
Pass a RequestOptions dictionary as the optional last argument to any SDK service function when you need to customize behavior for a specific request. For example, use it to increase the timeout for a long-running operation or to add a custom tracing header to a single call.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/core/request_options.py
Signature
class RequestOptions(typing.TypedDict, total=False):
timeout_in_seconds: NotRequired[int]
max_retries: NotRequired[int]
additional_headers: NotRequired[typing.Dict[str, typing.Any]]
additional_query_parameters: NotRequired[typing.Dict[str, typing.Any]]
additional_body_parameters: NotRequired[typing.Dict[str, typing.Any]]
chunk_size: NotRequired[int]
Import
from cohere.core.request_options import RequestOptions
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| timeout_in_seconds | int | No | The number of seconds to await an API call before timing out. Overrides the client-level default. |
| max_retries | int | No | The maximum number of retries to attempt if the API call fails. Overrides the client-level default. |
| additional_headers | Dict[str, Any] | No | Additional HTTP headers to merge into the request's header dictionary. |
| additional_query_parameters | Dict[str, Any] | No | Additional query parameters to merge into the request's query string. |
| additional_body_parameters | Dict[str, Any] | No | Additional parameters to merge into the request's JSON body. |
| chunk_size | int | No | The size in bytes for each chunk when streaming response data (used for file downloads). |
Outputs
| Name | Type | Description |
|---|---|---|
| N/A | N/A | RequestOptions is a TypedDict used as input configuration; it does not produce outputs itself. |
Usage Examples
import cohere
from cohere.core.request_options import RequestOptions
client = cohere.Client(api_key="your-api-key")
# Override timeout and add a custom header for a single request
response = client.v2.chat(
model="command-r-plus",
messages=[{"role": "user", "content": "Summarize this document."}],
request_options=RequestOptions(
timeout_in_seconds=120,
max_retries=5,
additional_headers={"X-Custom-Trace-Id": "abc-123"},
),
)
# Use chunk_size for streaming file downloads
response = client.v2.chat(
model="command-r-plus",
messages=[{"role": "user", "content": "Hello"}],
request_options=RequestOptions(chunk_size=4096),
)