@agentrewind/codec-anthropic
v0.1.4
Published
Anthropic Messages API codec for AgentRewind.
Maintainers
Readme
@agentrewind/codec-anthropic
Anthropic Messages API codec for AgentRewind.
Use this package when your agent calls the Anthropic TypeScript SDK through the Messages API.
Install
Most users get this codec through the SDK:
npm install @agentrewind/sdkUse this package directly only when a library needs granular dependency boundaries.
Supported Client Shape
The codec wraps:
client.messages.create(request)client.messages.stream(request)
Recording
import { AgentRewind, Anthropic, anthropicCodec, assertProviderClient, defineHarness } from "@agentrewind/sdk";
import type { AnthropicMessage, AnthropicRawMessageStreamEvent } from "@agentrewind/sdk";
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY
});
const codec = anthropicCodec();
assertProviderClient(client, codec);
const harness = defineHarness(async (ctx) => {
const message = await ctx.model.create<AnthropicMessage>(
{
model: "claude-opus-4-8",
max_tokens: 256,
system: "Answer with operational detail.",
messages: [{ role: "user", content: `Request ${ctx.uuid()}` }]
},
{ site: "draft-answer" }
);
return message.content;
});
const recorded = await AgentRewind.recordRun(
{
id: "anthropic-demo",
store: ".rewind",
model: client,
codec
},
harness
);Replay
Strict replay needs no live model client:
const replayed = await AgentRewind.replayRun(
recorded.path,
{ codec: anthropicCodec() },
harness
);Streaming
ctx.model.stream() calls client.messages.stream() under the hood:
assertProviderClient(client, codec, ["stream"]);await session.run(async (ctx) => {
for await (const event of ctx.model.stream<AnthropicRawMessageStreamEvent>(
{
model: "claude-opus-4-8",
max_tokens: 256,
messages: [{ role: "user", content: "Stream one sentence." }]
},
{ site: "stream-answer" }
)) {
console.log(event.type);
}
});Notes
metadatais treated as volatile and stripped from strict request fingerprints.- Anthropic input token usage includes regular, cache creation, and cache read input tokens.
- The codec preserves raw responses in the normalized response for local replay fidelity.
- This package targets Anthropic Messages. It does not wrap transport-level
fetch.
