Anthropic adapter
@receipta/anthropic wraps the @anthropic-ai/sdk (v0.30+, including current v0.110) so every Messages API call emits a receipt.
How it works
Same no-fork pattern as the OpenAI adapter — both SDKs share the fetchWithTimeout lineage (verified firsthand). The only provider-specific differences:
- the request id header is
request-id(Anthropic) vsx-request-id(OpenAI), - usage is
input_tokens/output_tokens(Anthropic) vsprompt_tokens/completion_tokens, - the response carries
stop_reasonvsfinish_reason.
The fetch layer is the version-stable single integration point.
Usage
ts
import Anthropic from '@anthropic-ai/sdk';
import { withReceipts } from '@receipta/anthropic';
import { openStore, generateKeyPair } from '@receipta/core';
const store = await openStore('./receipts.log.receipta');
const signer = generateKeyPair();
const client = withReceipts(
Anthropic,
{ apiKey: process.env.ANTHROPIC_API_KEY! },
{
store,
signer,
actor: { type: 'service', id: 'my-app' },
},
);
const res = await client.messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello' }],
});What gets captured
provider:"anthropic"model: from the response bodyusage:input_tokens/output_tokensrequest_id: therequest-idheaderattempt_index: best-effort, sourced from the Stainless SDK'sx-stainless-retry-countrequest header (0on the first attempt, incrementing on retry); omitted when the header is absentoutcome:successfor 2xx,errorotherwisecontent: the request + response bodies (whencaptureMode: "full")