API documentation

Everything you need to call LobeBase from your code.
Base URL
https://api.lobebase.com/v1

For AI agents

Point your agent at these instead of this page. None needs a sign-in, and English is the reference text.

  • This page as Markdown: /docs.md (add ?lang=zh-CN for Chinese), or request this page with Accept: text/markdown.
  • Index for language models: /llms.txt. All the documentation and the CLI skill in one file: /llms-full.txt.
  • The CLI skill: /cli/SKILL.md teaches an agent every lobebase command, its JSON output and its exit codes. See Command line.
  • The API: OpenAI-compatible base URL https://api.lobebase.com/v1, authenticated with Authorization: Bearer $LOBEBASE_API_KEY. GET /v1/models lists the models your key can call.
  • Every response carries an x-lobebase-request-id header, and the error codes say which failures are worth retrying.

Quick start

LobeBase relays the APIs of the model creators. If your code already talks to OpenAI, Anthropic or Gemini, switching takes only a new base URL and a LobeBase API key.

1. Get a key

Sign in and create an API key on the API keys page. The key is shown once, so copy it then. A new organization starts with no credit: add credit on the Billing page before the first request.

2. Base URL and authentication

The base URL is https://api.lobebase.com. Send the key as a bearer token: Authorization: Bearer YOUR_KEY. The headers the official SDKs use are accepted too: x-api-key (Anthropic), x-goog-api-key (Gemini) and api-key, and Gemini’s ?key= query parameter. A request that carries two different keys is refused with 401.

The examples below read the key from the LOBEBASE_API_KEY environment variable:

Shell
export LOBEBASE_API_KEY="lbk_..."

3. Send a request

Replace <model> with a name from GET /v1/models (see Models).

curl https://api.lobebase.com/v1/chat/completions \
  -H "Authorization: Bearer $LOBEBASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model>",
    "messages": [{ "role": "user", "content": "Hello" }]
  }'

The Anthropic SDKs use the same base URL, without a /v1 suffix, and send the key as x-api-key:

curl https://api.lobebase.com/v1/messages \
  -H "x-api-key: $LOBEBASE_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model>",
    "max_tokens": 256,
    "messages": [{ "role": "user", "content": "Hello" }]
  }'

Streaming

Set "stream": true and the response arrives as server-sent events, in the shape of the API you called. -N stops curl from buffering them.

curl -N https://api.lobebase.com/v1/chat/completions \
  -H "Authorization: Bearer $LOBEBASE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<model>",
    "messages": [{ "role": "user", "content": "Hello" }],
    "stream": true
  }'

Request ids

Every response carries an x-lobebase-request-id header. Quote it when you contact support; the same request is listed on the Requests page with its charge.

Name your app

To tell your apps apart on the Requests page, send the same headers OpenRouter reads: HTTP-Referer with your app's URL (only its origin is kept) and, optionally, X-Title (or X-OpenRouter-Title) with its name. A localhost or private address counts only together with a title. The headers are a label: they never change routing or price, are not passed to the model provider, and a malformed one is ignored.

App headers
curl https://api.lobebase.com/v1/chat/completions \
  -H "Authorization: Bearer $LOBEBASE_API_KEY" \
  -H "HTTP-Referer: https://myapp.example" \
  -H "X-Title: My App" \
  -H "Content-Type: application/json" \
  -d '{ "model": "<model>", "messages": [{ "role": "user", "content": "Hello" }] }'

Tag your requests

To see what each feature of your product costs, send up to 5 tags as a JSON object in the X-Lobebase-Tags header. A tag name uses lowercase letters, digits, - and _ and starts with a letter (at most 64 characters); a value is a string of 1 to 128 bytes with no control characters, and the whole header is at most 1 KiB. Each request is listed with its tags on the Requests page, and the Usage page adds up what each value of a tag was charged. Unlike the app headers, a malformed tag header is refused with 400, so a typo never goes uncounted. Tags are kept with the charge; they never change routing or price and are not passed to the model provider.

Request tags
curl https://api.lobebase.com/v1/chat/completions \
  -H "Authorization: Bearer $LOBEBASE_API_KEY" \
  -H 'X-Lobebase-Tags: {"feature":"summarize","env":"prod"}' \
  -H "Content-Type: application/json" \
  -d '{ "model": "<model>", "messages": [{ "role": "user", "content": "Hello" }] }'

