thelastapi
Get started free

An AI API with a usage dashboard per model

Track token spend and request volume per model across multiple AI labs in one unified dashboard, CLI tool, and metered API with thelastapi.

On this page 8 sections

thelastapi provides an AI API with automatic per-model usage tracking across every major provider, accessible via a hosted dashboard, CLI commands, and a reporting endpoint. Every chat completion, embedding, and image generation response returns the exact cost in micro-USD alongside the specific model that ran. You can inspect aggregated usage grouped by model, project, API key, or end user without building your own token-tracking database.

When your application routes different features to different models, tracking spend usually gets messy. One feature runs on a low-cost model for summarization, another needs a reasoning model for complex workflows, and customer-facing chat might use a balanced tier. If you call each provider directly, your usage metrics live in separate provider dashboards with different reporting intervals and billing units.

A unified gateway standardizes how spend is recorded, visualized, and capped. Here is how model-level usage tracking works, how to query it, and how to guard your spend.

How per-model usage tracking works

thelastapi routes requests through an OpenAI-compatible endpoint at https://thelastapi.dev/v1/ai. You can invoke a named thelastapi model tier or specify any provider model directly using its native identifier:

thelastapi modelRuns onGood forInput / Output price per million tokens
vibiz/fastGPT-6 Luna (OpenAI)Chat, tool calls, JSON output$0.10 / $0.50
vibiz/liteDeepSeek V4.1 FlashHigh-volume chat, 1M context$0.14 / $0.42
vibiz/smart-miniClaude Haiku 5.5 (Anthropic)Fast coding and writing$0.10 / $0.50
vibiz/balancedGemini 3.8 Flash (Google)Balanced quality and cost, 1M context$0.825 / $4.125
vibiz/reasoningGPT-6.1 Terra (OpenAI)Math, logic, structured planning$1.00 / $5.00
vibiz/smartClaude Sonnet 5.5 (Anthropic)Hard coding, writing, agent runs$2.00 / $10.00
vibiz/proClaude Opus 5.5 (Anthropic)Deep reasoning and long agent tasks$4.00 / $20.00

You can also request over 400 models directly by lab identifier (such as moonshotai/kimi-k3.1-pro or anthropic/claude-opus-5.5). See One API key for GPT, Claude and Gemini: how a unified AI API works for details on direct model selection.

Regardless of which model you choose, the gateway runs exactly that model. If a provider is down, the call fails with 503 model_unavailable or 503 provider_unavailable instead of silently rerouting your prompt to an unexpected model with different pricing. Every request records what it cost to run (cost) and what your account pays (billed), categorized by the exact model requested.

Inspecting model usage from the CLI and dashboard

You do not need to parse logs or reconcile monthly invoices to see which models drive your spend. The vibiz CLI provides instant breakdown views:

Terminal
# View usage grouped by model
vibiz usage --by model

# Filter to a specific model over the last 7 days
vibiz usage --period 7d --model vibiz/fast

# Check usage for a specific project
vibiz usage --project prj_123 --by model

# Open the hosted web dashboard directly in your browser
vibiz usage --open

Running vibiz usage --open generates a signed link to the hosted dashboard at thelastapi.dev. The dashboard displays interactive charts showing token volume, request outcomes, and dollar spend across models, projects, and environments.

If you group by other dimensions, you can see how model choices interact with your codebase:

  • --by tool: See total spend across chat completions, embeddings, images, and audio.
  • --by project: Compare AI usage across different services or staging environments.
  • --by api_key: Measure spend per autonomous agent or team member.
  • --by end_user: Determine which of your customers consume the most AI resources.

Querying model usage programmatically

If you run internal admin dashboards, automate cost accounting, or report metrics to your own team, you can query usage directly using the REST API:

Terminal
curl "https://thelastapi.dev/v1/usage?period=7d&group_by=model" \
  -H "Authorization: Bearer $VIBIZ_API_KEY"

The endpoint accepts group_by with up to three fields (capability, tool, model, alias, project, api_key, end_user, day, outcome) and filters including project, model, tool, and end_user.

The JSON response returns aggregate totals, per-model line items, and your current account limits:

JSON
{
  "object": "usage",
  "period": "7d",
  "totals": {
    "cost_usd": 4.12,
    "billed_usd": 4.53,
    "units": {
      "input_tokens": 1250000,
      "output_tokens": 420000
    }
  },
  "data": [
    {
      "model": "vibiz/fast",
      "cost_usd": 0.35,
      "billed_usd": 0.38,
      "units": {
        "input_tokens": 850000,
        "output_tokens": 210000
      }
    },
    {
      "model": "vibiz/smart",
      "cost_usd": 3.77,
      "billed_usd": 4.15,
      "units": {
        "input_tokens": 400000,
        "output_tokens": 210000
      }
    }
  ],
  "limits": {
    "resets_at": "2026-10-26T00:00:00.000Z",
    "daily_spend": {
      "spent_usd": 0.82,
      "held_usd": 0.05,
      "limit_usd": 5.00,
      "remaining_usd": 4.13,
      "used_pct": 16.4
    }
  }
}

This makes it straightforward to pass consumption data into internal billing tools or display a customer's individual token usage. Full parameter options are documented on the Usage and limits page.

