Skip to content

Cohere

Cohere provides cutting-edge language models. These are accessible through OpenAI’s SDK via the Compatibility API. This allows easy and portable integration with the Strands Agents SDK using the familiar OpenAI interface.

The Strands Agents SDK provides access to Cohere models through the OpenAI compatibility layer, configured as an optional dependency. To install, run:

Terminal window
pip install 'strands-agents[openai]' strands-agents-tools

After installing the openai package, you can import and initialize the Strands Agents’ OpenAI-compatible provider for Cohere models as follows:

from strands import Agent
from strands.models.openai import OpenAIModel
from strands_tools import calculator
model = OpenAIModel(
client_args={
"api_key": "<COHERE_API_KEY>",
"base_url": "https://api.cohere.ai/compatibility/v1", # Cohere compatibility endpoint
},
model_id="command-a-03-2025", # or see https://docs.cohere.com/docs/models
params={
"stream_options": None
}
)
agent = Agent(model=model, tools=[calculator])
agent("What is 2+2?")

The client_args configure the underlying OpenAI-compatible client. When using Cohere, you must set:

  • api_key: Your Cohere API key. Get one from the Cohere Dashboard.
  • base_url:
    • https://api.cohere.ai/compatibility/v1

Refer to OpenAI Python SDK GitHub for full client options.

The model_config specifies which Cohere model to use and any additional parameters.

ParameterDescriptionExampleOptions
model_idModel namecommand-r-plusSee Cohere docs
paramsModel-specific parameters{"max_tokens": 1000, "temperature": 0.7}API reference

ModuleNotFoundError: No module named 'openai'

Section titled “ModuleNotFoundError: No module named 'openai'”

You must install the openai dependency to use this provider:

Terminal window
pip install 'strands-agents[openai]'

Ensure you’re using a model ID compatible with Cohere’s Compatibility API (e.g., command-r-plus, command-a-03-2025, embed-v4.0), and your base_url is set to https://api.cohere.ai/compatibility/v1.