AnthropicClient
Category: LLM Providers
Source: anthropic_client.dart
Classes
AnthropicClient
LLM client for the Anthropic Messages API with streaming.
Prompt caching: when [promptCacheEnabled] is true (default), the request body includes a top-level cache_control: {type: "ephemeral"} directive. Anthropic's auto-caching advances the cache breakpoint to the last cacheable block on each turn, so a growing conversation accumulates cache hits without the client tracking breakpoint placement explicitly. Caching is GA on Claude 4.x — no beta header needed. Older models silently ignore the directive.
Constructor
dart
AnthropicClient({
required this.apiKey,
required this.model,
required this.systemPrompt,
String baseUrl = _defaultBaseUrl,
http.Client Function()? requestClientFactory,
this.promptCacheEnabled = true,
})Properties
| Property | Type | Description |
|---|---|---|
apiKey | String | |
model | String | |
systemPrompt | String | |
promptCacheEnabled | bool | |
id | ToolCallId | |
name | String | |
buffer | StringBuffer |
Methods
Stream<LlmChunk> stream(List<Message> messages, {List<Tool>? tools})
`static Stream<LlmChunk> parseStreamEvents(
Stream<Map<String, dynamic>> events,
)`
Parse Anthropic SSE event payloads into [LlmChunk]s.
Exposed as static for testability (can feed synthetic events).