Reading per-call costs directly in API responses

Beyond aggregated dashboards, you often need to associate the cost of a single prompt with a background job, database record, or user session. Every non-streaming JSON response from /v1/ai/chat/completions returns metadata fields alongside standard OpenAI outputs:

  • served_model: The exact underlying model that executed the prompt.
  • cost_micro_usd: The exact cost of the execution in micro-USD ($1 = 1,000,000 micro-USD).
Terminal
curl https://thelastapi.dev/v1/ai/chat/completions \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "vibiz/fast",
    "messages": [{"role": "user", "content": "Return three company names."}]
  }'

The response includes:

JSON
{
  "id": "chatcmpl_abc123",
  "object": "chat.completion",
  "model": "vibiz/fast",
  "served_model": "gpt-6-luna",
  "cost_micro_usd": 125,
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Acme, Orbit, Helix"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 14,
    "completion_tokens": 6,
    "total_tokens": 20
  }
}

In this call, cost_micro_usd: 125 translates to $0.000125. You can log this value directly in your database next to the task ID or prompt trace. If you build workflows with structured outputs, read JSON mode and structured output with any model to see how structured parameters affect output efficiency.

Setting budgets and spend caps per model and project

Tracking usage only solves half the problem; you also need mechanisms to prevent runaway scripts, loops, or traffic spikes from depleting your balance. thelastapi enforces layered limits:

  1. Daily safety cap: An account-wide ceiling on AI and actions (default $5 per UTC day). Account owners can raise this in the console under Billing or via PATCH /v1/billing {"daily_spend_limit_usd": 50} (up to $1,000).
  2. Project daily AI budget: A ceiling per project (default $1 per UTC day). Change it in the console or with:
    Terminal
    vibiz ai budget 10 --project prj_123
    Or via PATCH /v1/projects/:id/ai {"daily_budget_usd": 10}. Passing null removes the project budget.
  3. End-user daily budget: Set end_user_daily_budget_usd on a project to prevent any single end user from exhausting your daily allocation. Pass the user's ID in the user field of the chat completion payload, or send the X-Vibiz-User header.

When a limit is reached, the API returns a 429 rate_limited status with structured details:

JSON
{
  "error": {
    "code": "rate_limited",
    "message": "Project daily AI budget exceeded.",
    "type": "invalid_request_error",
    "details": {
      "reason": "project_budget",
      "raise_url": "https://thelastapi.dev/projects/prj_123/ai"
    }
  }
}

Account owners receive email alerts at 80% and 100% of the daily spend limit and project budgets, complete with direct links to adjust the cap. Check Billing and credits for more on how prepaid credits and auto-recharge settings work.

Running the gateway in your code

Because the AI gateway is OpenAI-compatible, integrating it requires no custom client libraries. Point the standard openai SDK to the gateway endpoint:

TypeScript
import OpenAI from 'openai';

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

// Run a lightweight extraction on a fast model
const classification = await openai.chat.completions.create({
  model: 'vibiz/fast',
  messages: [{ role: 'user', content: 'Classify: I cannot log in.' }],
});

// Run complex synthesis on a reasoning model
const analysis = await openai.chat.completions.create({
  model: 'vibiz/reasoning',
  messages: [{ role: 'user', content: 'Draft a root cause analysis for auth timeout.' }],
});

If you use orchestration libraries, you can pass the same base URL directly. See LangChain with a multi-model OpenAI-compatible gateway for examples configuring multi-model chains.

If your application uses @vibiz/app, you can pass vibiz.ai directly to the constructor without configuring separate environment variables:

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

const openai = new OpenAI(vibiz.ai);

// Attribute usage to a specific customer ID
const response = await openai.chat.completions.create({
  model: 'vibiz/smart',
  user: 'usr_84920',
  messages: [{ role: 'user', content: 'Generate quarterly projection summary.' }],
});

Using vibiz.user('usr_84920') automatically attaches the user attribution header, splitting your model dashboard metrics down to individual tenant accounts. Check the @vibiz/app reference for all available client methods.

Next steps

To start monitoring your model usage with thelastapi, create a project and inspect available models from your terminal:

Terminal
vibiz init "My App" --resources ai
vibiz dev
vibiz ai models

Review the AI docs for full schema details, or inspect the Usage and limits guide to configure custom budget thresholds.

Frequently asked questions

How do I view my AI API usage broken down by model?

Run `vibiz usage --by model` in your terminal to see cost and token totals per model, or run `vibiz usage --open` to view interactive usage graphs in the web console. You can also fetch model usage programmatically using `GET /v1/usage?group_by=model`.

Does thelastapi report the cost of each individual completion?

Yes. Every non-streaming chat completion JSON response includes the field `cost_micro_usd`, which states the exact cost of that call in micro-USD ($1 equals 1,000,000 micro-USD), along with `served_model` showing the exact lab model that ran.

Can I set daily spending caps on specific projects or models?

You can set a project-level daily ceiling using `vibiz ai budget <dollars> --project <id>` or through `PATCH /v1/projects/:id/ai` with `daily_budget_usd`. Accounts also have an overall daily spend limit ($5 default) that covers all models and actions.