@mutagent/openai
v0.1.2
Published
MutagenT integration for OpenAI SDK - wrapper with automatic tracing
Maintainers
Readme
MutagenT OpenAI
╔════════════════════════════════════════════════════════════════════════════════════════════╗
║ ║
║ ███╗ ███╗██╗ ██╗████████╗ █████╗ ██████╗ ███████╗███╗ ██╗████████╗ ║
║ ████╗ ████║██║ ██║╚══██╔══╝██╔══██╗██╔════╝ ██╔════╝████╗ ██║╚══██╔══╝ ║
║ ██╔████╔██║██║ ██║ ██║ ███████║██║ ███╗█████╗ ██╔██╗ ██║ ██║ ║
║ ██║╚██╔╝██║██║ ██║ ██║ ██╔══██║██║ ██║██╔══╝ ██║╚██╗██║ ██║ ║
║ ██║ ╚═╝ ██║╚██████╔╝ ██║ ██║ ██║╚██████╔╝███████╗██║ ╚████║ ██║ ║
║ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ║
║ ║
║ ██████╗ ██████╗ ███████╗███╗ ██╗ █████╗ ██╗ ║
║ ██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔══██╗██║ ║
║ ██║ ██║██████╔╝█████╗ ██╔██╗ ██║███████║██║ ║
║ ██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║██╔══██║██║ ║
║ ╚██████╔╝██║ ███████╗██║ ╚████║██║ ██║██║ ║
║ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚═╝ ╚═╝╚═╝ ║
║ ║
║ OpenAI Integration for AI-Native Observability. ║
║ ║
╚════════════════════════════════════════════════════════════════════════════════════════════╝OpenAI SDK wrapper with automatic tracing to MutagenT.
Installation
npm install @mutagent/openai @mutagent/sdkPeer Dependencies
| Package | Version |
|---------|---------|
| openai | >=4.0.0 |
| @mutagent/sdk | ^0.1.0 |
Quick Start
import { MutagentOpenAI } from '@mutagent/openai';
import { initTracing } from '@mutagent/sdk/tracing';
// Initialize tracing once at app startup
initTracing({ apiKey: process.env.MUTAGENT_API_KEY! });
// Create a traced OpenAI client
const client = new MutagentOpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
// Use like the standard OpenAI client -- traces are sent automatically
const completion = await client.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }],
});
// Streaming is also supported
const stream = await client.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}API Reference
MutagentOpenAI
Drop-in wrapper around the OpenAI client. Constructor accepts MutagentOpenAIOptions:
| Option | Type | Description |
|--------|------|-------------|
| apiKey | string | OpenAI API key |
| organization | string | OpenAI organization ID |
| baseURL | string | Custom base URL (proxies, Azure) |
| maxRetries | number | Max retries for failed requests |
| timeout | number | Timeout in milliseconds |
Exposes client.chat.completions.create() with the same interface as the OpenAI SDK. Both streaming and non-streaming calls are traced with input messages, output text, model name, and token usage metrics.
License
MIT
