Registry / llm-agents / langchain-cohere

langchain-cohere

JSON →
library0.6.0pypypi✓ verified 22d ago

langchain-cohere is an integration package that connects Cohere's powerful language AI models (Chat, Embeddings, Rerank) with the LangChain framework. It simplifies the process of building LLM-powered applications using Cohere's capabilities. The library is actively developed, with frequent releases often occurring on a weekly or bi-weekly cadence, and the current version is 0.5.0.

pip install langchain-cohere
INSTALL
IMPORT
SIG · LANGCHAIN-COHERE
L
langchain-cohere
llm-agentspythonv0.6.0
Install
12.5s avg
Import
3307ms
Disk
162MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 3.384s · 133.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 12.5s · import 3.230s · 127MB
162MB installed
● package 162MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ChatCohere
from langchain_cohere import ChatCohere
from langchain_community.chat_models import ChatCohere
Cohere chat model integrations were moved from `langchain_community` to `langchain_cohere`.
CohereEmbeddings
from langchain_cohere import CohereEmbeddings
from langchain.embeddings import CohereEmbeddings
Embeddings integrations were moved from `langchain.embeddings` (and `langchain_community`) to `langchain_cohere`.
CohereRerank
from langchain_cohere import CohereRerank
from langchain.retrievers.document_compressors import CohereRerank
Rerank integrations were moved from `langchain.retrievers.document_compressors` (and `langchain_community`) to `langchain_cohere`.
create_cohere_react_agent
from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent
from langchain_cohere import create_cohere_tools_agent
`create_cohere_tools_agent` was deprecated in v0.3.3 and has been replaced by `create_cohere_react_agent` with a different import path.

This quickstart demonstrates how to initialize the `ChatCohere` model and perform a simple chat completion. It uses the `COHERE_API_KEY` environment variable for authentication and `command-r-plus` as the model, which can be changed to other supported Cohere models.

import os from langchain_cohere import ChatCohere from langchain_core.messages import HumanMessage # Ensure your COHERE_API_KEY is set as an environment variable # or pass it directly to the ChatCohere constructor. # For example: cohere_api_key="your_api_key" llm = ChatCohere( model="command-r-plus", # or another supported Cohere chat model temperature=0, cohere_api_key=os.environ.get('COHERE_API_KEY', '') ) messages = [HumanMessage(content="What is the capital of Canada?")] try: response = llm.invoke(messages) print(response.content) except Exception as e: print(f"An error occurred: {e}") print("Please ensure COHERE_API_KEY is set and the model name is correct.")
Debug
Known issues
breakingThe `create_csv_agent` abstraction was deprecated in v0.3.5 and subsequently removed in v0.4.1. Users relying on this function will need to refactor their code.
fix
Migrate to using `create_csv_agent` from `langchain_experimental.agents.agent_toolkits.csv.base` and manually construct the agent workflow.
affects: >=0.3.5
breakingCohere integrations were moved from `langchain_community` (and other `langchain` paths) to the dedicated `langchain-cohere` package. Direct imports from `langchain_community.chat_models.ChatCohere`, `langchain.embeddings.CohereEmbeddings`, or `langchain.retrievers.document_compressors.CohereRerank` are deprecated and will break in newer `langchain` versions.
fix
Update import statements to use `from langchain_cohere import ...` for all Cohere components. For example, `from langchain_community.chat_models import ChatCohere` should become `from langchain_cohere import ChatCohere`.
affects: >=0.0.30 (for langchain-community deprecation)
breakingThe Cohere Chat and Rerank APIs migrated to v2 starting from v0.4.1. This introduced significant changes to message structure (using a single `messages` parameter with roles), chat history handling, tool definitions (JSON schema), and requires the `model` parameter to be explicitly specified for all calls.
fix
Review Cohere API v2 migration guides for `Chat` and `Rerank` to adapt request formats, message structures, and ensure the `model` parameter is always provided. `CohereRerank` now mandates the `model` parameter.
affects: >=0.4.1
deprecatedThe `create_cohere_tools_agent` and general `connectors` functionality were deprecated in v0.3.3.
fix
Migrate to `create_cohere_react_agent` found at `langchain_cohere.react_multi_hop.agent`. Re-evaluate usage of `connectors` as their functionality may have changed or been replaced by alternative methods within the Cohere API or LangChain.
affects: >=0.3.3
gotchaThe `langchain-cohere` package now manages the compatible `cohere` Python SDK version (v5+). Using an older or incompatible `cohere` SDK version installed separately may lead to unexpected behavior or errors.
fix
Ensure that your installed `cohere` package is version 5 or higher. `pip install --upgrade cohere` may be necessary. It's recommended to let `langchain-cohere` manage this dependency.
affects: *
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'langchain_community.chat_models'
Cohere integrations, including chat models, embeddings, and rerankers, were moved from `langchain_community` to the dedicated `langchain_cohere` package in `langchain-community` version 0.0.30 and later.
fix
Update your import statements to use `from langchain_cohere import ChatCohere` (or `CohereEmbeddings`, `CohereRerank`) instead of importing from `langchain_community`.
CohereAPIError: invalid api token
The Cohere API key provided is either missing, incorrect, expired, or not accessible to the `langchain-cohere` integration, leading to an authentication failure.
fix
Ensure your Cohere API key is correctly set as an environment variable named `COHERE_API_KEY`, or pass it directly to the model constructor using `cohere_api_key='YOUR_API_KEY'`.
UnprocessableEntityError: status_code: 422, body: {'message': 'invalid type: parameter texts is of type object but should be of type string.'}
The Cohere Embeddings API expects a list of strings as input for the `texts` parameter, but it received input that was not correctly formatted, such as a list of objects or a single object.
fix
Verify that the input to `CohereEmbeddings` is a list of strings. If you are extracting text from documents or other structures, ensure it's converted to the correct string format before passing it to the embedding function.
BadRequestError: response_format has an invalid json_schema
When attempting to use structured output or tool calling with Cohere chat models, the JSON schema provided to the model does not meet Cohere's strict validation requirements.
fix
Review the JSON schema definition for your structured output or tool calls to ensure it strictly adheres to Cohere's API documentation for `response_format`, including all required fields and correct data types. Consider simplifying the schema or debugging with manual JSON parsing if issues persist.
NotImplementedError: Provider cohere model does not support chat.
You are attempting to use a Cohere model that is not designed for chat interactions (e.g., a pure completion or embedding model) with a LangChain component or function specifically expecting a chat model, or the specific chat model is not supported by the current integration or provider configuration.
fix
Ensure you are using a Cohere chat model (like `command-r` or `command-r-plus`) when initializing `ChatCohere` and that the LangChain component being used is compatible with chat models. If using a non-chat model, use the appropriate `Cohere` LLM class instead of `ChatCohere`.
Upgrade
Version history
0.6.0latest on PyPI · released Jun 1, 2026
Audit
Dependencies
langchain-corerequiredProvides core abstractions and interfaces for the LangChain ecosystem, enabling seamless integration with other LangChain components. Version 1.0 is supported since langchain-cohere v0.5.0.
cohererequiredThe official Cohere Python SDK, which langchain-cohere uses to interact with Cohere's API. This package manages the Cohere SDK version, supporting v5+.
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
langchain-cohere — pip install langchain-cohere · libregistry