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

PyPI package: 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.2.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.2.tar.gz.

File metadata

File hashes

Hashes for openinference_instrumentation_cohere-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6dd953170960b629519002e96b3af655ad5a94e0f14809504a8b4fbd9c545cff
MD5 52a9c1afe17a3b4410433b0f2f4fdaba
BLAKE2b-256 dc12ca2fafab46e83943b94c45c290c4def449fe381575d354b35cbcd3c30bee

See more details on using hashes here.

Provenance

The following attestation bundles were made for openinference_instrumentation_cohere-0.1.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for openinference_instrumentation_cohere-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 87a527299ebd0daf812cce441e91dc369d2e90d9cb5f13a613aa9f9bac53a432
MD5 6027ae5d9c6766df2542dc1564f7ff3e
BLAKE2b-256 98c318e493b69fb09904b874939d677459ad28dcdd4d12fe7c31a3d64b90ba25

See more details on using hashes here.

Provenance

The following attestation bundles were made for openinference_instrumentation_cohere-0.1.2-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