1. Install
shell
npm install @getopentoken/sdk ai @ai-sdk/openai-compatible2. Use the gateway as a provider
Set OT_API_KEY for the gateway and OT_INGEST_KEY for traces. vercelAIOptions() gives createOpenAICompatible the gateway's URL and a fail-open fetch; experimental_telemetry makes the AI SDK emit its spans, which init() sends to Open Token.
index.ts
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { generateText } from "ai";
import { init, ready, shutdown, vercelAIOptions, withContext } from "@getopentoken/sdk";
const ot = init({ baseUrl: "https://getopentoken.com/v1" });
await ready(); // tracing is set up; the AI SDK's spans go to Open Token
const opentoken = createOpenAICompatible(vercelAIOptions(ot));
const { text } = await withContext({ feature: "summaries" }, () =>
generateText({
model: opentoken("amazon/nova-lite"),
prompt: "Say hello in one sentence.",
experimental_telemetry: { isEnabled: true },
}),
);
console.log(text);
await shutdown();If your app already registers OpenTelemetry with @vercel/otel, add Open Token to it: registerOTel({ serviceName: "my-app", spanProcessors: await spanProcessors() }), then call init().