Adapters
Anthropic Adapter
The Anthropic adapter translates Tekimax's unified interface to Anthropic's Messages API. Under the hood it uses the official @anthropic-ai/sdk package.
Installation
Code
npm install tekimax-tsUsage
Code
import { Tekimax, AnthropicProvider } from 'tekimax-ts';
const client = new Tekimax({
provider: new AnthropicProvider({
apiKey: process.env.ANTHROPIC_API_KEY!,
})
});
const result = await client.text.chat.completions.create({
model: 'claude-3-5-sonnet-20240620',
messages: [{ role: 'user', content: 'Hello Claude' }]
});
console.log(result.message.content);Streaming
Code
const stream = client.text.chat.completions.createStream({
model: 'claude-3-5-sonnet-20240620',
messages: [{ role: 'user', content: 'Tell me a story' }]
});
for await (const chunk of stream) {
process.stdout.write(chunk.delta);
}Tool Calling
Tool calling works identically to OpenAI — the adapter handles the translation to Anthropic's tool_use content blocks behind the scenes.
Code
const result = await client.text.chat.completions.create({
model: 'claude-3-5-sonnet-20240620',
messages: [{ role: 'user', content: 'What is the weather in Paris?' }],
tools: [{
type: 'function',
function: {
name: 'get_weather',
description: 'Get current weather for a location',
parameters: {
type: 'object',
properties: { location: { type: 'string' } },
required: ['location']
}
}
}]
});
// Normalized to the same shape as every other provider.
console.log(result.message.toolCalls);Vision (Image Analysis)
Code
const analysis = await client.images.analyze({
model: 'claude-3-5-sonnet-20240620',
image: 'https://example.com/photo.jpg', // URL or Base64 data URI
prompt: 'Describe what you see in this image.'
});
console.log(analysis.content);Notes
- System Prompts: Anthropic's Messages API requires
systemas a top-level parameter, not a message role. The adapter automatically extracts any{ role: 'system' }messages from your array and passes them to thesystemfield — so you can use the same message format as every other provider. - Max Tokens: Anthropic requires a
max_tokensvalue on every request. The adapter defaults to1024if you don't setmaxTokens, so you don't need to remember this requirement. - Tool Result Mapping: Anthropic expects tool results as a
usermessage withtool_resultcontent blocks, not as arole: 'tool'message. The adapter handles this conversion automatically.
