Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Heuristic:Cohere ai Cohere python Warning Deprecated Legacy Generate API

From Leeroopedia
Knowledge Sources
Domains SDK, Deprecation
Last Updated 2026-02-15 00:00 GMT

Overview

Deprecation warning for the legacy Generate and Summarize APIs which are marked as "Legacy" and will be removed in a future SDK release.

Description

The Cohere Python SDK v5.x marks several APIs as Legacy in `base_client.py` and `raw_base_client.py`:

  • generate() and generate_stream() -- text generation endpoints
  • summarize() -- text summarization endpoint

These methods raise deprecation warnings at runtime advising users to follow the migration guide. The associated response types (Generation, SingleGeneration, GenerateStreamedResponse, SummarizeResponse) remain in the SDK for backward compatibility but should not be used in new code.

Additionally, the Client class deprecated 19+ methods in v5.0.0 (e.g., `check_api_key`, `loglikelihood`, `batch_generate`, `codebook`, `batch_tokenize`, `batch_detokenize`, `detect_language`, `create_cluster_job`), which raise `ValueError` with a removal notice. Several dataset, embed_job, and connector methods were moved to sub-clients (e.g., `create_dataset` moved to `.datasets.create`).

Usage

Be aware of this deprecation when encountering code using the legacy generate, generate_stream, or summarize APIs. Migrate to the V2Client.chat() API for text generation, which provides a unified interface with streaming, tool use, and structured output support.

The Insight (Rule of Thumb)

  • Action: Replace `client.generate(prompt=...)` with `client_v2.chat(model=..., messages=[...])`.
  • Action: Replace `client.summarize(text=...)` with a V2 chat prompt that asks the model to summarize.
  • Value: All legacy generate/summarize parameters have V2 chat equivalents.
  • Trade-off: V2 chat uses a message-based interface rather than a prompt-based one; existing prompt strings need wrapping in `UserChatMessageV2` objects.

Reasoning

The Cohere API is converging on the V2 chat endpoint as the single unified interface for all text generation tasks. The legacy endpoints duplicate functionality and will not receive new features (e.g., tool use, structured output, thinking). The SDK raises runtime warnings to guide migration.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment