Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions docs/user-guide/concepts/model-providers/cohere.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Cohere

[Cohere](https://cohere.com) provides cutting-edge language models. These are accessible 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.

## Installation

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

```bash
pip install 'strands-agents[openai]'
```

## Usage

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

```python
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?")
```

## Configuration

### Client Configuration

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](https://dashboard.cohere.com).
* `base_url`:
* `https://api.cohere.ai/compatibility/v1`

Refer to [OpenAI Python SDK GitHub](https://github.com/openai/openai-python) for full client options.

### Model Configuration

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

| Parameter | Description | Example | Options |
| ---------- | ------------------------- | ------------------------------------------ | ------------------------------------------------------------------ |
| `model_id` | Model name | `command-r-plus` | See [Cohere docs](https://docs.cohere.com/docs/models) |
| `params` | Model-specific parameters | `{"max_tokens": 1000, "temperature": 0.7}` | [API reference](https://docs.cohere.com/docs/compatibility-api) |

## Troubleshooting

### `ModuleNotFoundError: No module named 'openai'`

You must install the `openai` dependency to use this provider:

```bash
pip install 'strands-agents[openai]'
```

### Unexpected model behavior?

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`.

## References

* [Cohere Docs: Using the OpenAI SDK](https://docs.cohere.com/docs/compatibility-api)
* [Cohere API Reference](https://docs.cohere.com/reference)
* [OpenAI Python SDK](https://github.com/openai/openai-python)
* [Strands Agents API](../../../api-reference/models.md)
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ nav:
- LlamaAPI: user-guide/concepts/model-providers/llamaapi.md
- Ollama: user-guide/concepts/model-providers/ollama.md
- OpenAI: user-guide/concepts/model-providers/openai.md
- Cohere: user-guide/concepts/model-providers/cohere.md
- Custom Providers: user-guide/concepts/model-providers/custom_model_provider.md
- Streaming:
- Async Iterators: user-guide/concepts/streaming/async-iterators.md
Expand Down