Cohere

Auto-instrument the Cohere v2 client (cohere on PyPI, cohere-ai on npm). Every chat, chat_stream and embed call inside an active run emits an llm_call event with model, billed token counts, latency, finish reason, and tool calls. Cost is computed server-side from the rate card.

Only the v2 client (ClientV2 / CohereClientV2) is instrumented. The legacy v1 Client is not touched.

Install / enable

Python:

pip install "agentping-io[cohere]"
import agentping
import cohere

agentping.init()
agentping.instrument_cohere()

client = cohere.ClientV2()

with agentping.run("support-triage", customer_id="acme-corp"):
    reply = client.chat(
        model="command-a-03-2025",
        messages=[{"role": "user", "content": "classify this ticket"}],
    )

instrument_cohere() patches cohere.ClientV2 and cohere.AsyncClientV2. Idempotent and global; call it once at module load. Supported cohere versions: 5.x.

TypeScript:

npm install @agentping/sdk cohere-ai
import { CohereClientV2 } from "cohere-ai";
import * as agentping from "@agentping/sdk";

agentping.init({ apiKey: process.env.AGENTPING_API_KEY });

const run = agentping.run("answer-bot");
const cohere = agentping.instrumentCohere(
  new CohereClientV2({ token: process.env.COHERE_API_KEY }),
  { run },
);

const reply = await cohere.chat({
  model: "command-a-03-2025",
  messages: [{ role: "user", content: "hi" }],
});

await run.finish({ status: "success" });

instrumentCohere returns a wrapped client covering chat, chatStream and embed.

What's captured

Field Source
provider cohere
model The requested model. Cohere's response does not echo it, so the request is the only source.
input_tokens usage.billed_units.input_tokens
output_tokens usage.billed_units.output_tokens
finish_reason finish_reason
tool_calls Number of message.tool_calls
latency_ms Wall-clock time of the call
stream true on chat_stream

Token counts are the billed units, which is what Cohere charges for, rather than the raw tokens block. Cohere reports no cache or reasoning breakdown, so those fields are never set.

embed emits an llm_call with kind: "embedding", the requested model and input_tokens from meta.billed_units. A call that raises is recorded as an llm_call with status: "error", error and exception, then re-raised.

Streaming

Both SDKs capture chat_stream (chatStream in TypeScript). Usage and finish reason arrive on the terminal message-end event; each tool-call-start event counts one tool call. One llm_call with stream: true fires once the stream is fully consumed or closed.

with agentping.run("answer-bot"):
    for event in client.chat_stream(
        model="command-a-03-2025",
        messages=[{"role": "user", "content": "explain briefly"}],
    ):
        if event.type == "content-delta":
            print(event.delta.message.content.text, end="", flush=True)
    # llm_call is emitted here

Prompt capture and time to first token

chat_stream / chatStream calls also report ttft_ms, the time from the request to the first content-start, content-delta, tool-plan-delta or tool-call-* event; message-start does not count. Pulse charts its p95 per agent.

Prompt and completion text are off by default. Turn them on once at init, with an optional cap per piece (default 4000 characters):

agentping.init(capture_llm_content=True, llm_content_max_chars=4000)
agentping.init({ captureLlmContent: true, llmContentMaxChars: 4000 });

Each chat call then carries input (the messages list, system message included, as the API takes it) and output (the text items of message.content). Documents and tool parts appear as markers, and each piece is clipped at the cap. The run page renders them as messages; see events for the wire shape. Embed calls carry no content.

Source / notes

Default rates ship for current Cohere models; the full list is on the LLM API pricing page. A Cohere model that is not on the default card lands with its token counts and appears in the unpriced-models list until you add its per-million rates under Spend, Rate cards; from then on every new call is priced. See Spend.