Comparison

Vercel AI SDK OpenAI-Compatible Provider vs @ai-sdk/openai for Gateways

Compare the Vercel AI SDK OpenAI-compatible provider with @ai-sdk/openai for gateways: which endpoint each calls, setup, streaming usage and per-request cost.

Choosing a Vercel AI SDK OpenAI-compatible setup for a gateway comes down to three options: the dedicated @ai-sdk/openai-compatible provider, the official @ai-sdk/openai provider with openai.chat(), or @ai-sdk/openai with its default openai() factory. They look interchangeable in a quick demo. They are not, and the difference is mostly about which HTTP endpoint the SDK calls.

This comparison covers what each option sends, which one fits a Chat Completions gateway like AtmoRouter, and the setup, streaming and cost accounting for the option we recommend. It is AtmoRouter-authored, the cost figures are illustrative arithmetic at catalogue rates, and nothing here is a benchmark.

The short answer

| Option | Endpoint it calls | Works against a Chat Completions-only gateway? | Gateway-specific hooks | |---|---|---|---| | createOpenAICompatible() from @ai-sdk/openai-compatible | /chat/completions | Yes | name, includeUsage, transformRequestBody, supportsStructuredOutputs | | openai.chat('model-id') from @ai-sdk/openai | /chat/completions | Usually, with OpenAI-specific behaviour | Tuned for OpenAI's own models | | openai('model-id') (default factory) | Responses API | No | — |

The AI SDK's OpenAI provider docs state that since AI SDK 5 the default openai('model-id') factory calls the Responses API, and that if your custom base URL only supports Chat Completions you should use openai.chat() or the OpenAI-compatible provider. AtmoRouter's compatibility guide says there is no public /v1/responses endpoint. So the default factory is out, and the real choice is between the other two.

Why the OpenAI-compatible provider wins at a gateway

@ai-sdk/openai is built around OpenAI's model list. It applies compatibility rules for OpenAI reasoning models, such as converting the system message into a developer message, and it documents a forceReasoning switch for model IDs it does not recognise. That is helpful against OpenAI itself. At a gateway that serves Claude, GLM, MiniMax and GPT families behind one URL, it adds behaviour you never asked for.

@ai-sdk/openai-compatible stays close to the plain Chat Completions contract and gives you the knobs a gateway needs. transformRequestBody lets you strip or rewrite a field for one provider without forking call sites. includeUsage asks for token counts on streams. name is the key you later use in providerOptions. OpenCode uses the same package for custom providers, and AtmoRouter's compatibility guide recommends it for OpenCode too.

Set up the Vercel AI SDK OpenAI-compatible provider

bashpnpm add ai @ai-sdk/openai-compatible
ts// lib/atmorouter.ts
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';

export const atmorouter = createOpenAICompatible({
  name: 'atmorouter',
  baseURL: 'https://atmorouter.dev/v1', // Chat Completions base
  apiKey: process.env.ATMOROUTER_API_KEY, // ar-xxxxxxxxxxxx
  includeUsage: true, // ask for usage frames on streams
});

The base URL includes /v1; the provider appends /chat/completions. The Anthropic Messages surface lives at https://atmorouter.dev without /v1, but that is a different SDK path. includeUsage defaults to off in the SDK. AtmoRouter requests usage reporting when stream_options is omitted, but its streaming docs recommend setting include_usage explicitly when your client depends on usage frames, and this flag does exactly that.

One call, one stream

tsimport { generateText, streamText } from 'ai';
import { atmorouter } from './lib/atmorouter';

const { text, usage } = await generateText({
  model: atmorouter('zai/glm-5.3'),
  prompt: 'Summarise these release notes in three bullets:\n' + notes,
});
console.log(text, usage.inputTokens, usage.outputTokens);

const result = streamText({
  model: atmorouter('mm/MiniMax-M3'),
  prompt: 'Explain the difference between a 429 and a 503 in two sentences.',
});
for await (const delta of result.textStream) process.stdout.write(delta);
console.log(await result.usage);

Copy model IDs exactly, family prefix included. An unknown ID returns 404 model_not_found, and a shortened name like glm-5.3 is not a catalogue ID.

For a Next.js route, follow the current AI SDK UI pattern and pass the request's abort signal through:

ts// app/api/chat/route.ts
import {
  convertToModelMessages,
  createUIMessageStreamResponse,
  streamText,
  toUIMessageStream,
} from 'ai';
import { atmorouter } from '@/lib/atmorouter';

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: atmorouter('cx/gpt-6-sol'),
    messages: await convertToModelMessages(messages),
    maxRetries: 1,
    abortSignal: req.signal,
  });

  return createUIMessageStreamResponse({
    stream: toUIMessageStream({ stream: result.stream }),
  });
}

Response helper names have changed across SDK majors (toUIMessageStreamResponse() in AI SDK 5), so match the docs for the version you install. The abort signal matters for cost: AtmoRouter's streaming docs say disconnecting cancels the gateway request, and an interrupted request can still be billed for tokens already processed.

What a request costs at catalogue rates

Usage arrives per response, so cost per feature is a sum, not a guess. Take one illustrative shape, 12,000 input tokens and 600 output tokens, priced at the live catalogue's from-rates (USD per million tokens):

| Catalogue ID | From input / output | Illustrative cost, 12k in + 600 out | |---|---|---| | zai/glm-5.3-flash | $0.000375 / $0.00125 | ~$0.0000053 | | mm/MiniMax-M3 | $0.00075 / $0.003 | ~$0.000011 | | zai/glm-5.3 | $0.0035 / $0.011 | ~$0.000049 | | cx/gpt-6-sol | $0.05 / $0.25 | ~$0.00075 | | cc/claude-sonnet-5-5 | $0.325 / $1.625 | ~$0.0049 |

These are from-prices; a model with several tiers can bill above the floor, and rates refresh, so the model page is authoritative. Cached input is billed at 10% of the input rate where the model supports caching. For non-streaming calls, the exact charge also comes back in the X-Atmorouter-Cost header, and the usage log records every settled charge.

Mistakes that break the call or the bill

  • Using the default `openai()` factory. It targets the Responses API, which AtmoRouter does not expose publicly. Use the compatible provider or openai.chat().
  • Missing or doubled `/v1`. The provider appends /chat/completions, so https://atmorouter.dev or .../v1/v1 both miss the endpoint.
  • Nested retries. maxRetries defaults to 2 in the SDK. Wrapping it in your own retry loop multiplies attempts. Pick one retry owner, retry only 429/502/503, and never retry 400/401/403/404.
  • `providerOptions` under the wrong key. It must match the provider's name.
  • Estimating cost from visible text. Read usage or the settled usage log instead; partial streams can be charged for processed tokens.

FAQ

Can I use @ai-sdk/openai with AtmoRouter at all?

Yes, with openai.chat('model-id') and baseURL: 'https://atmorouter.dev/v1'. Avoid the bare openai('model-id') factory, which calls the Responses API.

Do tool calls work through the compatible provider?

The provider sends standard Chat Completions tool definitions. Whether a given model handles tools well depends on the model, so test your exact catalogue ID before shipping.

Why is usage empty on my stream?

Check includeUsage: true on the provider first. Interrupted streams may also end without a usage frame; the settled usage row in the dashboard is the fallback source.

Is there a seat fee or subscription?

No. AtmoRouter uses a prepaid USD balance with no subscription and no seat count, and a failed upstream request costs nothing.

Next step

Copy the provider file, run the streaming example against a low-cost ID from the live model list, and log usage before you build on it. The streaming and compatibility docs cover the edge cases, and the LangChain setup guide shows the same gateway behind a Python stack.

Newer

Tool Calling Token Cost: What Your Agent Really Pays Per Turn

Older

LangChain With an OpenAI-Compatible API: AtmoRouter Setup Guide

Build with AtmoRouter.