Cohere
Auto-instrument the Cohere V2 SDK. Every ClientV2.chat call inside an active run emits an llm_call event with billed token counts, model, and latency. Cost is computed server-side from the rate card.
Install / enable
Python:
pip install "agentping-sdk[cohere]"
import agentping
import cohere
agentping.init()
agentping.instrument_cohere()
client = cohere.ClientV2()
with agentping.run("rfp-classifier") as r:
reply = client.chat(
model="command-r-plus-08-2024",
messages=[{"role": "user", "content": "classify this RFP"}],
)
r.score("confidence", 0.86)
instrument_cohere() patches ClientV2.chat, AsyncClientV2.chat, the streaming variant, and embed. Idempotent; safe to call once at module load. Supports cohere >= 5.0.0.
TypeScript:
npm install @agentping/sdk cohere-ai
import * as agentping from "@agentping/sdk";
import { CohereClientV2 } from "cohere-ai";
agentping.init({ apiKey: process.env.AGENTPING_API_KEY });
const run = agentping.run("rfp-classifier");
const cohere = agentping.instrumentCohere(
new CohereClientV2({ token: process.env.COHERE_API_KEY }),
{ run },
);
const reply = await cohere.chat({
model: "command-r-plus-08-2024",
messages: [{ role: "user", content: "classify" }],
});
await run.finish({ status: "success" });
instrumentCohere returns a wrapped client whose return types match the original.
What's captured
Model, input tokens, output tokens, and latency on every chat. Token counts come from usage.billed_units, which matches the Cohere invoice rather than the raw tokens block. Embedding calls (embed) are auto-captured too, recorded as kind: "embedding" with their own rate-card pricing. RAG and tool use keep the same usage shape; record tool selection separately for trace clarity:
if reply.message.tool_calls:
for call in reply.message.tool_calls:
r.event("tool_call", {"tool": call.function.name, "args": call.function.arguments})
Streaming
Automatic. chat_stream is wrapped: events pass through untouched and one llm_call fires when the stream drains, reading billed_units from the terminal message-end event. No manual handling needed.
Source / notes
- Python:
agentping.instrument_cohere()in agentping-sdk-python - TypeScript:
instrumentCoherein agentping-sdk-typescript
The rate card covers Command-R, Command-R+, Command Light, and the Embed v3 family. Self-hosted Cohere via the on-prem container is unpriced by design; add an override for your deployment.