Rate limits

Each organization may make 600 requests and use 2M tokens per minute, with 50 requests running at once, unless raised for your organization. Over a limit the gateway answers 429 with a Retry-After header. GET /v1/key shows the limits that apply to the key you call it with.

Command line

The lobebase command line is the console in your terminal: balance, usage, requests, models and prices, limits, billing and API keys. Every command prints JSON, so scripts and AI agents can drive it. It does not call models; use the API for that.

Install

Node.js 22.13 or newer is required. Install it globally, or run it without installing:

Install
npm i -g @lobebase/cli
lobebase --help

# or run it without installing
bunx @lobebase/cli --help
npx @lobebase/cli --help

Sign in

lobebase auth login --email you@company.com emails a six-digit code; type it at the prompt, or pass it with --code. Without a terminal the first call only sends the code and exits with 2. A session is read-only for 30 days; --write opens a session that may change data for 12 hours, and risky changes such as creating an API key still wait for a person to approve them. A new address must accept the Terms of Service once in the console before any command but auth works.

Sign in
lobebase auth login --email you@company.com
# a 6-digit code is emailed to you; type it at the prompt, or pass it:
lobebase auth login --email you@company.com --code 123456
lobebase auth status

Commands

A few of the commands; every one prints JSON. Add --organization with an organization id when you belong to more than one. lobebase --help and, for example, lobebase billing --help list the rest, and the CLI skill describes them all.

Commands
lobebase balance                       # credit, holds and what you may spend now
lobebase models list                   # models you can call, with limits and capabilities
lobebase models prices                 # your price per million tokens, per model
lobebase requests list --status failed --limit 20
lobebase usage summary --by model --from 2026-11-01
lobebase limits show                   # rate limits and spending limits
lobebase billing quote 50              # what a $50 top-up costs, fee included
lobebase api-keys list
lobebase procedures                    # every console procedure with its input schema

Output and exit codes

Every command prints one JSON document with a callId; quote it when you ask for help. A success goes to stdout and exits 0:

Output
# lobebase balance
{
  "command": "balance",
  "data": {
    "spendable": "0",
    "creditLimit": "0",
    "display": { "spendable": "$0.00", "held": "$0.00", "owed": "$0.00", "remainingCredit": "$0.00" },
    "everCredited": false,
    "held": "0",
    "lots": [],
    "nextExpiry": null,
    "owed": "0",
    "remainingCredit": "0"
  },
  "ok": true,
  "callId": "call_aa915152-83c4-4f2a-8dd2-cc7755d8c47b"
}

A failure goes to stderr as ok: false with a stable error.code to branch on, and exits with a code that says what kind of failure it was:

Error output
# lobebase requests list: stderr, exit code 5
{
  "error": {
    "code": "SIGN_UP_TERMS_NOT_ACCEPTED",
    "message": "Accept the Terms of Service and Privacy Policy in the console before you continue: https://lobebase.com/welcome",
    "trpcCode": "FORBIDDEN"
  },
  "ok": false,
  "callId": "call_5c85ccfa-b5c8-4105-a74a-8a438c831633"
}
Exit codeMeaning
0
Done.
1
Any other failure. error.trpcCode says which.
2
The command line is wrong, or a sign-in code is still needed (CODE_REQUIRED).
4
Not signed in, or the session expired. Run lobebase auth login.
5
Refused. A read-only session tried to change data, the Terms of Service have not been accepted yet, or your role may not do this. error.code says which.
6
A person must approve this exact call, then you run it again. The failure names the approval page.
7
The approval was refused: it expired, was already used, or belonged to a different call.
8
The console could not be reached.
9
The target does not exist.
10
The state changed, or the write was refused as a conflict.

Use it from an agent

Give your coding agent /cli/SKILL.md. It lists every command and flag, the stable error codes and how approvals work. To install it as a skill:

Install the skill
mkdir -p .claude/skills/lobebase
curl -o .claude/skills/lobebase/SKILL.md https://lobebase.com/cli/SKILL.md

Endpoints and protocols

The gateway answers in the official shape of the API you call: paths, request and response bodies, streaming events, usage fields and error bodies follow that API, so its SDKs work unchanged. Which API family a call speaks is decided by its path.

