ClaudeChatProvider class

AIChatProvider implementation for the Anthropic Claude Messages API.

Supported config keys:

  • apiKey (required): Anthropic API key (format: "sk-ant-...")
  • model (optional): model name (default: "claude-haiku-4-5-20251001")
  • anthropicVersion (optional): API version header (default: "2023-06-01")

ChatRole.system messages are extracted from the conversation list and forwarded as the top-level "system" field required by the Anthropic API. Multiple system messages are joined with newlines.

Example:

final provider = ClaudeChatProvider();
await provider.initialize({'apiKey': 'sk-ant-...'});

final response = await provider.sendChatMessages([
  ChatMessage.system('You are a Dart expert.'),
  ChatMessage.user('What is a mixin?'),
]);
print(response.message.content);

await provider.dispose();
Inheritance

Constructors

ClaudeChatProvider()

Properties

hashCode → int
The hash code for this object.
no setterinherited
isInitialized → bool
Whether the provider has been initialised and is ready for use.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkInitialized() → void
Throws StateError if the provider has been disposed or not yet initialised.
inherited
dispose() → Future<void>
Releases all resources held by this provider (HTTP connections, etc.).
override
initialize(Map<String, dynamic> config) → Future<void>
Initialises the provider with provider-specific config.
override
mapHttpError(int statusCode, String body) → AIChatException
Converts an HTTP statusCode and response body into the appropriate AIChatException subclass.
inherited
markAsDisposed() → void
Marks the provider as disposed. Call at the start of dispose.
inherited
markAsInitialized() → void
Marks the provider as ready. Call at the end of initialize.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sendChatMessages(List<ChatMessage> messages, {Map<String, dynamic>? parameters}) → Future<ChatResponse>
Sends a complete list of messages and returns the model's reply.
override
sendMessage(String message, {List<ChatMessage>? history, Map<String, dynamic>? parameters}) → Future<ChatResponse>
Sends a single message and returns the model's reply.
override
sendMessageStream(String message, {List<ChatMessage>? history, Map<String, dynamic>? parameters}) → Stream<String>
Sends a message and streams response tokens as they are generated.
override
toString() → String
A string representation of this object.
inherited
withRetry<T>(Future<T> fn(), {int maxAttempts = 3}) → Future<T>
Retries fn up to maxAttempts times with exponential back-off.
inherited

Operators

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