Skip to main content
Cohere provides chat, embeddings, and reranking models. Braintrust instruments the native Cohere Python SDK so you can inspect prompts, responses, streaming behavior, embeddings, and rerank calls in Braintrust.

Setup

1

Install packages

# uv
uv add braintrust cohere
# pip
pip install braintrust cohere
2

Set environment variables

BRAINTRUST_API_KEY=<your-braintrust-api-key>
CO_API_KEY=<your-cohere-api-key>

Auto-instrumentation

To automatically trace Cohere SDK calls, call braintrust.auto_instrument() before creating your Cohere client.
import os

import braintrust

braintrust.auto_instrument()
braintrust.init_logger(
    api_key=os.environ["BRAINTRUST_API_KEY"],
    project="cohere-example",  # Replace with your project name
)

import cohere

client = cohere.ClientV2(os.environ["CO_API_KEY"])
response = client.chat(
    model="command-r-plus",
    messages=[{"role": "user", "content": "Explain tracing in one sentence."}],
)

print(response.message.content[0].text)
The integration silently no-ops if the cohere package is not installed.

Manual instrumentation

To trace specific Cohere clients individually (rather than all of them globally), use wrap_cohere().
import os

from braintrust import init_logger
from braintrust.integrations.cohere import wrap_cohere
import cohere

init_logger(
    api_key=os.environ["BRAINTRUST_API_KEY"],
    project="cohere-example",  # Replace with your project name
)

client = wrap_cohere(cohere.ClientV2(os.environ["CO_API_KEY"]))
response = client.chat(
    model="command-r-plus",
    messages=[{"role": "user", "content": "Explain tracing in one sentence."}],
)

print(response.message.content[0].text)

Resources