Skip to content

fix: resolve CO_API_URL when clients are constructed - #819

Draft
Kayvan-Zahiri wants to merge 1 commit into
cohere-ai:mainfrom
Kayvan-Zahiri:codex/resolve-base-url-at-construction
Draft

Kayvan-Zahiri wants to merge 1 commit into
cohere-ai:mainfrom
Kayvan-Zahiri:codex/resolve-base-url-at-construction

Conversation

@Kayvan-Zahiri

@Kayvan-Zahiri Kayvan-Zahiri commented Oct 20, 2026 •

Copy link
Copy Markdown

Problem

CO_API_URL is evaluated in constructor default arguments when the modules are imported. Setting it after import cohere (for example while loading application configuration) or changing it before constructing another client does not affect the default endpoint. All four public client classes exhibit this behavior.

Change

Resolve CO_API_URL at construction time in the handwritten V1 clients and let the V2 constructors delegate that resolution. Explicit non-None base URLs retain precedence, and removing the environment variable restores the normal production endpoint. The existing URL normalization remains in place.

Only .fernignore-protected client modules and a new test file change; generated endpoints and models are untouched. Imports in the changed modules were cleaned up to satisfy Ruff.

Validation

  • 8 public sync/async V1/V2 regression cases with captured models.list() requests. Each checks runtime environment changes, removal and explicit override behavior.4 failed and 4 passed before; all 8 pass after. No live requests or credentials.
  • Offline client-init, auth, dataset, embedding, overrides and cloud-wrapper test modules: 79 passed, 28 skipped, 9 warnings. AWS/OCI extras are absent; live API modules were excluded.
  • Poetry-prescribed Mypy 1.13 passes all 362 source files.
  • Changed-file Ruff 0.11.5 lint and new-test formatting pass. Full-repository lint has 58 findings (59 in an untouched baseline); every final finding also exists in the baseline. Full formatting reports 32 pre-existing files in both trees. Unrelated files were left untouched.
  • Poetry wheel/source distribution build and whitespace check pass. Lockfile unchanged.

All checks used the repository Poetry environment. Final 8 regressions were rerun after import cleanup.

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.

1 participant