Anthropic provider implementation for Stratix AI Agents.

Requires explicit model configuration - no defaults provided. Supports Claude 3 models (Opus, Sonnet, Haiku) with tool use and streaming. Note: Anthropic does not support embeddings.

import { AnthropicProvider } from '@stratix/ai-anthropic';

const provider = new AnthropicProvider({
apiKey: process.env.ANTHROPIC_API_KEY!,
models: [
{ name: 'claude-sonnet-4-5-20250929', pricing: { input: 3.0, output: 15.0 } },
{ name: 'claude-opus-4-5-20251101', pricing: { input: 5.0, output: 25.0 } }
]
});

const response = await provider.chat({
model: 'claude-sonnet-4-5-20250929',
messages: [{ role: 'user', content: 'Hello!', timestamp: new Date() }]
});
const provider = new AnthropicProvider({
apiKey: process.env.ANTHROPIC_API_KEY!,
models: [
{ name: 'claude-sonnet-4-5-20250929', pricing: { input: 3.5, output: 17.5 } },
{ name: 'claude-opus-4-5-20251101', pricing: { input: 25.0, output: 125.0 } }
]
});
const provider = new AnthropicProvider({
apiKey: process.env.ANTHROPIC_API_KEY!,
models: [
{ name: 'claude-sonnet-4-5-20250929' }
]
});
for await (const chunk of provider.streamChat({
model: 'claude-3-5-sonnet-20241022',
messages: [{ role: 'user', content: 'Write a story', timestamp: new Date() }]
})) {
process.stdout.write(chunk.content);
}

Implements

  • LLMProvider

Constructors

Methods

  • Sends a chat completion request

    Parameters

    • params: ChatParams

      Chat parameters

    Returns Promise<ChatResponse>

    The chat completion response

  • Streams a chat completion response

    Parameters

    • params: ChatParams

      Chat parameters

    Returns AsyncIterable<ChatChunk>

    Async iterable of chat chunks

  • Generates embeddings for the given input

    Parameters

    • _params: EmbeddingParams

    Returns Promise<EmbeddingResponse>

    The embedding vectors

  • Calculates the cost of a chat completion based on token usage. Returns 0 if no pricing information is available for the model.

    Parameters

    • model: string

      The model used

    • usage: TokenUsage

      Token usage information

    Returns number

    Cost in USD, or 0 if pricing not configured

Properties

name: "anthropic" = 'anthropic'

Unique name of the provider (e.g., 'openai', 'anthropic', 'local')

models: string[]

List of supported models