API reference
SuperbAPI API reference
Connect to supported AI models through one OpenAI-compatible base URL and a prepaid wallet. Start with read-only model discovery, then send a chat request using a model available to your key.
Reference reviewed against the gateway implementation.
Authentication
Base URL: https://www.superbapi.com/v1
Every request carries a key in the Authorization header. Generate keys in the workspace — each one can be scoped to a model allowlist, given a monthly budget, and given an expiry date.
Authorization: Bearer sk-sbapi-…
Model aliases. The gateway accepts an sb- prefixed model id and advertises aliases for configured Claude models. Use an alias returned by discovery when a client reserves the original name. For example, sb-claude-opus-5 illustrates the prefix format, not a promise that this model is currently available.
Quickstart
- Create a key in the workspace and set
SUPERBAPI_KEYin your local environment. Keep it server-side. - Run read-only discovery below. Choose a text/chat model id for
SUPERBAPI_MODEL; do not choose a video model for chat. - Run one of the chat examples. A successful generation spends prepaid credit; discovery does not generate content.
1 · Discover models (no generation)
curl https://www.superbapi.com/v1/models \
-H "Authorization: Bearer $SUPERBAPI_KEY"
Response shape illustration; MODEL_ID_FROM_V1_MODELS is a placeholder, not a callable model or a live availability claim:
{
"object": "list",
"data": [
{
"id": "MODEL_ID_FROM_V1_MODELS",
"object": "model",
"owned_by": "superbapi"
}
]
}
Set SUPERBAPI_MODEL to your chosen id for the SDK examples. In curl, replace MODEL_ID_FROM_V1_MODELS with that exact id.
2 · Send a chat request (billable on success)
curl
curl https://www.superbapi.com/v1/chat/completions \
-H "Authorization: Bearer $SUPERBAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "MODEL_ID_FROM_V1_MODELS",
"messages": [{"role": "user", "content": "Say hello in one short sentence."}]
}'
Python — pip install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["SUPERBAPI_KEY"],
base_url="https://www.superbapi.com/v1",
)
completion = client.chat.completions.create(
model=os.environ["SUPERBAPI_MODEL"],
messages=[{"role": "user", "content": "Say hello in one short sentence."}],
)
print(completion.choices[0].message.content)
Node — npm install openai
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.SUPERBAPI_KEY,
baseURL: "https://www.superbapi.com/v1",
});
const completion = await client.chat.completions.create({
model: process.env.SUPERBAPI_MODEL,
messages: [{ role: "user", content: "Say hello in one short sentence." }],
});
console.log(completion.choices[0].message.content);
Check advertised prices and capabilities on the models page. Its public catalogue includes comparison-only models that may be unavailable; it is not the same list as authenticated GET /v1/models. Editor and desktop-client setup is covered in the setup guides.
A successful non-streaming response has an assistant message under choices[0].message.content. This is an illustrative shape; ids, text and token counts vary:
{
"id": "chatcmpl_example",
"object": "chat.completion",
"model": "MODEL_ID_FROM_V1_MODELS",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello!"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 3,
"total_tokens": 15
}
}
Endpoints
On narrow screens, scroll tables sideways. Keyboard: focus a table or code example and use the arrow keys.
| Endpoint | What it does |
|---|---|
POST /v1/chat/completions | Chat completions. OpenAI-compatible request and response shapes for supported chat models — send stream: true for SSE. |
GET /v1/models | Configured model ids visible to this key, filtered by its model allowlist. |
GET /v1/credits | Wallet totals for the account behind the key: credit bought (including bonus) and credit spent. |
GET /v1/key | Inspect the presented key: its label, lifetime usage and configured spend cap. |
POST /v1/videos | Submit a video render. Returns a task id; the charge happens here, on a successful submit only. |
GET /v1/videos/{task_id} | Poll a render. Free — the charge happened at submit. Poll about every 15 seconds. |
POST /mcp | Model Context Protocol over HTTP (JSON-RPC 2.0), authenticated with the same key. |
POST /api/v1/keys | Mint a new API key programmatically. Authenticated with a provisioning token, not an API key. |
GET /api/v1/keys | List all API keys belonging to the token's account, masked — including manually created keys. |
DELETE /api/v1/keys/{id} | Revoke an API key belonging to the token's account by id, including a manually created key. The key stops routing immediately. |
POST/v1/chat/completions
Chat completions. OpenAI-compatible request and response shapes for supported chat models — send stream: true for SSE.
Chat parameters are forwarded to the upstream, including messages, temperature, max_tokens, tools, response_format, where supported by the chosen model. The gateway maps model for routing and defaults streaming usage collection. Compatibility does not mean every provider supports every parameter.
Billing is per token at the served model's rate, taken from your prepaid balance. Chat failures before any upstream succeeds are not charged. Interrupted streams can still incur a charge for reported or estimated partial usage; see Streaming.
GET/v1/models
Configured model ids visible to this key, filtered by its model allowlist.
Use this authenticated discovery endpoint instead of assuming a fixed model list. Entries contain id, object and owned_by, not prices. Discovery is not an upstream-health guarantee; a listed model can still fail. Check the model capability before choosing chat versus video.
GET/v1/credits
Wallet totals for the account behind the key: credit bought (including bonus) and credit spent.
{ "data": { "total_credits": 57.5, "total_usage": 12.34 } }GET/v1/key
Inspect the presented key: its label, lifetime usage and configured spend cap.
{ "data": { "label": "production", "usage": 12.34, "limit": 25, "limit_remaining": 12.66, "is_free_tier": false } }
limit is null when the key has no configured budget. The remaining amount is the value reported for this key; do not treat it as a reservation for future requests.
POST/v1/videos
Submit a video render. Returns a task id; the charge happens here, on a successful submit only.
A rejected submit costs nothing. Submits can take ~30 s to return a task id, so give the call a generous client timeout and never retry a submit that timed out — it may already be rendering, and a retry pays for a second clip.
Full reference, including reference-image rules and the two billing classes: the video API guide.
GET/v1/videos/{task_id}
Poll a render. Free — the charge happened at submit. Poll about every 15 seconds.
Read error.message whenever status is failed: a content-moderation rejection needs a different prompt, not a retry. A render that fails after being charged is refunded automatically on the poll that observes the failure, and the response says so.
POST/mcp
Model Context Protocol over HTTP (JSON-RPC 2.0), authenticated with the same key.
Use an MCP client that supports HTTP transport and bearer authentication at https://www.superbapi.com/mcp with Authorization: Bearer. Request/response only: a GET for the optional server-initiated stream answers 405, so the client must support plain POST request/response mode.
Key provisioning
Minting keys from your own backend — for per-customer keys, or a fresh key per deploy. These are authenticated with a provisioning token (created in the workspace), not with an API key.
POST/api/v1/keys
Mint a new API key programmatically. Authenticated with a provisioning token, not an API key.
Create a provisioning token once in the workspace, then mint per-customer or per-environment keys from your own backend. The key value is returned once, at creation.
{ "name": "customer-4182", "budgetLimit": 25, "allowedModels": ["MODEL_ID_FROM_V1_MODELS"], "routeScope": "text-code" }
Replace MODEL_ID_FROM_V1_MODELS with a discovered text/chat model id. Valid route scopes are all, text-code, vision and video. Minted keys inherit a default budget when you omit budgetLimit, and minting is rate-limited per account. Keep the provisioning token server-side; never put it in browser code.
GET/api/v1/keys
List all API keys belonging to the token's account, masked — including manually created keys.
DELETE/api/v1/keys/{id}
Revoke an API key belonging to the token's account by id, including a manually created key. The key stops routing immediately.
Machine-readable: openapi.json · llms.txt · catalog/models.json.
Streaming
Send stream: true and read a standard text/event-stream of chat.completion.chunk objects, terminated by data: [DONE]. The gateway defaults stream_options.include_usage to true, unless the caller overrides it. Upstream usage is optional even when requested. If absent, billing uses a length-based estimate; the gateway does not inject a final usage chunk. SSE responses do not have the completed-cost headers listed below.
# client is the OpenAI() instance from the quickstart above.
stream = client.chat.completions.create(
model=os.environ["SUPERBAPI_MODEL"],
messages=[{"role": "user", "content": "Write a haiku about prepaid credit."}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")
# Some upstreams omit usage; handle it only when present.
if chunk.usage:
print("\ntokens:", chunk.usage.total_tokens)
Response headers
These headers have different coverage for JSON chat, video submission and SSE streaming. Account totals are available through GET /v1/credits.
| Header | Meaning |
|---|---|
x-request-id | On every response. Quote it to support to have a specific call looked up. |
x-superbapi-cost-usd | USD charge, on successful non-streaming chat responses and video submits. Not supplied on SSE streams. |
x-superbapi-total-tokens | Billed tokens on successful non-streaming chat responses. Not supplied on video submits or SSE streams. |
x-superbapi-served-model | Served model on successful non-streaming chat responses and video submits. Not supplied as a header on SSE streams. |
retry-after | Seconds to wait when supplied on a 429; not every rate-limit response includes it. |
Errors
Gateway-generated /v1 validation and routing errors use the envelope below. Forwarded upstream failures, video-poll responses and provisioning errors can have different shapes; inspect the HTTP status and body before classifying the failure:
{ "error": { "message": "Unknown model 'gpt-9'. Call GET /v1/models for the ids this key can use.", "type": "api_error", "code": null } }
| Status | What it means | What to do |
|---|---|---|
400 | The request cannot be routed — model is missing, or a video model was sent to chat/completions (use POST /v1/videos). | Fix the request. |
401 | Missing API key or Invalid API key. | Send Authorization: Bearer sk-sbapi-…. |
402 | Out of credit: the wallet is empty, the key's monthly budget is spent, or the account's daily cap is reached. | Top up, or raise the key's budget. |
403 | The key is revoked, expired, outside its route scope, or outside its model allowlist — or the account is suspended or unverified. | Check the key's settings in the workspace. |
404 | No connected provider serves that model id. | Call GET /v1/models for the ids this key can use. |
408 | The request body stalled before it finished arriving. | Correct the connection/body issue before retrying; do not blindly repeat a video submit. |
413 | The request body is larger than the gateway accepts. | Send less. |
429 | Rate limited. A retry-after header may be supplied, in seconds. | Honor retry-after when present; otherwise use bounded exponential backoff. Avoid duplicate video submits. |
502 | Every upstream that serves this model failed. Not charged. | Inspect error.message and the request id. A bounded retry may help transient chat failures; it does not guarantee a different upstream. |
503 | No healthy provider key is available, or an upstream provider account has exhausted its credit. | Inspect error.code and error.message. provider_account_out_of_credit requires the gateway operator to restore upstream credit; topping up your own wallet or repeated retries will not fix it. Use bounded retries only for transient capacity failures. |
Limits & budgets
Cost calculation illustration, not a quote: if a model cost $1 per million input tokens and $3 per million output tokens, a 1,000-input / 500-output request would cost (1,000 ÷ 1,000,000 × $1) + (500 ÷ 1,000,000 × $3) = $0.0025. These hypothetical rates are not SuperbAPI prices. Check the models page for the selected model; cache, reasoning and video pricing can differ.
- Prepaid, not postpaid. Calls draw down a balance you topped up; there is no invoice to be surprised by. Credit is valid for 12 months.
- Per-key budget. Requests are checked against the configured cap and can return
402. Read reported remaining budget fromGET /v1/keyand review actual usage in the workspace. Do not assume a budget is an atomic reservation for concurrent requests. - Per-key model allowlist. A key outside its allowlist is refused with
403before any upstream is called, so it cannot spend. - Failover. When an upstream errors the gateway retries another that serves the same model. You see one request; the retry is not billed twice.
FAQ
Which SDK do I use with SuperbAPI?
The official OpenAI SDK for your language. SuperbAPI is OpenAI-compatible, so you only change the base URL to https://www.superbapi.com/v1 and pass a SuperbAPI key — no SuperbAPI-specific SDK to install.
How do I know what a call cost?
Successful non-streaming chat responses include x-superbapi-cost-usd, x-superbapi-total-tokens and x-superbapi-served-model. Video submits include cost and served-model headers, not token totals. SSE streams do not include these completed-cost headers. GET /v1/credits returns account totals; the workspace shows request usage.
Am I charged when a request fails?
A chat request rejected before any upstream succeeds is not charged. An interrupted SSE stream can still be billed for reported or estimated partial usage. A video render that fails after a successful submit is refunded when a poll observes the failed status; inspect the refund field and workspace usage.
Does SuperbAPI support streaming?
Yes. Send stream: true to POST /v1/chat/completions for a standard SSE stream. The gateway requests upstream usage by default, but a caller can override stream_options.include_usage. Some upstreams omit usage even when requested. When usage is absent, billing uses a length-based estimate; no final usage chunk is synthesized.
SuperbAPI is an independent aggregator and is not affiliated with, endorsed by, or partnered with any model owner. Third-party product names are used nominatively to describe compatibility and routing. Model availability and pricing change over time; use authenticated discovery for configured ids and the models page for advertised rates and capability details. Neither is an uptime guarantee.