Skip to main content

OpenInference Cohere Instrumentation

pypi

Python auto-instrumentation library for the Cohere Python client.

Chat calls made with the Cohere v2 client (ClientV2 and AsyncClientV2) are traced and exported as OpenInference LLM spans, capturing the input messages, output message, invocation parameters, tool calls, and token counts.

Coverage

ClientV2.chat, AsyncClientV2.chat, ClientV2.chat_stream, and AsyncClientV2.chat_stream are instrumented. 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 calls to them produce no spans:

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

Installation

pip install openinference-instrumentation-cohere

Quickstart

Install packages needed for this demonstration.

pip install openinference-instrumentation-cohere cohere arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp

Start Phoenix in the background as a collector. By default, it listens on http://localhost:6006.

phoenix serve

Set up CohereInstrumentor to trace your application and send the traces to Phoenix.

from openinference.instrumentation.cohere import CohereInstrumentor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor

endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))

CohereInstrumentor().instrument(tracer_provider=tracer_provider)

Run a chat request. Set the CO_API_KEY environment variable with your Cohere API key.

import cohere

co = cohere.ClientV2()
response = co.chat(
    model="command-a-03-2025",
    messages=[{"role": "user", "content": "Why is the sky blue?"}],
)
print(response.message.content[0].text)

More Info

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openinference_instrumentation_cohere-0.1.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file openinference_instrumentation_cohere-0.1.1.tar.gz.

File metadata

File hashes

Hashes for openinference_instrumentation_cohere-0.1.1.tar.gz
Algorithm Hash digest
SHA256 164264fbb79a5d1350f260107dee09ac423fe52ddbf187b1eac530c51229d63b
MD5 c26b46d1a446a902f28f8bf8137562d9
BLAKE2b-256 d00b59d26210026d35c716cb6052343f69ffdc173fa7f07524fb6156f12c71d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for openinference_instrumentation_cohere-0.1.1.tar.gz:

Publisher: publish.yaml on Arize-ai/openinference

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openinference_instrumentation_cohere-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for openinference_instrumentation_cohere-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 237705cf5cf52796926b38aa436519ec0eb2a0ea3d5c1417b2d23e093ba2659c
MD5 c890460804dfef765b602ef5389d7121
BLAKE2b-256 f6fabf7d0941c64ffa158f16a7e091994ba23a24bbc6a4369c3b992533bb16cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for openinference_instrumentation_cohere-0.1.1-py3-none-any.whl:

Publisher: publish.yaml on Arize-ai/openinference

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page