claude_box 0.1.4
claude_box: ^0.1.4 copied to clipboard
A claude AI provider based on ai_box.
claude_box #
An Anthropic (Claude) provider based on ai_box.
Usage #
import 'package:ai_box/ai_box.dart';
import 'package:claude_box/claude_box.dart';
Future<void> main() async {
final ai = Claude(apiKey: 'sk-ant-...');
// One-shot text generation.
final answer = await ai.generateText(
model: 'claude-sonnet-4-6',
message: 'Say hello in one short sentence.',
);
print(answer);
// Multi-turn chat.
final res = await ai.chat(
model: 'claude-sonnet-4-6',
messages: [
LLMContent.system('You are concise.'),
LLMContent.user('What is the capital of Japan?'),
],
maxTokens: 32,
);
print(res.text);
print(res.usage); // token usage
}
Streaming #
True SSE streaming — text arrives incrementally and the final chunk carries the finish reason and token usage:
await for (final text in ai.generateTextStream(
model: 'claude-sonnet-4-6',
message: 'Write a haiku about Dart.',
)) {
stdout.write(text);
}
Models and key validation #
final models = await ai.getModels();
final ok = await ai.validateKey();
Multimodal input (images, files), tool calling, structured output and the
sealed LLMException error hierarchy are all provided by
ai_box — see its README for details.