Skip to content

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

Merged
fern-support merged 2 commits into
mainfrom
fern-support/max-retries-constructor
Jun 29, 2026
Merged

feat(client): forward max_retries through Client/ClientV2 constructors#779
fern-support merged 2 commits 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
Backward-compatible constructor wiring with unchanged defaults; only affects HTTP retry policy configuration.

Overview
Adds optional max_retries on Client, AsyncClient, ClientV2, and AsyncClientV2, forwarding it into the base client so retry behavior can be set once at construction (e.g. max_retries=0 to disable SDK retries). Omitting it keeps the existing default of 2; per-request request_options still override.

Also bumps the package to 7.0.5 and updates SDK version strings in request headers.

Reviewed by Cursor Bugbot for commit 8fa3618. 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).
@fern-support fern-support enabled auto-merge (squash) June 29, 2026 16:15
@fern-support fern-support merged commit 41f344b into main Jun 29, 2026
4 checks passed
@fern-support fern-support deleted the fern-support/max-retries-constructor branch June 29, 2026 17:53
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.

3 participants