Skip to main content

Cohere builds enterprise-grade large language models for chat, search, and retrieval-augmented generation. The Cohere Python client can be instrumented using the openinference-instrumentation-cohere package.

Install#

The instrumentor requires cohere >= 5.13.0.

Setup#

Set the CO_API_KEY environment variable to authenticate calls made using the client.

Connect your application to Phoenix with the register function, then enable the CohereInstrumentor:

Run Cohere#

Observe#

Now that you have tracing setup, all chat calls made with the Cohere v2 client will be streamed to your running Phoenix for observability and evaluation. Spans capture the input messages, output message, invocation parameters, tool definitions and tool calls, and token counts from Cohere’s usage.tokens.

Coverage#

The instrumentor traces the Cohere v2 client (cohere.ClientV2 and cohere.AsyncClientV2), covering both the chat and chat_stream methods. Streamed calls finish their span when the returned iterator is exhausted, with the accumulated output message, tool calls, and token counts.

The following are not traced and produce no spans:

  • The v1 client (cohere.Client)
  • The embed, rerank, and classify endpoints

Resources#