Cohere Wrapper
Wrap your Cohere client to automatically trace every chat() call with model, input, output, token usage, and cost.
Installation
pip install twosignal[cohere]Usage
from twosignal import TwoSignal
from twosignal.wrappers.cohere import wrap_cohere
import cohere
ts = TwoSignal()
client = wrap_cohere(cohere.ClientV2(api_key="your-key"))
response = client.chat(
model="command-r-plus",
messages=[{"role": "user", "content": "Hello"}],
)What Gets Captured
| Field | Description |
|---|---|
model | Model name (e.g., command-r-plus) |
input | Input messages |
output | Response content |
usage.prompt_tokens | Input token count |
usage.completion_tokens | Output token count |
cost | Estimated cost in USD |
V1 and V2 Clients
The wrapper works with both Cohere v1 (Client) and v2 (ClientV2) clients, as well as their async variants (AsyncClient, AsyncClientV2).
# v1 client
client = wrap_cohere(cohere.Client(api_key="your-key"))
response = client.chat(
model="command-r",
message="Hello",
chat_history=[],
)