/docs/integrations/createObsrvMiddleware
Vercel AI SDK
Current integration pattern for AI SDK calls. A dedicated middleware helper is planned; today, wrap the call in a trace and log the model step explicitly.
Current pattern
import { generateText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";
import { TraceClient } from "@theta-lab/obsrv";
const client = new TraceClient();
await client.trace({ name: "ai-sdk-call", runType: "prod" }, async (t) => {
await t.step({ name: "generateText", type: "llm", model: "claude-sonnet-4-6" }, async (s) => {
s.logMessage({ role: "user", text: "Summarize the trace" });
const result = await generateText({
model: anthropic("claude-sonnet-4-6"),
prompt: "Summarize the trace",
});
s.logMessage({ role: "assistant", text: result.text });
return result;
});
});Status
The manual pattern is live today. A createObsrvMiddlewarepackage export should not be documented as shipped until it exists in@theta-lab/obsrv.