$ import OpenAI from 'openai' import { wrapOpenAI, withTrace } from '@voightxyz/openai' const openai = wrapOpenAI(new OpenAI(), { agent: 'production-chat-api', }) app.post('/api/chat', async (req, res) => { await withTrace( async () => { const r = await openai.chat.completions.create({ model: 'gpt-4o-mini', messages: req.body.messages, }) res.json({ reply: r.choices[0].message }) }, { routeTag: 'POST /api/chat', tags: { userId: req.user.id, plan: req.user.plan, }, }, ) }) COMMAND_BLOCK: import OpenAI from 'openai' import { wrapOpenAI, withTrace } from '@voightxyz/openai' const openai = wrapOpenAI(new OpenAI(), { agent: 'production-chat-api', }) app.post('/api/chat', async (req, res) => { await withTrace( async () => { const r = await openai.chat.completions.create({ model: 'gpt-4o-mini', messages: req.body.messages, }) res.json({ reply: r.choices[0].message }) }, { routeTag: 'POST /api/chat', tags: { userId: req.user.id, plan: req.user.plan, }, }, ) }) COMMAND_BLOCK: import OpenAI from 'openai' import { wrapOpenAI, withTrace } from '@voightxyz/openai' const openai = wrapOpenAI(new OpenAI(), { agent: 'production-chat-api', }) app.post('/api/chat', async (req, res) => { await withTrace( async () => { const r = await openai.chat.completions.create({ model: 'gpt-4o-mini', messages: req.body.messages, }) res.json({ reply: r.choices[0].message }) }, { routeTag: 'POST /api/chat', tags: { userId: req.user.id, plan: req.user.plan, }, }, ) }) CODE_BLOCK: import { openai } from '@ai-sdk/openai' import { streamText } from 'ai' export async function POST(req: Request) { const result = streamText({ model: openai('gpt-4o-mini'), prompt: (await req.json()).prompt, experimental_telemetry: { isEnabled: true, metadata: { userId: session.user.id, plan: session.user.plan, }, }, }) return result.toAIStreamResponse() } CODE_BLOCK: import { openai } from '@ai-sdk/openai' import { streamText } from 'ai' export async function POST(req: Request) { const result = streamText({ model: openai('gpt-4o-mini'), prompt: (await req.json()).prompt, experimental_telemetry: { isEnabled: true, metadata: { userId: session.user.id, plan: session.user.plan, }, }, }) return result.toAIStreamResponse() } CODE_BLOCK: import { openai } from '@ai-sdk/openai' import { streamText } from 'ai' export async function POST(req: Request) { const result = streamText({ model: openai('gpt-4o-mini'), prompt: (await req.json()).prompt, experimental_telemetry: { isEnabled: true, metadata: { userId: session.user.id, plan: session.user.plan, }, }, }) return result.toAIStreamResponse() } COMMAND_BLOCK: import { Voight } from '@voightxyz/sdk' const voight = new Voight({ agentId: 'my-bot' }) const t0 = Date.now() const res = await fetch('https://api.openai.com/v1/chat/completions', { method: 'POST', headers: { authorization: `Bearer ${process.env.OPENAI_API_KEY}` }, body: JSON.stringify({ model: 'gpt-4o-mini', messages: [...], }), }).then((r) => r.json()) voight.log({ type: 'reasoning', model: 'gpt-4o-mini', durationMs: Date.now() - t0, outcome: 'success', metadata: { tokens: { input: res.usage.prompt_tokens, output: res.usage.completion_tokens, }, tags: { userId: job.userId, tenantId: job.tenantId, }, }, }) COMMAND_BLOCK: import { Voight } from '@voightxyz/sdk' const voight = new Voight({ agentId: 'my-bot' }) const t0 = Date.now() const res = await fetch('https://api.openai.com/v1/chat/completions', { method: 'POST', headers: { authorization: `Bearer ${process.env.OPENAI_API_KEY}` }, body: JSON.stringify({ model: 'gpt-4o-mini', messages: [...], }), }).then((r) => r.json()) voight.log({ type: 'reasoning', model: 'gpt-4o-mini', durationMs: Date.now() - t0, outcome: 'success', metadata: { tokens: { input: res.usage.prompt_tokens, output: res.usage.completion_tokens, }, tags: { userId: job.userId, tenantId: job.tenantId, }, }, }) COMMAND_BLOCK: import { Voight } from '@voightxyz/sdk' const voight = new Voight({ agentId: 'my-bot' }) const t0 = Date.now() const res = await fetch('https://api.openai.com/v1/chat/completions', { method: 'POST', headers: { authorization: `Bearer ${process.env.OPENAI_API_KEY}` }, body: JSON.stringify({ model: 'gpt-4o-mini', messages: [...], }), }).then((r) => r.json()) voight.log({ type: 'reasoning', model: 'gpt-4o-mini', durationMs: Date.now() - t0, outcome: 'success', metadata: { tokens: { input: res.usage.prompt_tokens, output: res.usage.completion_tokens, }, tags: { userId: job.userId, tenantId: job.tenantId, }, }, }) - @voightxyz/openai for OpenAI - @voightxyz/anthropic for Anthropic - @voightxyz/vercel-ai for the Vercel AI SDK - @voightxyz/sdk for library mode