curl examples: chat completions with different models
Send chat completions to GPT, Claude, Gemini, and DeepSeek using curl by swapping the model parameter on one OpenAI-compatible endpoint.
On this page 8 sections
- How to format the basic curl request
- Calling different models by tier or lab identifier
- How to stream completions with server-sent events
- Reading the response: token usage, cost, and served model
- Passing user IDs to track spend per customer
- How to inspect available models from the terminal
- Handling rate limits, budgets, and errors
- FAQ
To run chat completions across different AI models with curl, send a POST request to https://thelastapi.dev/v1/ai/chat/completions with your bearer token and pass the desired model in the JSON payload. Because the gateway is fully OpenAI-compatible, you change models by updating the "model" field—whether you want a managed tier like vibiz/fast or a direct lab model like anthropic/claude-opus-5.5. Every response returns standard chat format while specifying the exact cost in cost_micro_usd and the actual model run in served_model.
This guide walks through working curl commands for different models, shows how to stream tokens over server-sent events, and explains how to inspect usage and errors.
How to format the basic curl request
Every chat request to the gateway requires three things:
- The endpoint URL:
https://thelastapi.dev/v1/ai/chat/completions - An
Authorizationheader containing your account key (vz_sk_...) or project AI key (vz_ai_...) - A JSON body with a
modelstring and amessagesarray
Here is the minimal request:
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": "Name a bakery in three words."}
]
}'If you use an account key and want to attribute spend to a specific project, pass the project header:
curl https://thelastapi.dev/v1/ai/chat/completions \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H "X-Vibiz-Project: prj_123" \
-H "Content-Type: application/json" \
-d '{
"model": "vibiz/fast",
"messages": [
{"role": "user", "content": "Hello!"}
]
}'The gateway handles the translation to the underlying provider. If you want to know more about how one key routes across multiple providers, see how to access multiple AI models with a single API.
Calling different models by tier or lab identifier
You can target models in two distinct ways: using a thelastapi tier name or specifying any supported lab's model identifier directly.
1. Using stable thelastapi model tiers
thelastapi models are stable names representing specific workload tiers. Each name maps to a single lab model. When the underlying model is upgraded, the tier moves to the newer release, but the tier name in your scripts stays the same.
| thelastapi model | Runs on | Best suited for | List price (in / out per M tokens) |
|---|---|---|---|
vibiz/fast | GPT-6 Luna (OpenAI) | General chat, tool calls, JSON mode | $0.10 / $0.50 |
vibiz/lite | DeepSeek V4.1 Flash (DeepSeek) | Low-cost high-volume chat, 1M 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, 1M context | $0.825 / $4.125 |
vibiz/reasoning | GPT-6.1 Terra (OpenAI) | Extended thinking, math, logic | $1 / $5 |
vibiz/smart | Claude Sonnet 5.5 (Anthropic) | Complex coding, long writing tasks | $2 / $10 |
vibiz/pro | Claude Opus 5.5 (Anthropic) | Heavyweight reasoning, long agent runs | $4 / $20 |
To call Claude Sonnet 5.5 via the managed tier, set "model": "vibiz/smart":
curl https://thelastapi.dev/v1/ai/chat/completions \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "vibiz/smart",
"messages": [
{"role": "system", "content": "You are a concise code reviewer."},
{"role": "user", "content": "Explain why array indexing starts at zero."}
],
"max_tokens": 500
}'To run DeepSeek V4.1 Flash with low latency and long context, switch the model to vibiz/lite:
curl https://thelastapi.dev/v1/ai/chat/completions \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "vibiz/lite",
"messages": [
{"role": "user", "content": "Write a short poem about server uptime."}
]
}'2. Using direct lab identifiers
If your project requires a specific lab release rather than a tier alias, pass the lab's full model id. More than 400 models from OpenAI, Anthropic, Google, DeepSeek, xAI, Moonshot AI, Qwen, Mistral, and Meta are available. You can read more about how this architecture operates in one API key for GPT, Claude and Gemini: how a unified AI API works.
Here is a curl request calling Anthropic's flagship model directly:
curl https://thelastapi.dev/v1/ai/chat/completions \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-opus-5.5",
"messages": [
{"role": "user", "content": "Outline a zero-downtime migration strategy."}
]
}'Here is a curl call sending a prompt to Moonshot AI's Kimi:
curl https://thelastapi.dev/v1/ai/chat/completions \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "moonshotai/kimi-k3.1-pro",
"messages": [
{"role": "user", "content": "Summarize key differences between TCP and UDP."}
]
}'If you submit a model id that does not exist in the catalogue, the gateway does not guess or redirect. It returns a 400 invalid_request error naming the model parameter.
How to stream completions with server-sent events
To stream chunks as they are generated, include "stream": true in the JSON body and pass the -N (or --no-buffer) flag to curl. This stops curl from buffering the chunks locally.
curl -N https://thelastapi.dev/v1/ai/chat/completions \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "vibiz/balanced",
"stream": true,
"messages": [
{"role": "user", "content": "Draft a welcome message for an onboarding tour."}
]
}'The server returns data lines formatted as server-sent events:
data: {"id":"chatcmpl_abc123","object":"chat.completion.chunk","created":1741500000,"model":"vibiz/balanced","served_model":"google/gemini-3.8-flash","choices":[{"index":0,"delta":{"content":"Welcome"},"finish_reason":null}]}
data: {"id":"chatcmpl_abc123","object":"chat.completion.chunk","created":1741500000,"model":"vibiz/balanced","served_model":"google/gemini-3.8-flash","choices":[{"index":0,"delta":{"content":" aboard!"},"finish_reason":null}]}
data: [DONE]If an error happens mid-stream, the connection does not emit [DONE]. Instead, it delivers a final JSON event containing the error object: data: {"error": {...}}. You can explore implementation patterns in streaming chat completions with server-sent events through one API.
Reading the response: token usage, cost, and served model
Non-streaming responses mirror the OpenAI schema but append metadata fields to keep your billing transparent:
{
"id": "chatcmpl_890xyz",
"object": "chat.completion",
"created": 1741500000,
"model": "vibiz/fast",
"served_model": "openai/gpt-6-luna",
"cost_micro_usd": 150,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Crust & Crumb."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 14,
"completion_tokens": 5,
"total_tokens": 19
}
}Notice two fields:
served_model: Identifies the exact model that processed the prompt. If you calledvibiz/fast, this showsopenai/gpt-6-luna. thelastapi never substitutes a cheaper or different model.cost_micro_usd: Shows the real cost of the request in micro-dollars (one million micro-dollars equals $1.00 USD). In this example, 150 micro-dollars equals $0.00015.
Passing user IDs to track spend per customer
To monitor spend across individual customers in your application, supply a stable pseudonymous user id. You can include it in the JSON body under "user" or in the request headers under X-Vibiz-User:
curl https://thelastapi.dev/v1/ai/chat/completions \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H "X-Vibiz-User: usr_user987" \
-H "Content-Type: application/json" \
-d '{
"model": "vibiz/fast",
"user": "usr_user987",
"messages": [
{"role": "user", "content": "Help me reset my profile password."}
]
}'Tagging calls this way allows you to enforce per-user daily budgets (end_user_daily_budget_usd) and view customer breakdowns in the CLI via vibiz usage --by end_user. Learn more in the Usage and limits documentation.
How to inspect available models from the terminal
Before assembling a curl call, you can search all available models and their current token pricing directly in your terminal:
# Search for Claude models
vibiz ai models claude
# Search for DeepSeek or Gemini models
vibiz ai models deepseek
vibiz ai models geminiTo retrieve the complete list programmatically using curl, query the /v1/ai/models endpoint:
curl https://thelastapi.dev/v1/ai/models?all=1 \
-H "Authorization: Bearer $VIBIZ_API_KEY"To inspect capability health before sending high-priority traffic, make a GET request to /v1/ai/health:
curl https://thelastapi.dev/v1/ai/health \
-H "Authorization: Bearer $VIBIZ_API_KEY"Handling rate limits, budgets, and errors
When a curl request cannot be completed, the gateway returns a standard error object with a descriptive code and details payload.
Common error scenarios include:
{
"error": {
"code": "rate_limited",
"message": "Project daily AI budget exceeded.",
"type": "requests",
"param": null,
"details": {
"reason": "project_budget"
}
}
}Key limits and error codes to track:
rate_limited(429): Triggered when you hit concurrency limits (50 in-flight for account keys, 25 for project keys, after up to 60 s waiting for a free slot), token limits (400k tokens per minute on account keys), or daily spend caps.- Account daily safety cap: New accounts start with a default $5 daily limit across AI and actions, resetting at midnight UTC. Owners can increase this up to $1,000 in Billing.
- Project budget: Projects default to a $1 daily AI budget, adjustable via
PATCH /v1/projects/:id/aior the console. model_unavailable(503): If the upstream provider is down, the request fails immediately rather than swapping to a different model without your consent.payment_required(402): Sent if your prepaid credit balance drops to zero or cannot cover the worst-case token ceiling for the request. Accounts begin with $2 of trial credit; see Billing and credits for top-up details.
For complete field breakdowns, rate tier configurations, and media endpoints, review the AI documentation. Create your account at thelastapi.dev/start to set up your unified access key.
Frequently asked questions
How do I choose between a thelastapi model tier and a specific lab model id in curl?
Pass a tier name like `vibiz/fast` or `vibiz/smart` if you want a stable tier that updates as providers release better versions. Pass a specific lab identifier like `anthropic/claude-opus-5.5` or `moonshotai/kimi-k3.1-pro` if your system relies on an exact model release.
Can I use the official OpenAI SDK instead of writing raw curl commands?
Yes. Because the `/v1/ai` gateway is OpenAI-compatible, point the OpenAI client's `baseURL` to `https://thelastapi.dev/v1/ai` and provide your thelastapi key as the `apiKey`.
What happens if an upstream model provider experiences downtime?
The gateway answers with a `503 model_unavailable` or `provider_unavailable` error code. It never secretly routes your request to a different model or provider.
How can I see how much a curl request cost?
Every non-streaming JSON response includes the `cost_micro_usd` integer, indicating the exact price of the call in micro-dollars. You can also view aggregated spend with the CLI by running `vibiz usage --by model`.