EndpointAPINotes
POST /v1/chat/completions
OpenAI
Chat Completions, streaming or not.
POST /v1/responses
OpenAI
Responses.
POST /v1/messages
Anthropic
Messages, streaming or not.
POST /v1/messages/count_tokens
Anthropic
Token counting for Messages requests.
POST /v1beta/models/{model}:generateContent
Gemini
Also under /v1/models/{model}:generateContent.
POST /v1beta/models/{model}:streamGenerateContent
Gemini
Always streams. Also under /v1/models/{model}:streamGenerateContent.
POST /v1/images/generations
OpenAI
Image generation.
POST /v1/images/edits
OpenAI
Image editing (multipart upload).
POST /v1/systemone
LobeBase
TypeSafe System One decision models: one JSON answer.
GET /v1/models
OpenAI, Anthropic, Gemini
The models your key can call.
GET /v1/models/{model}
OpenAI, Anthropic, Gemini
One model.
GET /v1/key
LobeBase
The calling key: status, expiry, spending limit and rate limits.
GET /v1/requests/{id}
LobeBase
One request made with the calling key: status, usage, charge and price detail. A request of another key is 404.

A model works on the endpoints its provider supports. Calling a model on an endpoint it does not serve is refused with 404 (operation_unsupported). Request bodies must not be compressed.

Models

Put the model name in the model field of the request (for Gemini, in the path). Names are the creators’ own, written exactly as listed.

List the models your key can call

GET /v1/models returns the models this key can call right now: on sale, priced, allowed for your organization and allowed for the key. A model that is not in the list is refused as not found or not allowed.

List models
curl https://api.lobebase.com/v1/models \
  -H "Authorization: Bearer $LOBEBASE_API_KEY"
Response
{
  "object": "list",
  "data": [
    { "id": "<model>", "object": "model", "created": 1700000000, "owned_by": "lobebase" }
  ]
}

The list takes the shape of the SDK that asks: Anthropic’s when the request carries anthropic-version or x-api-key, Gemini’s under /v1beta/models or with x-goog-api-key, and OpenAI’s otherwise.

Variants

A model may also be sold as a variant, written <model>:<variant>: the same model served from a different source under its own name. Use the full name, colon included. A variant is available only to organizations it has been enabled for, and then appears in /v1/models like any other model.

Prices

Every base model on sale, with its context window and price per million tokens, is on the prices page; a variant uses its base model’s price items and its own rate, so its price can differ from the base model’s. Signed in, the Models page shows the price your organization pays.

Errors

Errors use the official error shape of the API you called, with the status and, for OpenAI-shaped bodies, the error.code shown below each status. OpenAI-shaped bodies also carry lobebase.request_id, Anthropic-shaped ones request_id. The request id is always in the body field named above; for many errors it is also appended to the message, because most clients print only the message.

Error body
{
  "error": {
    "code": "insufficient_quota",
    "message": "The organization does not have enough balance ... (request id: req_...)",
    "param": null,
    "type": "insufficient_quota"
  },
  "lobebase": { "request_id": "req_..." }
}

A request the gateway refuses before it reaches a model also carries the header x-lobebase-reject-reason with the reason shown under its code. A refused request is not charged and, when it can be attributed to your organization, is listed on the Requests page with that reason. Paths and methods the gateway does not serve get a plain 404 or 405 with no record. The Code column is what the Requests page and GET /v1/requests/{id} show as the request’s error code.

Errors the gateway answers

