@converra/ai-sdk-middleware
v0.1.2
Published
Vercel AI SDK middleware for capturing LLM traces with Converra
Maintainers
Readme
@converra/ai-sdk-middleware
Vercel AI SDK middleware that automatically captures LLM traces and sends them to Converra for diagnostics and optimization.
Installation
npm install @converra/ai-sdk-middleware [email protected] @ai-sdk/[email protected]Keep the AI SDK and provider majors aligned. This package currently targets the
AI SDK v4 middleware contract, so use ai@4 with @ai-sdk/openai@1.
Quick Start
import { createConverraMiddleware } from '@converra/ai-sdk-middleware';
import { wrapLanguageModel, generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
const model = wrapLanguageModel({
model: openai('gpt-4o'),
middleware: createConverraMiddleware({
apiKey: process.env.CONVERRA_API_KEY!,
promptName: 'My Support Bot',
}),
});
// Use normally - traces are captured automatically
const result = await generateText({
model,
prompt: 'Help me reset my password',
});Configuration
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| apiKey | string | required | Your Converra API key |
| endpoint | string | https://converra.ai/api/v1 | API endpoint |
| promptName | string | Untitled Prompt | Name for auto-created prompt |
| batchSize | number | 1 | Traces per batch before flushing |
| flushInterval | number | 30000 | Milliseconds between flushes |
| enabled | boolean | true | Kill switch to disable capture |
What it captures
- Input messages (system prompt, user messages, assistant responses)
- Tool definitions, tool calls, and tool results
- Token usage (prompt, completion, total)
- Latency (start to end timing)
- Model ID and finish reason
How it works
The middleware wraps generate and stream calls via the AI SDK v4 middleware contract. Traces are buffered in memory and sent to Converra's conversation API in batches. Trace capture is non-blocking and never delays LLM responses.
Get an API key
Sign up at converra.ai or create an account programmatically:
curl -X POST https://converra.ai/api/v1/auth/signup \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]"}'License
Apache-2.0
