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

FieldDescription
modelModel name (e.g., command-r-plus)
inputInput messages
outputResponse content
usage.prompt_tokensInput token count
usage.completion_tokensOutput token count
costEstimated 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=[],
)

Have questions? Join our community!

Connect with other developers and the 2Signal team.

Join Discord