CodeStatusRetryMessage
caller_key_invalid
reason: key_invalid
401
error.code: invalid_api_key
No.
The API key is not valid.
caller_key_revoked
reason: key_revoked
401
error.code: invalid_api_key
No.
This API key has been revoked.
caller_key_disabled
reason: key_disabled
401
error.code: invalid_api_key
No.
This API key is disabled.
caller_key_expired
reason: key_expired
401
error.code: invalid_api_key
No.
This API key has expired.
caller_ip_not_allowed
reason: ip_not_allowed
403
No.
This API key cannot be used from this address.
caller_invalid_request
reason: invalid_request
400
No.
The request is not valid.
caller_payload_too_large
reason: payload_too_large
413
No.
The request body is too large.
caller_upstream_rejected
400 (or the upstream’s own 4xx status)
No.
Says what is wrong in the provider’s own words, with provider-identifying details removed.
policy_group_retired
reason: group_retired
403
No.
This API key is no longer available. Create a new key to continue.
policy_model_not_allowed
reason: model_not_allowed
403
error.code: model_not_found
No.
This API key or organization is not allowed to use this model.
policy_model_not_found
reason: model_not_found
404
error.code: model_not_found
No.
The model does not exist.
policy_model_no_price
reason: model_no_price
404
No.
This model is not available for sale.
policy_service_tier_unsupported
reason: service_tier_unsupported
400
No.
This service tier is not available.
policy_tool_unsupported
reason: tool_unsupported
400
No.
This tool is not available.
policy_input_modality_unsupported
reason: input_modality_unsupported
400
No.
This request carries audio or video input, which is not available for this model.
policy_output_modality_unsupported
reason: output_modality_unsupported
400
No.
This request asks for audio or image output, which is not available.
policy_no_route
reason: no_route
503
Yes. Wait for Retry-After.
No route is available for this model right now.
policy_operation_unsupported
reason: operation_unsupported
404
No.
This model is not supported on this endpoint.
policy_organization_frozen
reason: organization_frozen
403
No.
This organization is frozen.
policy_organization_closed
reason: organization_closed
403
No.
This organization is closed.
policy_key_rate_limited
reason: key_rate_limited
429
error.code: rate_limit_exceeded
Yes. Wait for Retry-After.
Too many requests.
policy_organization_rate_limited
reason: organization_rate_limited
429
error.code: rate_limit_exceeded
Yes. Wait for Retry-After.
Too many requests.
policy_spending_limit_exceeded
reason: spending_limit_exceeded
429
error.code: insufficient_quota
Only when funds are held by running requests: then Retry-After says when to retry.
A spending limit on this API key or organization has been reached.
policy_insufficient_funds
reason: insufficient_funds
402
error.code: insufficient_quota
Only when funds are held by running requests: then Retry-After says when to retry.
The organization does not have enough balance for this request.
upstream_unavailable
502 (or the upstream’s own 5xx status)
503
Yes. Retry-After is sent when the provider gave a delay.
The upstream service returned an error.
upstream_timeout
504
Yes, after a short wait.
The upstream service did not respond in time.
upstream_unreachable
502 (or the upstream’s own 5xx status)
Yes. Retry-After is sent when the provider gave a delay.
The upstream service returned an error.
upstream_rate_limited
429
error.code: rate_limit_exceeded
Yes. Retry-After is sent when the provider gave a delay.
The upstream service is rate limited. Please retry later.
upstream_bad_response
502
Yes, after a short wait.
The upstream service returned an error.
upstream_first_content_timeout
504
Yes, after a short wait.
The upstream service did not respond in time.
conversion_failed
500
No.
The gateway failed to process the request.
gateway_response_scrub_failed
502
No.
The upstream service returned an error.
gateway_overloaded
reason: gateway_overloaded
503
Yes. Wait for Retry-After.
The gateway is busy.
gateway_dependency_unavailable
reason: dependency_unavailable
503
Yes. Wait for Retry-After.
A required service is unavailable. Please retry.
gateway_not_ready
503
Yes. Wait for Retry-After.
The gateway is starting up.
gateway_shutdown
503
Yes. Wait for Retry-After.
The gateway is shutting down.
gateway_internal
500
502 (or the upstream’s own 5xx status)
No.
The gateway failed to process the request.

How each API shows an error

The same answer is spelled differently in each API. The status is the HTTP status. OpenAI-shaped bodies have error.type and error.code (null unless a code is shown), Anthropic-shaped bodies only error.type, and Gemini-shaped bodies error.status beside an error.code that is the HTTP status. A spending limit and an insufficient balance both carry error.code insufficient_quota in an OpenAI-shaped body: tell them apart by the status, 429 for a limit and 402 for the balance. Anthropic and Gemini have no such code, so branch on the status. Gemini has no payment status; its error.status for 402 is UNKNOWN.

StatusOpenAI: error.typeAnthropic: error.typeGemini: error.status
400
invalid_request_error
invalid_request_error
INVALID_ARGUMENT
401
invalid_request_error
error.code: invalid_api_key
authentication_error
UNAUTHENTICATED
402
insufficient_quota
error.code: insufficient_quota
billing_error
UNKNOWN
403
model not allowed
invalid_request_error
error.code: model_not_found
permission_error
PERMISSION_DENIED
403
other reasons
invalid_request_error
permission_error
PERMISSION_DENIED
404
model not found
invalid_request_error
error.code: model_not_found
not_found_error
NOT_FOUND
404
other reasons
invalid_request_error
not_found_error
NOT_FOUND
413
invalid_request_error
request_too_large
INVALID_ARGUMENT
429
rate limit
requests
error.code: rate_limit_exceeded
rate_limit_error
RESOURCE_EXHAUSTED
429
spending limit
insufficient_quota
error.code: insufficient_quota
rate_limit_error
RESOURCE_EXHAUSTED
500
server_error
api_error
INTERNAL
502
server_error
api_error
UNAVAILABLE
503
server_error
overloaded_error
UNAVAILABLE
504
server_error
timeout_error
DEADLINE_EXCEEDED

Once a stream has started its status cannot change. A failure after that ends the stream with an error event in the API’s own format, carrying the request id, and the request is recorded with one of these codes:

CodeMeaning
caller_disconnected
The client closed the connection before the response ended. When the gateway cancelled the upstream call, you are charged for the output delivered and for the input the provider had already reported; when it could not, you are charged for the full usage.
upstream_interrupted
The connection to the model provider broke while the response was streaming. You are charged for the output delivered.
upstream_stream_error
The model provider reported an error inside a stream that had started. You are charged for the output delivered.
upstream_idle_timeout
A stream that had started went silent for too long and was ended. You are charged for the output delivered.
gateway_settlement_failed
Recording the request on our side failed after the response was sent. The response itself was not affected.

Billing and balance

What a request costs

A model has an official price per fee item, such as uncached input, cached input and output, per million tokens, in USD. You pay the official price times your organization’s rate; by default the rate is 1.00, so you pay the official price. Staff can set a different rate for an organization. A request is priced at the prices in force when it started, and a model whose creator publishes peak and off-peak prices is priced by the period the request started in. Cached input is charged at the cache price only when the provider reports a cache hit. See prices.

Balance and holds

Your balance is the credit your organization has left. When a request arrives the gateway holds an estimate of its cost. For a text request that is the estimated input plus the largest output it may produce (max_tokens, or the model’s maximum when you set none); an image request holds the most expensive combination of its price items, bounded by the output limit and the number of images you ask for, and a /v1/systemone request holds the model’s whole context window of input. Token counting (/v1/messages/count_tokens) holds nothing and costs nothing. A request is admitted only if the hold fits in what you may spend now, which is the balance minus the holds of requests still running (plus the credit limit of a postpaid organization). Otherwise it is refused with 402 (error.code insufficient_quota in an OpenAI-shaped body, billing_error in an Anthropic one); add credit, or lower the output limit (max_tokens) or the number of images you ask for.

When the response ends, the gateway prices the usage the provider reported, releases the hold and charges the real amount. The charge is usually below the hold. A request already admitted is always settled, even when it ran over its hold.

What is not charged

A request the gateway refuses costs nothing. A request that fails with no output costs nothing. If the client disconnects from a stream, you pay for the output delivered and for the input the provider had already reported when the gateway could cancel the call at the provider; when it could not, you pay the usage the provider reports. If a model call fails and the gateway retries elsewhere, the failed attempt is not charged to you.

Adding credit

Organization owners and admins add credit with a card on the Billing page, which shows the credit, the top-up fee added to the payment and the total before you pay. The fee is not credited and not refundable. Paid credit expires twelve months after the payment day, at the end of that UTC day. Auto top-up can add credit by itself when what you may spend falls below a threshold you set. An organization approved for postpaid use pays a monthly bill instead.

Limits you can set

A key and each member can carry a spending limit per day, week, month or in total. A request that would pass the limit is refused with 429; the Errors section shows what each API puts in the body (an OpenAI-shaped body carries error.code insufficient_quota), and the Requests page lists it as spending_limit_exceeded. Set limits on the Limits page and on each key.

Where to see what you spent

Days are cut at UTC midnight. The Usage page shows usage by model and day with amounts for a month or a custom range, the Balance history tab of Billing lists every balance change in a month, and the Monthly bills tab lists the monthly bills of a postpaid organization. Each request, its status and its charge are on the Requests page, and GET /v1/requests/{id} returns the same price detail to your code, for requests made with the calling key only.

Every leading model. One API key.

Sign in, add credit and change one line of config. Pay for what you use, no subscription.

Get an API key