Skip to content

feat(client): forward max_retries through Client/ClientV2 constructors#779

Open
fern-support wants to merge 1 commit into
mainfrom
fern-support/max-retries-constructor
Open

feat(client): forward max_retries through Client/ClientV2 constructors#779
fern-support wants to merge 1 commit into
mainfrom
fern-support/max-retries-constructor

Conversation

@fern-support

@fern-support fern-support commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Makes max_retries configurable from the client constructors. Requested by Cohere (handle retries centrally outside the SDK; the default of 2 made that hard to enforce).

The base BaseCohere / AsyncBaseCohere constructors already accept max_retries, but the hand-maintained override constructors in client.py / client_v2.py never forwarded it — so max_retries could only be set per-request via request_options, not at the client level. (These files are .fernignore'd, so fern generate never touches them; this had to be a manual edit.)

Changes

Thread max_retries: typing.Optional[int] = None through all four override constructors, forwarding to the respective super().__init__:

  • ClientBaseCohere
  • AsyncClientAsyncBaseCohere
  • ClientV2Client
  • AsyncClientV2AsyncClient

The None default preserves existing behavior: the base client applies its own default of 2. Per-request max_retries in request_options continues to take precedence.

Usage

import cohere

client = cohere.AsyncClientV2(api_key="...", max_retries=0)  # disable SDK-level retries

Verification

  • inspect.signature(...).parameters contains max_retries for Client, AsyncClient, ClientV2, AsyncClientV2.
  • Instantiating each with max_retries=0 stores 0 on the client wrapper; instantiating without it stores the base default of 2.
  • Confirmed timeout is still forwarded for all four (regression guard).
  • mypy src/cohere/client.py src/cohere/client_v2.py — clean.
  • Offline unit tests pass (test_client_init, test_overrides, test_embed_utils, test_embed_streaming).

Note

Low Risk
Constructor-only plumbing with None preserving prior defaults; no change to retry logic itself.

Overview
Adds optional max_retries to Client, AsyncClient, ClientV2, and AsyncClientV2 so callers can set SDK-level retry behavior at construction (e.g. max_retries=0 to disable the default of 2).

The hand-maintained overrides in client.py and client_v2.py now accept max_retries: typing.Optional[int] = None and pass it through to BaseCohere / AsyncBaseCohere (and V2 wrappers delegate via Client / AsyncClient). Omitting the argument keeps the existing base default; per-request request_options max_retries still overrides the client default.

Reviewed by Cursor Bugbot for commit df151d6. Bugbot is set up for automated code reviews on this repo. Configure here.

The base BaseCohere/AsyncBaseCohere constructors accept `max_retries`,
but the hand-maintained Client, AsyncClient, ClientV2 and AsyncClientV2
override constructors never exposed it, so it could not be set at the
client level (only per-request via request_options).

Thread `max_retries: Optional[int] = None` through all four override
constructors, forwarding to the respective super().__init__. The None
default preserves the existing behavior (base applies its default of 2).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants