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
-
- Object
- BaseAIChatProvider
- ClaudeChatProvider
Constructors
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
statusCodeand responsebodyinto 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
messagesand returns the model's reply.override -
sendMessage(
String message, {List< ChatMessage> ? history, Map<String, dynamic> ? parameters}) → Future<ChatResponse> -
Sends a single
messageand returns the model's reply.override -
sendMessageStream(
String message, {List< ChatMessage> ? history, Map<String, dynamic> ? parameters}) → Stream<String> -
Sends a
messageand 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
fnup tomaxAttemptstimes with exponential back-off.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited