Anthropic (Claude)
FlowKit supports Anthropic's Claude models via the AnthropicAdapter.
Setup
bash
export ANTHROPIC_API_KEY=sk-ant-...Usage
typescript
import { AnthropicAdapter } from "@andresaya/flowkit";
const adapter = new AnthropicAdapter({
apiKey: process.env.ANTHROPIC_API_KEY!,
model: "claude-3-5-sonnet-20241022",
});
const engine = new FlowEngine(flow, { llm: adapter, storage });Configuration
typescript
interface AnthropicConfig {
/** Anthropic API key (required) */
apiKey: string;
/** Model to use (default: claude-3-5-sonnet-20241022) */
model?: string;
/** Max tokens (default: 4096) */
maxTokens?: number;
/** Temperature (default: 0) */
temperature?: number;
/** Timeout in ms (default: 60000) */
timeout?: number;
/** Base URL (default: https://api.anthropic.com) */
baseUrl?: string;
/** Enable streaming (default: false) */
streaming?: boolean;
}Available Models
| Model | Best For | Cost |
|---|---|---|
claude-3-5-sonnet-20241022 | Best balance (recommended) | $$ |
claude-3-5-haiku-20241022 | Fast and cheap | $ |
claude-3-opus-20240229 | Most capable | $$$ |
Streaming
Enable streaming for real-time responses:
typescript
const adapter = new AnthropicAdapter({
apiKey: process.env.ANTHROPIC_API_KEY!,
model: "claude-3-5-sonnet-20241022",
streaming: true,
});Example
typescript
import {
agent, flow, FlowEngine, MemoryStorage, AnthropicAdapter,
name, yesNo
} from "@andresaya/flowkit";
const bot = agent("Alex")
.company("MyCompany")
.personality("helpful and thoughtful")
.build();
const myFlow = flow("greeting", bot)
.ask("name", "What's your name?", name(), "user_name")
.then("confirm")
.ask("confirm", "Nice to meet you {{user_name}}! Need help?", yesNo(), "needs_help")
.when({ yes: "help", no: "bye" })
.say("help", "How can I help?")
.done()
.say("bye", "Goodbye!")
.done()
.build();
const engine = new FlowEngine(myFlow, {
llm: new AnthropicAdapter({
apiKey: process.env.ANTHROPIC_API_KEY!,
model: "claude-3-5-sonnet-20241022",
}),
storage: new MemoryStorage(),
});
const result = await engine.start("session-1");
console.log(result.message);Features
| Feature | Supported |
|---|---|
| Streaming | Yes |
| Tool Calling | Yes |
| JSON Mode | Yes |
Tips
- Use Sonnet for most use cases - Best balance of speed and quality
- Claude is excellent for reasoning - Great for complex conversation flows
- Enable streaming - Better user experience with real-time responses
- Set temperature to 0 - For deterministic responses