Skip to content

Anthropic (Claude)

Use Anthropic's Claude models as the LLM provider in a CompositeVoice pipeline.

Use AnthropicLLM when you want Claude’s strong instruction-following and reasoning for your voice assistant.

Prerequisites

npm install @anthropic-ai/sdk

Basic setup

import { CompositeVoice, AnthropicLLM, NativeSTT, NativeTTS } from '@lukeocodes/composite-voice';

const agent = new CompositeVoice({
  stt: new NativeSTT({ language: 'en-US' }),
  llm: new AnthropicLLM({
    proxyUrl: '/api/proxy/anthropic',
    model: 'claude-haiku-4-5',
    maxTokens: 512,
    systemPrompt: 'You are a concise voice assistant. Keep answers under two sentences.',
  }),
  tts: new NativeTTS(),
});

await agent.start();

Configuration options

OptionTypeDefaultDescription
modelstring'claude-haiku-4-5'Model identifier. See model variants below.
maxTokensnumber1024Maximum tokens per response. Anthropic requires this field.
systemPromptstringSystem-level instructions for the assistant.
temperaturenumberRandomness (0 = deterministic, 2 = creative).
topPnumberNucleus sampling threshold (0—1).
streambooleantrueStream tokens incrementally.
proxyUrlstringCompositeVoice proxy endpoint. Recommended for browsers.
apiKeystringDirect API key. Use only in server-side code.
maxRetriesnumber3Retry count for failed requests.

Model variants

ModelSpeedCapability
claude-haiku-4-5FastestBest for low-latency voice
claude-sonnet-4-6BalancedGood reasoning + speed
claude-opus-4-6SlowestMost capable

Complete example

import {
  CompositeVoice,
  AnthropicLLM,
  DeepgramSTT,
  DeepgramTTS,
} from '@lukeocodes/composite-voice';

const agent = new CompositeVoice({
  stt: new DeepgramSTT({
    proxyUrl: '/api/proxy/deepgram',
    language: 'en',
    options: { model: 'nova-3', smartFormat: true },
  }),
  llm: new AnthropicLLM({
    proxyUrl: '/api/proxy/anthropic',
    model: 'claude-haiku-4-5',
    maxTokens: 256,
    temperature: 0.7,
    systemPrompt: 'You are a friendly voice assistant. Answer briefly.',
  }),
  tts: new DeepgramTTS({
    proxyUrl: '/api/proxy/deepgram',
    voice: 'aura-2-thalia-en',
  }),
  conversationHistory: { enabled: true, maxTurns: 10 },
});

await agent.start();

Tips

  • maxTokens is required. Anthropic’s API rejects requests without it. The provider defaults to 1024, but for voice applications, lower values (128—512) produce faster responses.
  • System prompts are handled automatically. AnthropicLLM extracts system messages and passes them as the top-level system parameter, which is what the Anthropic API expects.
  • Use a proxy in browsers. The proxy server injects your API key server-side so it never reaches the client.
  • Streaming is on by default. Set stream: false only if you need the complete response before TTS begins.

© 2026 CompositeVoice. All rights reserved.

Font size
Contrast
Motion
Transparency