thelastapi
Get started free

Add AI features to your SaaS without vendor lock-in

Add AI features to your SaaS without lock-in by using an OpenAI-compatible gateway that lets you switch models with an environment variable.

On this page 8 sections

You can avoid vendor lock-in by building against standard OpenAI-compatible endpoints that let you switch models and providers by changing an environment variable. Instead of writing code against proprietary lab SDKs or vendor-specific wrappers, you use standard client libraries pointed at a unified gateway. If you ever decide to switch platforms, run your own gateway, or call a model lab directly, you only need to change your base URL and API key.

Building AI features this way protects your product from unexpected price changes, sudden deprecations, and architectural dead ends.

The three traps that lock your SaaS into an AI vendor

Adding AI to software usually starts with a simple prototype. Without planning for independence, three common traps create vendor lock-in:

  1. Proprietary client libraries and response shapes. If you write your features directly against a specific lab's SDK, every model switch requires refactoring streaming pipelines, parameter formats, tool-call schemas, and error handlers.
  2. Silent routing and opaque fallbacks. Some multi-model proxy services route traffic between models behind the scenes to smooth over outages. While this keeps an endpoint responsive, it changes your prompt behavior, output formats, and token costs without your consent.
  3. Scattered credentials and billing silos. Managing separate API accounts across three or four model labs leads to scattered spending dashboards, separate card charges, and messy credential rotation in local and production environments.

By using an open, standard wire format, your application code remains isolated from the underlying model provider.

Build on the standard OpenAI wire format

The OpenAI chat completions shape (/v1/ai/chat/completions) is now the default standard across the software industry. Most community libraries, agent frameworks, and evaluation tools speak this protocol natively.

thelastapi provides an OpenAI-compatible gateway under /v1/ai. You can use the official openai SDK or @ai-sdk/openai without installing custom middleware. To switch where your requests go, you change two environment variables:

Terminal
# In .env.development.local or your production host
VIBIZ_AI_BASE_URL=https://thelastapi.dev/v1/ai
VIBIZ_AI_API_KEY=vz_ai_...

Because the gateway supports standard OpenAI parameters (model, messages, stream, tools, response_format), your application logic contains no proprietary code. If you later choose to leave the gateway, you point VIBIZ_AI_BASE_URL (or OPENAI_BASE_URL) back to OpenAI or another compatible host. Read more about portable architecture in no lock-in: how to take your app elsewhere.

Stable tier aliases versus explicit model identifiers

Vendor lock-in often happens when model versions are hardcoded throughout your application. thelastapi lets you choose models in two ways: through functional aliases or through explicit lab identifiers.

Functional aliases

Functional aliases provide stable task-oriented names. When a lab releases an improved model, thealias moves forward without breaking your code:

Model aliasUnderlying modelPrimary use casePrice per 1M tokens (in / out)
vibiz/fastGPT-6 Luna (OpenAI)Chat, tool calls, JSON extraction$0.10 / $0.50
vibiz/liteDeepSeek V4.1 FlashCost-effective chat, 1M token context$0.14 / $0.42
vibiz/smart-miniClaude Haiku 5.5 (Anthropic)Fast writing, code generation$0.10 / $0.50
vibiz/balancedGemini 3.8 Flash (Google)Balanced quality, 1M token context$0.825 / $4.125
vibiz/reasoningGPT-6.1 Terra (OpenAI)Math, logic, structured planning$1 / $5
vibiz/smartClaude Sonnet 5.5 (Anthropic)Complex coding, writing, agent loops$2 / $10
vibiz/proClaude Opus 5.5 (Anthropic)Deep reasoning, demanding chat$4 / $20

Explicit model IDs

If you require an exact model version, you can call any model directly by its lab ID, such as anthropic/claude-opus-5.5 or moonshotai/kimi-k3.1-pro. Over 400 models from OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot AI, Qwen, Mistral, and Meta are available. You can read more about how this works in one API key for GPT, Claude and Gemini: how a unified AI API works.

Whichever route you pick, the model you request is the exact model that runs. If a provider experiences an outage, the gateway responds with 503 model_unavailable or 503 provider_unavailable alongside a retry hint. It will never quietly substitute a different model behind your back.

Implementation: Calling multiple labs with one client

Here is how to set up an AI feature in a TypeScript application. First, initialize your project using the CLI:

Terminal
vibiz init "Acme App" --resources ai
vibiz dev

