Skip to main content
The Muxx SDK provides seamless integration with the Anthropic TypeScript SDK.

Wrapping the Client

import { Muxx } from 'muxx';
import Anthropic from '@anthropic-ai/sdk';

const muxx = new Muxx();
const client = muxx.wrap(new Anthropic());

const response = await client.messages.create({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Hello!' }],
});

Streaming

const stream = client.messages.stream({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 1024,
  messages: [{ role: 'user', content: 'Write a poem' }],
});

for await (const event of stream) {
  if (event.type === 'content_block_delta' && event.delta.type === 'text_delta') {
    process.stdout.write(event.delta.text);
  }
}

System Prompts

const response = await client.messages.create({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 1024,
  system: 'You are a helpful coding assistant.',
  messages: [{ role: 'user', content: 'Write a Python sort function' }],
});

Tool Use

const tools: Anthropic.Tool[] = [
  {
    name: 'get_weather',
    description: 'Get current weather for a location',
    input_schema: {
      type: 'object',
      properties: {
        location: {
          type: 'string',
          description: 'City and country',
        },
      },
      required: ['location'],
    },
  },
];

const response = await client.messages.create({
  model: 'claude-3-5-sonnet-20241022',
  max_tokens: 1024,
  tools,
  messages: [{ role: 'user', content: "What's the weather in Tokyo?" }],
});

With Traces

async function analyzeDocument(doc: string): Promise<string> {
  return muxx.trace('document-analysis', async () => {
    const analysis = await muxx.span('analyze', async () => {
      return client.messages.create({
        model: 'claude-3-5-sonnet-20241022',
        max_tokens: 2048,
        messages: [{ role: 'user', content: `Analyze: ${doc}` }],
      });
    });

    return analysis.content[0].type === 'text' ? analysis.content[0].text : '';
  });
}

Model Selection

// Fast and capable
await client.messages.create({ model: 'claude-3-5-sonnet-20241022', ... });

// Fast and cost-effective
await client.messages.create({ model: 'claude-3-5-haiku-20241022', ... });

// Most powerful
await client.messages.create({ model: 'claude-3-opus-20240229', ... });