Ir al contenido

Quickstart: Vercel AI SDK

Esta página aún no está disponible en tu idioma.

Use the traces your AI SDK agent emits to test its behavior in Mibo. You enable the SDK’s built-in telemetry, send a trace over OpenTelemetry, and write your first tool-call test.

  • A Mibo account with a verified email. Open the verification link in the browser you signed up with.
  • Node.js 22.18 or later to run TypeScript directly.
  • An OpenAI API key for the model in this example.

Tested November 21, 2026 with Node.js 26.13.1 and the package versions pinned below.

Open the verification link in the browser you signed up with. If you open it elsewhere, Mibo asks you to choose a new password and earlier API keys stop working. If you own the workspace, create an API key in Settings and copy it. Mibo shows the key only once. If you’re a workspace member, ask the owner for a key.

This example sets service.name with OTEL_SERVICE_NAME. A workspace key lets Mibo create an Agent with that name on the first trace. A key scoped to one Agent sends traces to that Agent. See trace routing.

Run these commands in a new project directory. The script uses top-level await, so set the project to ES modules.

Terminal window
npm init -y
npm pkg set type=module
npm install --save-exact [email protected] @ai-sdk/[email protected] @ai-sdk/[email protected] \

This guide uses AI SDK 7 with the OpenTelemetry integration from @ai-sdk/otel. AI SDK 7 accepts experimental_telemetry as a deprecated alias for telemetry. Mibo also reads the ai.* attributes emitted by AI SDK 5.

Terminal window
export OTEL_SERVICE_NAME=vercel-support
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://api.mibo-ai.com/public/traces
export OTEL_EXPORTER_OTLP_TRACES_HEADERS='x-api-key=<YOUR_MIBO_API_KEY>'
export OTEL_METRICS_EXPORTER=none
export OTEL_LOGS_EXPORTER=none
export OPENAI_API_KEY='<YOUR_OPENAI_API_KEY>'

The exporter uses the traces-specific endpoint as written. If you use the generic OTEL_EXPORTER_OTLP_ENDPOINT, set it to https://api.mibo-ai.com so the exporter appends /v1/traces to the base URL. The metrics and logs settings keep the SDK focused on trace export.

Save the following as agent.ts.

import { OpenTelemetry } from '@ai-sdk/otel';
import { openai } from '@ai-sdk/openai';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { generateText, registerTelemetry, stepCountIs, tool } from 'ai';
import { z } from 'zod';
const sdk = new NodeSDK({
traceExporter: new OTLPTraceExporter({ timeoutMillis: 10_000 }),
});
sdk.start();
registerTelemetry(new OpenTelemetry({ agentSpanName: 'functionId' }));
try {
const { text } = await generateText({
model: openai.chat('gpt-4o-mini'),
prompt: 'Use lookupOrder to check order A-1042.',
tools: {
lookupOrder: tool({
description: 'Look up an order by ID',
inputSchema: z.object({ orderId: z.string() }),
execute: async ({ orderId }) => ({ orderId, status: 'shipped', eta: 'Friday' }),
}),
},
stopWhen: stepCountIs(3),
timeout: 20_000,
maxRetries: 0,
experimental_telemetry: { isEnabled: true, functionId: 'support-agent' },
});
console.log(text);
} finally {
await sdk.shutdown();
}

Run the script.

Terminal window
node agent.ts

The script prints the model’s reply, for example Your order A-1042 has shipped and should arrive on Friday. Awaiting sdk.shutdown() flushes buffered spans before the script exits. In a server, start the SDK once and shut it down when the server stops.

Open Traces and select the Agent that received the trace by its current name. If Mibo created the Agent for this example, its initial name is vercel-support. Open the order trace and click View raw trace data to inspect the invoke_agent support-agent and chat gpt-4o-mini spans. If the model called lookupOrder, you’ll also see execute_tool lookupOrder in the raw data and the call under What the agent did.

  1. Wait for the order trace to finish, then click Create test from this trace.
  2. Open Draft if the editor shows tabs. Set Name to Looks up the order and clear Checks a trace when so the test checks each new trace for this Agent.
  3. Keep the Tool call check. If the draft omits it, choose Tool call from Does check. Set Tool name to lookupOrder and select Must call. Remove the other checks and click Save test.
  4. Run node agent.ts again. Open the new trace on Traces and look under Test results. The check passes when the trace records a call to lookupOrder.
Data AI SDK 7 OpenTelemetry attributes
User input and final reply gen_ai.input.messages and gen_ai.output.messages
Requested model gen_ai.request.model
Tool name and arguments gen_ai.tool.name and gen_ai.tool.call.arguments on the tool span
Token usage gen_ai.usage.input_tokens and gen_ai.usage.output_tokens

The recordInputs and recordOutputs telemetry options default to true. With recordInputs: false, Mibo skips tests that have a Checks a trace when condition if the trace has no usable user input. With recordOutputs: false, checks on the reply have no text to read. Review Data handling before sending traces that contain personal data.

Send OTLP/HTTP protobuf with x-api-key to https://api.mibo-ai.com/public/traces. See OpenTelemetry (OTLP) for OTLP/HTTP JSON, gzip compression, and exporter settings.

Problem Likely cause Solution
404 or connection error Wrong host or path, such as /public/traces/v1/traces Set OTEL_EXPORTER_OTLP_TRACES_ENDPOINT to https://api.mibo-ai.com/public/traces.
HTTP 401 Missing, invalid, or revoked key Check the x-api-key entry in OTEL_EXPORTER_OTLP_TRACES_HEADERS. Ask the workspace owner to check whether the key is active.
HTTP 401 with API_KEY_EXPIRED in the message The API key expired Set x-api-key in OTEL_EXPORTER_OTLP_TRACES_HEADERS to an active key and rerun the script.
Export fails with a gRPC transport error The exporter uses OTLP/gRPC Use @opentelemetry/exporter-trace-otlp-proto for OTLP/HTTP protobuf.
HTTP 400 with a message beginning OTLP traces need the 'service.name' resource attribute service.name is unset or defaults to unknown_service, and Mibo can’t infer the Agent Set OTEL_SERVICE_NAME before starting the SDK.
The script prints a reply but no trace appears The process exits with spans still buffered Await sdk.shutdown() in a short script. If you manage a tracer provider directly, await its forceFlush() to export buffered spans while it stays active.
403 AGENT_LIMIT_REACHED Your plan has reached its Agent limit Use an existing Agent or free capacity for a new one. See Agent limit reached.
HTTP 403 with “Monthly trace ingestion limit reached” in the message Your workspace has used its monthly trace quota Wait for the next usage period or upgrade. Once capacity returns, rerun the script or resend the rejected payload.
Export succeeds but the trace is hidden or tool calls are missing Content capture is off, or the instrumentation emits an unsupported set of attributes Keep recordInputs and recordOutputs enabled. Check the supported trace dialects.