@galdor/provider-anthropic
v0.3.1
Published
Anthropic (Claude Messages API) provider adapter for galdor-bun.
Readme
@galdor/provider-anthropic
The Anthropic (Claude Messages API) provider
adapter for galdor. Implements the core
Provider interface, so it drops into any graph, agent, or council.
Covers generate + streaming, tool calling, structured output, vision, extended
thinking (including signature round-trips and redacted thinking), prompt caching,
the typed error taxonomy with Retry-After, cancellation, and a stream-safe
header timeout (60 s default).
Install
bun add @galdor/provider-anthropic # or: npm install @galdor/provider-anthropicUsage
import { newAnthropic } from "@galdor/provider-anthropic";
import { userMessage, messageText } from "@galdor/core/schema";
const provider = newAnthropic({
apiKey: process.env.ANTHROPIC_API_KEY!,
// baseURL: "https://api.anthropic.com", // optional override
// timeoutMs: 60_000, // header timeout; 0 disables
});
// One-shot
const res = await provider.generate({
model: "claude-haiku-4-5",
messages: [userMessage("Explain MCP in one sentence.")],
});
console.log(messageText(res.message), res.usage);
// Streaming
for await (const ev of provider.stream({ model: "claude-haiku-4-5", messages: [userMessage("Count to 3.")] })) {
// ev is a provider Event (content deltas, tool calls, message stop, …)
}Pass tools, toolChoice, responseFormat, reasoning, and message
cacheControl on the request; unsupported features surface as a typed
UnsupportedError rather than being silently dropped.
License
Apache-2.0