The CLI creates your development environment and writes VIBIZ_AI_BASE_URL and VIBIZ_AI_API_KEY (along with their standard OPENAI_* aliases) into .env.development.local.

You can now use the standard openai library to call different labs using identical syntax:

TypeScript
import OpenAI from 'openai';

const openai = new OpenAI({
  baseURL: process.env.VIBIZ_AI_BASE_URL,
  apiKey: process.env.VIBIZ_AI_API_KEY,
});

async function generateSummary(text: string, userId: string) {
  const response = await openai.chat.completions.create({
    model: 'vibiz/fast',
    messages: [
      { role: 'system', content: 'Summarize the following text in two sentences.' },
      { role: 'user', content: text },
    ],
    user: userId,
  });

  return response.choices[0]?.message.content;
}

If your application uses the @vibiz/app library, you can pass vibiz.ai directly to the constructor without configuring custom environment variable names:

TypeScript
import OpenAI from 'openai';
import { vibiz } from '@vibiz/app';

const openai = new OpenAI(vibiz.ai);

Every JSON completion response returns the exact model that handled the call in the served_model field, along with the precise cost in cost_micro_usd.

Protecting margins with strict spending caps

Building AI features into a SaaS product exposes your margins to runaway loops and high-volume abuse. Preventing vendor lock-in also means ensuring your financial controls are independent of any single model provider's pricing quirks.

thelastapi enforces multi-tier budget controls:

  • Account daily spend ceiling: Set to $5 per UTC day by default across all AI calls and actions. Account owners can adjust this limit in the console under Billing or via PATCH /v1/billing with daily_spend_limit_usd.
  • Project daily budget: Defaults to $1 per UTC day. Owners can modify it using vibiz ai budget 15 or PATCH /v1/projects/:id/ai with daily_budget_usd.
  • End-user daily budget: Passing a user identifier (via the user parameter or X-Vibiz-User header) allows you to track usage per customer and set an end_user_daily_budget_usd cap.

When a limit is reached, the API returns a 429 rate_limited status with a descriptive reason code (daily_spend, project_budget, or end_user_budget). For deeper optimization strategies, review how to cut your LLM API bill: tiers, max_tokens and budgets and per-user AI budgets: stop one user from burning your AI bill.

Bringing your own lab credentials

If you have existing commitments or enterprise credits with a specific lab, you can attach your own credentials without changing your application code.

For Google models, you can attach your Gemini API key from Google AI Studio:

Terminal
GEMINI_API_KEY=your_key_here vibiz ai keys set google

Once configured, calls to Google models (such as vibiz/balanced, vibiz/image, or direct google/* model IDs) route to your personal Google account. The call cost on your thelastapi usage statement becomes $0, and the response marks "paid_by": "your_key".

If Google's service rejects your key or encounters an issue, the request fails with provider_failed (details.reason: "customer_key_rejected") rather than falling back to the gateway account. You are never billed unexpectedly. Other lab models continue to run through the gateway as usual.

Inspecting usage and costs

You can verify costs and token metrics directly from your terminal or script:

Terminal
# Check today's usage grouped by model
vibiz usage --by model

# Check past week's spend by user for a specific project
vibiz usage --period 7d --by end_user --project prj_123

Detailed metrics are available through GET /v1/usage, giving you clear insight into tokens, latency, and costs across every lab. Complete integration rules and configuration options are detailed on the AI docs page, with account parameters covered in Usage and limits and Billing and credits.

To start building without vendor lock-in, install the CLI, configure your project with vibiz init, and run your first chat completions against the standard /v1/ai endpoint.

Frequently asked questions

How does using an OpenAI-compatible gateway prevent vendor lock-in?

You build against standard OpenAI SDK interfaces and wire formats rather than proprietary vendor SDKs. If you ever switch providers, you only update your base URL and API key instead of refactoring application code.

Will the gateway swap in a different model if the requested lab is down?

No. The gateway returns a 503 error (`model_unavailable` or `provider_unavailable`) with a retry hint rather than silently routing your request to an unexpected model.

What happens if an AI request exceeds my daily budget?

The API returns an HTTP 429 status code with `rate_limited` and a clear reason in `details.reason`, such as `daily_spend` or `project_budget`. Account owners also receive notification emails at 80% and 100% of their daily limits.

Can I use my own API keys for specific models?

Yes. You can attach your own Google Gemini API key using `vibiz ai keys set google`, routing Google models to your account at zero platform usage cost while keeping other lab models on the gateway.