AnthropicClient class

A client for communicating with Anthropic's Claude API.

Implements LlmClient to integrate seamlessly with the Vantura framework. Supports both the standard Messages API (non-streaming) and the Server-Sent Events (SSE) streaming format.

Implemented types

Constructors

AnthropicClient({required String apiKey, String model = 'claude-3-5-sonnet-latest', String baseUrl = 'https://api.anthropic.com/v1/messages', String apiVersion = '2023-06-01', int maxTokens = 4096, double? temperature, void onRetry(int attempt, Duration nextDelay, dynamic error)?, Client? httpClient})
Creates an AnthropicClient.

Properties

apiKey → String
API key for authentication.
final
apiVersion → String
Anthropic API version header.
final
baseUrl → String
Base URL for Anthropic API.
final
hashCode → int
The hash code for this object.
no setterinherited
maxTokens → int
Default maximum tokens to sample.
final
model → String
Default model to use for requests.
final
onRetry → void Function(int attempt, Duration nextDelay, dynamic error)?
Callback emitted when a request is about to be retried.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
temperature → double?
Default temperature for responses.
final

Methods

close() → void
Closes the client and cleans up any resources.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sendChatRequest(List<Map<String, dynamic>> messages, List<Map<String, dynamic>>? tools, {double? temperature, int? maxCompletionTokens, double? topP, bool? stream, String? reasoningEffort, dynamic stop, CancellationToken? cancellationToken}) → Future<Map<String, dynamic>>
Sends a single, complete chat request to the LLM.
override
sendStreamingChatRequest(List<Map<String, dynamic>> messages, List<Map<String, dynamic>>? tools, {double? temperature, int? maxCompletionTokens, double? topP, String? reasoningEffort, dynamic stop, CancellationToken? cancellationToken}) → Stream<Map<String, dynamic>>
Sends a streaming chat request using Anthropic's SSE protocol.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited