Use @ai-sdk/openai with Claude, Gemini and more
Point @ai-sdk/openai to an OpenAI-compatible gateway to run Claude, Gemini, and DeepSeek models through standard AI SDK functions with one key.
On this page 6 sections
You can use @ai-sdk/openai with Claude, Gemini, and hundreds of other models by pointing the createOpenAI provider to an OpenAI-compatible gateway base URL. By passing baseURL: 'https://thelastapi.dev/v1/ai' into the provider instance, you keep standard AI SDK methods like generateText and streamText while routing prompts to models from Anthropic, Google, DeepSeek, and OpenAI. One API key handles authentication, and exactly the model you specify runs on every request.
This setup eliminates the need to install separate provider packages or maintain different API keys for every lab. Here is how to configure the provider, select models, manage daily project budgets, and stream responses.
How to configure @ai-sdk/openai for other model providers
The AI SDK uses provider factories to configure network targets and authentication headers. Instead of using default endpoints, you override baseURL and supply your thelastapi key.
To start, create a project with AI access using the CLI or retrieve your keys from your environment:
vibiz init "Support Engine" --resources ai
vibiz devThe CLI writes your credentials to .env.development.local. It sets VIBIZ_AI_BASE_URL (pointing to https://thelastapi.dev/v1/ai) and VIBIZ_AI_API_KEY (starting with vz_ai_). It also provides the standard OPENAI_BASE_URL and OPENAI_API_KEY aliases.
You can initialize the provider using environment variables directly:
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';
const provider = createOpenAI({
baseURL: process.env.VIBIZ_AI_BASE_URL,
apiKey: process.env.VIBIZ_AI_API_KEY,
});
const { text } = await generateText({
model: provider('vibiz/smart'),
prompt: 'Explain database normalization in two sentences.',
});
console.log(text);If your application already imports the @vibiz/app package and has VIBIZ_APP_KEY set, you can pass vibiz.ai directly into createOpenAI:
import { createOpenAI } from '@ai-sdk/openai';
import { vibiz } from '@vibiz/app';
import { generateText } from 'ai';
// vibiz.ai returns { baseURL, apiKey } derived from your app key
const provider = createOpenAI(vibiz.ai);
const { text } = await generateText({
model: provider('vibiz/fast'),
prompt: 'Write three taglines for a coffee roaster.',
});Because the base URL points to the unified endpoint, the provider accepts models from any supported lab without extra adapter layers. For a broader overview of how requests map across labs, read about our OpenAI-compatible API for Claude and Gemini: change one base URL.
Calling Claude, Gemini and DeepSeek with standard AI SDK methods
Once configured, your AI SDK workflows operate normally. You can stream text, execute tool calls, and run structured data generation across different lab backends by changing only the model identifier string.
Here is an example running a streaming completion using Claude Sonnet 5.5:
import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';
const provider = createOpenAI({
baseURL: process.env.VIBIZ_AI_BASE_URL,
apiKey: process.env.VIBIZ_AI_API_KEY,
});
const result = streamText({
model: provider('anthropic/claude-opus-5.5'),
messages: [
{ role: 'system', content: 'You are an expert technical editor.' },
{ role: 'user', content: 'Review this deployment script for missing flags.' },
],
});
for await (const delta of result.textStream) {
process.stdout.write(delta);
}To switch the execution to Gemini or DeepSeek, replace the model name passed into provider(). The gateway manages the protocol conversion:
// Call Gemini 3.8 Flash
const geminiResult = await generateText({
model: provider('vibiz/balanced'),
prompt: 'Categorize these support tickets by urgency.',
});
// Call DeepSeek V4.1 Flash
const deepseekResult = await generateText({
model: provider('vibiz/lite'),
prompt: 'Extract keywords from this release log.',
});This flexibility allows you to compare models inside the same application logic. To see how this pattern works in other runtimes, refer to how to use Claude with the OpenAI Python SDK.
Choosing between tier aliases and exact model ids
When invoking models via provider(modelId), you can supply either an alias or a specific lab identifier.
- thelastapi aliases: These are task-oriented names tied to designated models. If an underlying lab model is updated, the alias is pointed to the newer version while maintaining predictable role behavior.
- Direct lab ids: You can call specific model ids directly, such as
anthropic/claude-opus-5.5ormoonshotai/kimi-k3.1-pro. More than 400 models from OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot AI, Qwen, Mistral, and Meta are available.
The following table details the primary tier aliases:
| Model alias | Underlying lab model | Target workload | List pricing (in / out per 1M tokens) |
|---|---|---|---|
vibiz/fast | GPT-6 Luna (OpenAI) | Low-latency chat, JSON, tool calling | $0.10 / $0.50 |
vibiz/lite | DeepSeek V4.1 Flash | Cost-efficient chat, 1M token context | $0.14 / $0.42 |
vibiz/smart-mini | Claude Haiku 5.5 (Anthropic) | Quick, strong writing and coding | $0.10 / $0.50 |
vibiz/balanced | Gemini 3.8 Flash (Google) | Balanced quality and cost, 1M context | $0.825 / $4.125 |
vibiz/reasoning | GPT-6.1 Terra (OpenAI) | Math, multi-step logic, planning | $1.00 / $5.00 |
vibiz/smart | Claude Sonnet 5.5 (Anthropic) | Coding tasks, complex writing, agents | $2.00 / $10.00 |
vibiz/pro | Claude Opus 5.5 (Anthropic) | Complex reasoning, deep agent runs | $4.00 / $20.00 |
To view the live list of models and pricing from your terminal, run:
vibiz ai modelsEvery response returns the exact model executed in the served_model field. If you request a model that is currently experiencing downtime, the gateway returns a 503 model_unavailable or 503 provider_unavailable error rather than silently routing your tokens to a different model.
Handling budgets, rate limits and model errors
Production deployments require safeguards against runaways, unexpected token spikes, and bad inputs. The gateway handles rate limits and spending limits uniformly.
Daily budgets and account safety caps
The system applies several spending ceilings automatically:
- Daily spend limit: Accounts default to a $5 daily spend cap across AI and background actions. Account owners can raise this limit in the console or CLI up to $1,000.
- Project AI budget: Each project defaults to a $1 daily AI budget. Owners can adjust this in the console or via
vibiz ai budget <dollars> --project <id>. - Prepaid balance: Calls are validated against your balance before execution. If a request's worst-case token allocation exceeds your credit balance by more than $0.50, the gateway returns
402 payment_required.
When an app reaches a daily limit, the gateway answers with a 429 rate_limited status containing a structured reason such as daily_spend or project_budget. Account owners receive an alert email at 80% and 100% of these caps, providing an direct link to adjust them. Details on how limits work are covered in the Usage and limits documentation.
Standard error shapes
Because the gateway uses standard OpenAI response formatting, @ai-sdk/openai catches standard error payloads:
{
"error": {
"code": "rate_limited",
"message": "Daily project AI budget reached.",
"type": "requests",
"param": null,
"details": {
"reason": "project_budget",
"raise_url": "https://thelastapi.dev/projects/prj_123/ai"
}
}
}If an error occurs mid-stream during an SSE session, it is sent as a trailing event in the format data: {"error": {...}} rather than terminating the HTTP pipe without explanation.
Tracking per-call costs and usage in production
When building features on top of AI models, debugging spend per user or per feature is essential. Every JSON completion from the /v1/ai endpoint includes two metadata fields:
served_model: Confirms the exact model string that generated the answer.cost_micro_usd: Shows the real cost of the request in millionths of a dollar (micro-USD).
You can attribute spending to individual end users by attaching your user's identifier as the user parameter in the model call. In @vibiz/app, you can scope operations via vibiz.user(userId) to set the X-Vibiz-User header automatically.
To inspect recent spend by model or tool from your terminal:
vibiz usage --period 7d --by modelTo see which features or team members generated costs across individual keys, run:
vibiz usage --period 24h --by api_keyYou can review broader system concepts for running multiple models under a single credential in our guide on how a unified AI API works. For complete interface options and advanced parameters, visit the official AI documentation.
To start using @ai-sdk/openai across all supported labs, create your account at thelastapi.dev/start to generate your initial key.
Frequently asked questions
Do I need separate packages like `@ai-sdk/anthropic` or `@ai-sdk/google` when using this gateway?
No. Because the gateway provides a unified, OpenAI-compatible chat completion endpoint, `@ai-sdk/openai` handles requests for Claude, Gemini, DeepSeek, and other providers directly through `createOpenAI`.
What happens if a requested model goes offline?
The gateway returns a `503 model_unavailable` or `503 provider_unavailable` error with a retry hint. It never silently substitutes a different model for the one you specified.
How do token limits and context windows work on large models?
Context limits depend on the underlying model, up to 1M tokens on `vibiz/lite` and `vibiz/balanced`. The default output size (`max_tokens`) is 1,024 tokens if omitted, with an allowed maximum of 16,384 tokens.
Can I use my existing Google Gemini key to avoid platform usage charges for Google models?
Yes. You can register your Gemini API key using `vibiz ai keys set google`. Calls to Google models will run against your personal account at no platform fee, while calls to other labs continue billing to your credit balance.