Back to GuidesDeveloper
LLM FinOps for Vercel AI SDK Apps
7 min readUpdated June 2026
Point the Vercel AI SDK at Cloptima
The Vercel AI SDK's OpenAI provider takes a base URL, so you only change configuration — not your generateText/streamText calls. Use a Cloptima virtual key and pass attribution on the headers option.
ts
import { createOpenAI } from "@ai-sdk/openai";
import { generateText } from "ai";
const cloptima = createOpenAI({
baseURL: "https://api.cloptima.ai/v1/ai",
apiKey: process.env.CLOPTIMA_VIRTUAL_KEY, // clop_vk_dPXO67p…
headers: { "x-cloptima-team": "web", "x-cloptima-app": "chat", "x-cloptima-environment": "production" },
});
const { text } = await generateText({ model: cloptima("gpt-4o-mini"), prompt });Attribute per route and workspace
Set x-cloptima-feature, x-cloptima-session-id, and x-cloptima-run-id per request to tie spend to a route, customer workspace, or agent run — not just an app total.
Add gateway controls when you need them
Because traffic already flows through Cloptima, budgets, model allowlists, provider access, and no-retention prompt policy apply without further app changes.
Operationalize
Use separate virtual keys and policies for preview, staging, and production deployments, and review unattributed usage as part of release readiness.