Observability for Cohere with Opik
Cohere provides state-of-the-art large language models that excel at text generation, summarization, classification, and retrieval-augmented generation.
Wrap your Cohere client with track_cohere and every chat() and chat_stream() call is logged to Opik with its messages, response, model and token usage. The async client works out of the box.
Cohere’s native API is not OpenAI-shaped — chat() takes keyword-only arguments and streaming is a separate chat_stream() method returning a union of events — so if your code uses the Cohere SDK, use track_cohere rather than track_openai against the compatibility endpoint.
Account Setup
Comet provides a hosted version of the Opik platform, simply create an account and grab your API Key.
You can also run the Opik platform locally, see the installation guide for more information.
Getting Started
Installation
Configuring Opik
Run opik configure and follow the prompts. See the Python SDK Configuration guide for other options, such as configuring Opik in code or with environment variables.
Configuring Cohere
Set your Cohere API key as an environment variable:
Logging LLM calls
Create a Cohere client, wrap it with track_cohere, and use it as usual:
Advanced Usage
Using with the @track decorator
Calls made with a tracked client inside a function decorated with @track are nested under that function’s trace:
Streaming
Cohere streams through a separate chat_stream() method. The span is ended once the stream is fully consumed, and the events are aggregated into a single logged response:
Async client
track_cohere works with cohere.AsyncClientV2 as well, for both chat() and chat_stream():
Cost Tracking
Opik records the token usage Cohere returns on each call. Cohere reports tokens.input_tokens and tokens.output_tokens, which the integration maps onto Opik’s prompt_tokens / completion_tokens names.
Supported Methods
track_cohere logs chat() and chat_stream() on both cohere.ClientV2 and cohere.AsyncClientV2. Other methods, such as embed() and rerank(), aren’t logged; to trace them, call them inside a function decorated with @track.
Using Cohere through the OpenAI compatibility API
If your code calls Cohere through the OpenAI SDK against Cohere’s compatibility endpoint, keep that code and use track_openai as described below.
Getting started with the compatibility API
Configuring Opik
To start tracking your Cohere LLM calls, you’ll need to have both opik and openai packages installed. You can install them using pip:
In addition, you can configure Opik using the opik configure command which will prompt you for the correct local server address or if you are using the Cloud platform your API key:
Configuring Cohere
You’ll need to set your Cohere API key as an environment variable:
Tracking Cohere API calls through the compatibility API
Leverage the OpenAI Compatibility API by replacing the base URL with Cohere’s endpoint when initializing the client:
The track_openai will automatically track and log the API call, including the input prompt, model used, and response generated. You can view these logs in your Opik project dashboard.

Using the compatibility API within a tracked function
If you are using Cohere within a function tracked with the @track decorator, you can use the tracked client as normal:

Supported Cohere models
The track_openai wrapper with Cohere’s compatibility API supports the following Cohere models:
command-r7b-12-2024- Command R 7B modelcommand-r-plus- Command R Plus modelcommand-r- Command R modelcommand-light- Command Light modelcommand- Command model
Supported OpenAI methods
The track_openai wrapper supports the following OpenAI methods when used with Cohere:
client.chat.completions.create(), including support for stream=True modeclient.beta.chat.completions.parse()client.beta.chat.completions.stream()client.responses.create()
If you would like to track another OpenAI method, please let us know by opening an issue on GitHub.