Change the base URL to call other AI models from OpenAI code
Change your OpenAI client base URL to point at an OpenAI-compatible gateway to call Claude, Gemini, and DeepSeek without rewriting code.
On this page 7 sections
You can call models from Anthropic, Google, DeepSeek, and Moonshot AI using your existing OpenAI client by changing the baseURL property to https://thelastapi.dev/v1/ai. The gateway accepts standard OpenAI request payloads, routes them to the target provider, and formats the output to match the OpenAI schema. This lets you switch models in code by editing a configuration string rather than rewriting SDK integrations.
When you point an OpenAI SDK instance at an OpenAI-compatible endpoint, your application preserves its streaming logic, function calling schema, and token parsing. This guide covers how to set the base URL, how model naming works, how to handle errors, and how to inspect per-request costs.
How to configure the OpenAI client with a new base URL
Most official OpenAI SDK libraries inspect environment variables before falling back to defaults. If you set OPENAI_BASE_URL in your environment, the client redirects all outgoing API calls to that URL automatically. Alternatively, you can pass the base URL and API key explicitly when initializing the client.
Environment variables
When running locally with the CLI, running vibiz dev populates .env.development.local with your development credentials. This includes VIBIZ_AI_BASE_URL and VIBIZ_AI_API_KEY, along with their aliases OPENAI_BASE_URL and OPENAI_API_KEY:
OPENAI_BASE_URL="https://thelastapi.dev/v1/ai"
OPENAI_API_KEY="vz_ai_1234567890abcdef"TypeScript and JavaScript
In Node.js, Bun, or Deno, initialize the official openai package using those environment values:
import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: process.env.VIBIZ_AI_BASE_URL || 'https://thelastapi.dev/v1/ai',
apiKey: process.env.VIBIZ_AI_API_KEY,
});
async function main() {
const completion = await openai.chat.completions.create({
model: 'anthropic/claude-sonnet-5.5',
messages: [
{ role: 'system', content: 'You are a concise engineering assistant.' },
{ role: 'user', content: 'Explain idempotency keys in one sentence.' },
],
});
console.log(completion.choices[0]?.message.content);
}
main();Because the response matches the standard OpenAI payload, completion.choices[0].message.content resolves normally, even though the call ran on an Anthropic model.
Using the @vibiz/app helper
If your project imports @vibiz/app, you do not need to configure URLs manually. The SDK provides a pre-configured configuration helper directly from the app environment:
import OpenAI from 'openai';
import { vibiz } from '@vibiz/app';
// vibiz.ai returns { baseURL, apiKey } derived from VIBIZ_APP_KEY
const openai = new OpenAI(vibiz.ai);
const res = await openai.chat.completions.create({
model: 'vibiz/fast',
messages: [{ role: 'user', content: 'Status check.' }],
});To learn more about connecting unified clients, see our guide on the OpenAI-compatible API for Claude and Gemini.
Which model names can you pass to the client?
Once your base URL points to /v1/ai, the model parameter determines which lab processes the request. You can pass two kinds of model names: tier aliases or full provider model identifiers.
Stable tier aliases
Tier aliases are purpose-built shortcuts. Each alias routes to a specific underlying model, updated as labs release revisions. If the assigned provider suffers an outage, the gateway returns model_unavailable or provider_unavailable instead of quietly substituting an unrequested model.
| thelastapi model | Underlying lab model | Best suited for | Input / Output price per 1M tokens |
|---|---|---|---|
vibiz/fast | GPT-6 Luna (OpenAI) | Low-latency chat, JSON mode, tool calls | $0.10 / $0.50 |
vibiz/lite | DeepSeek V4.1 Flash (DeepSeek) | Low-cost context-heavy tasks (1M context) | $0.14 / $0.42 |
vibiz/smart-mini | Claude Haiku 5.5 (Anthropic) | Quick code analysis and editing | $0.10 / $0.50 |
vibiz/balanced | Gemini 3.8 Flash (Google) | High context windows (1M context) | $0.825 / $4.125 |
vibiz/reasoning | GPT-6.1 Terra (OpenAI) | Multi-step logic, math, planning | $1.00 / $5.00 |
vibiz/smart | Claude Sonnet 5.5 (Anthropic) | Complex coding tasks and agents | $2.00 / $10.00 |
vibiz/pro | Claude Opus 5.5 (Anthropic) | Long agent executions and heavy logic | $4.00 / $20.00 |
Calling models by lab ID
You can bypass aliases and request any model directly by its catalogue id. Over 400 models are accessible, including models from Anthropic, Google, Moonshot AI, DeepSeek, xAI, Mistral, and Meta:
// Call Claude directly
const claudeRes = await openai.chat.completions.create({
model: 'anthropic/claude-opus-5.5',
messages: [{ role: 'user', content: 'Generate a TypeScript type guard.' }],
});
// Call Kimi directly
const kimiRes = await openai.chat.completions.create({
model: 'moonshotai/kimi-k3.1-pro',
messages: [{ role: 'user', content: 'Summarize our conversation.' }],
});For more specifics on querying Moonshot models, see our post on Kimi API access. You can browse the complete catalogue from the AI docs or via the CLI:
vibiz ai models --allHow the gateway handles streaming and cost tracking
When you switch endpoints, the client still handles standard server-sent event (SSE) streams. Set stream: true as you normally would:
const stream = await openai.chat.completions.create({
model: 'vibiz/smart',
messages: [{ role: 'user', content: 'Draft a short onboarding email.' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}If an error interrupts an active stream, the gateway transmits the issue as a final SSE event containing the standard OpenAI error structure (data: {"error": {...}}) without an accompanying [DONE] marker.
Response metadata and usage tracking
Standard responses add fields that help monitor infrastructure and spending. Every non-streamed JSON payload returned by /v1/ai/chat/completions contains two tracking fields alongside regular output:
served_model: Confirms the exact underlying lab model that answered the request.cost_micro_usd: Denotes the exact cost of the execution in micro-USD (millionths of a dollar).
{
"id": "chatcmpl-xyz123",
"object": "chat.completion",
"model": "vibiz/fast",
"served_model": "gpt-6-luna",
"cost_micro_usd": 125,
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Ready." }
}
]
}This lets your code record token costs directly against application users. For broader architecture patterns, read about how a unified AI API works.
Setting safety caps and handling rate limits
Routing all AI calls through one base URL centralizes billing controls. Instead of managing balances across four vendor portals, spending limits are enforced directly at the gateway layer.
Default spending limits
- Account daily limit: By default, an account cannot exceed $5 per UTC day across AI calls and background actions. An account owner can raise this limit up to $1,000 inside the console billing dashboard or via
PATCH /v1/billingwithdaily_spend_limit_usd. - Project daily budget: Each project defaults to a $1 daily AI cap. You can update this using the CLI:Terminal
vibiz ai budget 15 --project prj_123 - Concurrency and throughput: A standard project key permits 120 requests and 200,000 tokens per minute, with up to 25 in-flight requests. Account keys permit 300 requests and 400,000 tokens per minute.
When a limit is reached, the API returns an HTTP 429 error with a structured explanation:
{
"error": {
"code": "rate_limited",
"message": "Project daily AI budget reached.",
"type": "invalid_request_error",
"details": {
"reason": "project_budget",
"raise_url": "https://thelastapi.dev/projects/prj_123/ai?edit=ai_budget"
}
}
}To review your real-time spend, check the Usage and limits docs or run:
vibiz usage --by model --period 24hTesting your endpoint directly with curl
You can verify that your API key and network path work before touching application code by executing a raw curl command against the completions route:
curl https://thelastapi.dev/v1/ai/chat/completions \
-H "Authorization: Bearer $VIBIZ_AI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "vibiz/smart-mini",
"messages": [
{"role": "user", "content": "Say hello in Swedish."}
]
}'You can also send prompts directly from your terminal using the built-in CLI:
vibiz ai "Say hello in Swedish." --model vibiz/smart-miniAdding your own Google key
If you have existing Google Cloud credits, you can configure your own Gemini API key. Calls to Google models (vibiz/balanced, vibiz/image, or any explicit google/... model) will execute against your Google account:
GEMINI_API_KEY=your_key_here vibiz ai keys set googleWhen configured, the thelastapi gateway charges $0 for those operations (paid_by: "your_key"), while non-Google models continue billing against your standard account balance. If your Google key is invalid or exhausts its quota, the call fails immediately with customer_key_rejected rather than falling back to paid thelastapi credits behind your back.
To learn more about configuring keys and permissions across development and production environments, read the Keys and environments guide or review our Billing and credits documentation.
Ready to switch your endpoints? Create your account at thelastapi.dev/start to generate your gateway keys.
Frequently asked questions
Does changing the base URL break streaming or tool calling in the OpenAI SDK?
No. The gateway uses the standard OpenAI chat completions wire protocol, so streaming chunks (SSE), function calling, tool use, and JSON mode work without code adjustments.
What happens if an external model provider goes down?
The gateway returns a 503 error (`model_unavailable` or `provider_unavailable`) with a retry hint. It never silently swaps to a different model than the one you requested.
How do I track costs for individual application users through the custom URL?
Pass your internal pseudonymous identifier in the `user` field of the chat completion payload, or supply the `X-Vibiz-User` HTTP header; spend is then broken down by end user in usage reporting.