Module: Apipurse
- Defined in:
- lib/apipurse/wrap_openai.rb,
lib/apipurse.rb,
lib/apipurse/wrap_anthropic.rb
Overview
Apipurse::WrapAnthropic.call(client, apipurse) — automatic, zero-call-site
cost tracking for the official anthropic Ruby gem. Same design as
Apipurse::WrapOpenAI — see wrap_openai.rb for the full "this is not a
proxy" explanation, which applies identically here.
Usage:
client = Anthropic::Client.new
apipurse = Apipurse::Client.new(
ingest_token: ENV["APIPURSE_INGEST_TOKEN"],
provider_id: ENV["APIPURSE_PROVIDER_ID"],
base_url: "https://your-apipurse-domain.com"
)
Apipurse::WrapAnthropic.call(client, apipurse)
= client..create(
model: "claude-sonnet-4-20250514",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello" }]
)
Streaming: unlike OpenAI, Anthropic's stream always carries token counts in
its message_start and message_delta events — no extra request flag
needed.
Defined Under Namespace
Modules: WrapAnthropic, WrapOpenAI Classes: Client, TrackCompletionResult