Skip to main content
Cohere provides chat, embeddings, reranking, and audio transcription models. Braintrust traces Cohere SDK calls, including streaming chat and tool calls.

Setup

Install the Braintrust and cohere-ai packages, then set your API keys. Requires cohere-ai v7.0.0 or later, including both the v7 request shape and the current v8 SDK.
1

Install packages

2

Set environment variables

.env

Auto-instrumentation

To trace Cohere SDK calls without modifying your application code, initialize Braintrust normally, then run your app with Braintrust’s import hook to patch the Cohere SDK at runtime.
1

Initialize Braintrust and call Cohere

2

Run with the import hook

The auto-instrumentation example uses plain JavaScript so node --import can run the file directly. The Braintrust APIs work the same in TypeScript projects — compile your TypeScript to JavaScript, then run the compiled file with the import hook.
If you’re using a bundler, see Trace LLM calls for plugin and loader setup.

Manual instrumentation

To trace Cohere clients manually, wrap them yourself with wrapCohere(). Use this when you want to instrument specific clients individually rather than all of them globally.

What Braintrust traces

Braintrust patches the cohere-ai SDK and creates an LLM-typed span per call:
  • Chat completion spans (cohere.chat and cohere.chatStream), with messages and request parameters as input; chat output (including aggregated tool calls for streaming) and token usage; first-token timing for streaming.
  • Extended thinking content for reasoning models, captured from streaming cohere.chatStream responses as structured thinking content blocks in the span output.
  • Embedding spans (cohere.embed), with input texts and request parameters; output summarized as the first embedding’s vector length.
  • Rerank spans (cohere.rerank), with query and documents as input; results as a list of {index, relevance_score} items.
  • Token usage metrics (prompt, completion, total, plus cached prompt tokens and reasoning tokens when reported).
  • Request metadata (model and selected request parameters) and response metadata (response ID, finish reason, generation ID, response type, and Cohere API version when present).
  • Errors captured on every call.

Resources