Prerequisites
- Muxx TypeScript SDK installed (
npm install muxx) - Your Muxx API key
- An LLM provider SDK (OpenAI, Anthropic, etc.)
Get started with the Muxx TypeScript SDK in minutes.
npm install muxx)import { Muxx } from 'muxx';
import OpenAI from 'openai';
// Initialize Muxx
const muxx = new Muxx({ apiKey: 'muxx_sk_live_xxxxxxxxxxxx' });
// Wrap the OpenAI client
const client = muxx.wrap(new OpenAI());
// Use as normal - all calls are automatically traced
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'What is the capital of France?' }],
});
console.log(response.choices[0].message.content);
import { Muxx } from 'muxx';
import OpenAI from 'openai';
const muxx = new Muxx();
const client = muxx.wrap(new OpenAI());
async function summarizeDocument(document: string): Promise<string> {
return muxx.trace('document-summary', async () => {
// Extract key points
const points = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: `Extract key points from: ${document}` }],
});
// Generate summary
const summary = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'user', content: `Summarize these points: ${points.choices[0].message.content}` },
],
});
return summary.choices[0].message.content ?? '';
});
}
// Both LLM calls are grouped under one trace
const result = await summarizeDocument('Your long document here...');
import { Muxx } from 'muxx';
import OpenAI from 'openai';
const muxx = new Muxx();
const client = muxx.wrap(new OpenAI());
async function summarizeDocument(document: string): Promise<string> {
return muxx.trace('document-summary', async () => {
const points = await muxx.span('extract-points', async () => {
return client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: `Extract key points: ${document}` }],
});
});
const summary = await muxx.span('generate-summary', async () => {
return client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: `Summarize: ${points.choices[0].message.content}` }],
});
});
return summary.choices[0].message.content ?? '';
});
}
await muxx.trace(
'user-chat',
async () => {
// Your code here
},
{ metadata: { userId: 'user_123', feature: 'support' } }
);
await muxx.trace('risky-operation', async () => {
try {
await riskyOperation();
} catch (error) {
// Error is captured with full stack trace
throw error;
}
});