本页还没有译文
本页 23 段还没译成简体中文,下面显示的是英文原文。Respan
还没翻译译自英文(ai-sdk.dev)本页 23 段都还没译
Respan (formerly Keywords AI) is an LLM engineering platform for observability, evaluation, and gateway routing. Respan integrates with the AI SDK to provide:
- Tracing for each AI SDK call (input, output, token usage, cost, latency)
- Tool call and structured output capture
- Optional gateway routing across 250+ models behind a single endpoint
Setup
The AI SDK supports tracing via OpenTelemetry. With the VercelAIInstrumentor from @respan/instrumentation-vercel, traces are exported to Respan automatically.
Install
npm install ai @ai-sdk/openai @respan/respan @respan/instrumentation-vercelConfigure environment variables
RESPAN_API_KEY="your-respan-api-key"Get your API key from platform.respan.ai.
Initialize Respan
Create instrumentation.ts at the root of your Next.js project:
import { Respan } from '@respan/respan';
import { VercelAIInstrumentor } from '@respan/instrumentation-vercel';
export async function register() {
const respan = new Respan({
apiKey: process.env.RESPAN_API_KEY,
instrumentations: [new VercelAIInstrumentor()],
});
await respan.initialize();
}Then mark the SDK packages as server-external in next.config.ts:
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
serverExternalPackages: ['@respan/respan', '@respan/instrumentation-vercel'],
};
export default nextConfig;Initialize Respan at the top of your handler or entry point:
import { Respan } from '@respan/respan';
import { VercelAIInstrumentor } from '@respan/instrumentation-vercel';
const respan = new Respan({
apiKey: process.env.RESPAN_API_KEY,
instrumentations: [new VercelAIInstrumentor()],
});
await respan.initialize();Generate text with telemetry enabled
import { openai } from '@ai-sdk/openai';
import { generateText } from 'ai';
const result = await generateText({
model: openai('gpt-6-luna'),
prompt: 'Tell me a joke about AI',
experimental_telemetry: { isEnabled: true },
});Spans appear in the Respan traces page with input, output, token usage, and cost.
Gateway routing (optional)
To use Respan as a unified gateway across providers, point your AI SDK provider at the Respan gateway with your RESPAN_API_KEY. For the OpenAI provider, use https://api.respan.ai/api as the base URL. Provider keys are managed in Respan; only the Respan key is needed at runtime.
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';
const provider = createOpenAI({
apiKey: process.env.RESPAN_API_KEY!,
baseURL: 'https://api.respan.ai/api',
});
const result = await generateText({
model: provider('gpt-5.4-nano'),
prompt: 'Tell me a joke about AI',
experimental_telemetry: { isEnabled: true },
});The same gateway endpoint accepts Anthropic and Google models when used with their respective AI SDK providers (createAnthropic, createGoogleGenerativeAI) and the matching base path (/api/anthropic, /api/google/gemini).