# API documentation > Everything you need to call LobeBase from your code. ## 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](https://lobebase.com/docs.md) (add `?lang=zh-CN` for Chinese), or request this page with `Accept: text/markdown`. - Index for language models: [/llms.txt](https://lobebase.com/llms.txt). All the documentation and the CLI skill in one file: [/llms-full.txt](https://lobebase.com/llms-full.txt). - The CLI skill: [/cli/SKILL.md](https://lobebase.com/cli/SKILL.md) teaches an agent every `lobebase` command, its JSON output and its exit codes. See [Command line](https://lobebase.com/docs#cli). - 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](https://lobebase.com/docs#errors) 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](https://lobebase.com/login) and create an API key on the [API keys](https://lobebase.com/api-keys) page. The key is shown once, so copy it then. A new organization starts with no credit: add credit on the [Billing](https://lobebase.com/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: ```bash export LOBEBASE_API_KEY="lbk_..." ``` ### 3. Send a request Replace `` with a name from `GET /v1/models` (see [Models](https://lobebase.com/docs#models)). ```bash curl https://api.lobebase.com/v1/chat/completions \ -H "Authorization: Bearer $LOBEBASE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "", "messages": [{ "role": "user", "content": "Hello" }] }' ``` ```python import os from openai import OpenAI client = OpenAI(base_url="https://api.lobebase.com/v1", api_key=os.environ["LOBEBASE_API_KEY"]) response = client.chat.completions.create( model="", messages=[{"role": "user", "content": "Hello"}], ) print(response.choices[0].message.content) ``` ```typescript import OpenAI from 'openai'; const client = new OpenAI({ apiKey: process.env.LOBEBASE_API_KEY, baseURL: 'https://api.lobebase.com/v1' }); const response = await client.chat.completions.create({ messages: [{ content: "Hello", role: 'user' }], model: "", }); console.log(response.choices[0]?.message.content); ``` The Anthropic SDKs use the same base URL, without a `/v1` suffix, and send the key as `x-api-key`: ```bash 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": "", "max_tokens": 256, "messages": [{ "role": "user", "content": "Hello" }] }' ``` ```python import os from anthropic import Anthropic client = Anthropic(base_url="https://api.lobebase.com", api_key=os.environ["LOBEBASE_API_KEY"]) message = client.messages.create( model="", max_tokens=256, messages=[{"role": "user", "content": "Hello"}], ) print(message.content[0].text) ``` ```typescript import Anthropic from '@anthropic-ai/sdk'; const client = new Anthropic({ apiKey: process.env.LOBEBASE_API_KEY, baseURL: 'https://api.lobebase.com' }); const message = await client.messages.create({ max_tokens: 256, messages: [{ content: 'Hello', role: 'user' }], model: '', }); console.log(message.content); ``` ### 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. ```bash curl -N https://api.lobebase.com/v1/chat/completions \ -H "Authorization: Bearer $LOBEBASE_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "", "messages": [{ "role": "user", "content": "Hello" }], "stream": true }' ``` ```python import os from openai import OpenAI client = OpenAI(base_url="https://api.lobebase.com/v1", api_key=os.environ["LOBEBASE_API_KEY"]) stream = client.chat.completions.create( model="", messages=[{"role": "user", "content": "Hello"}], stream=True, ) for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="") ``` ```typescript import OpenAI from 'openai'; const client = new OpenAI({ apiKey: process.env.LOBEBASE_API_KEY, baseURL: 'https://api.lobebase.com/v1' }); const stream = await client.chat.completions.create({ messages: [{ content: "Hello", role: 'user' }], model: "", stream: true, }); for await (const chunk of stream) process.stdout.write(chunk.choices[0]?.delta?.content ?? ''); ``` ### 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](https://lobebase.com/requests) page with its charge. ### Name your app To tell your apps apart on the [Requests](https://lobebase.com/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. ```bash 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": "", "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](https://lobebase.com/requests) page, and the [Usage](https://lobebase.com/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. ```bash 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": "", "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: ```bash 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. ```bash 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. ```bash 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: ```text # 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: ```text # 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 code | Meaning | | --- | --- | | `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](https://lobebase.com/cli/SKILL.md). It lists every command and flag, the stable error codes and how approvals work. To install it as a skill: ```bash 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. | Endpoint | API | Notes | | --- | --- | --- | | `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. ```bash curl https://api.lobebase.com/v1/models \ -H "Authorization: Bearer $LOBEBASE_API_KEY" ``` ```json { "object": "list", "data": [ { "id": "", "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 `:`: 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](https://lobebase.com/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](https://lobebase.com/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. ```json { "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 | Code | Status | Retry | Message | | --- | --- | --- | --- | | `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`. | Status | OpenAI: error.type | Anthropic: error.type | Gemini: 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: | Code | Meaning | | --- | --- | | `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](https://lobebase.com/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](https://lobebase.com/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](https://lobebase.com/docs#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](https://lobebase.com/limits) page and on each key. ### Where to see what you spent Days are cut at UTC midnight. The [Usage](https://lobebase.com/usage) page shows usage by model and day with amounts for a month or a custom range, the [Balance history](https://lobebase.com/billing/balance-history) tab of Billing lists every balance change in a month, and the [Monthly bills](https://lobebase.com/billing/bills) tab lists the monthly bills of a postpaid organization. Each request, its status and its charge are on the [Requests](https://lobebase.com/requests) page, and `GET /v1/requests/{id}` returns the same price detail to your code, for requests made with the calling key only. --- --- name: lobebase-cli description: Operate your LobeBase organization from the terminal with `lobebase`: sign in with an emailed code, list the console's procedures, and call them. Use when an agent needs console data or must act as a signed-in member. --- # lobebase `lobebase` calls the same procedures as the console web app, as the member who signed it in. ## Output and exit codes Every command prints one JSON document with a `callId` (quote it when asking for help): - Success, on stdout, exit 0 (3 for a `--dry-run --exit-code` that found changes, still this envelope): `{ "ok": true, "command", "data", "callId" }` - Failure, on stderr: `{ "ok": false, "error": { "trpcCode", "code", "message", "details" }, "callId" }` | Exit | Meaning | | ---- | ------------------------------------------------------------------------------------------------------------- | | 0 | Done | | 1 | Any other failure (`error.trpcCode` says which) | | 2 | The command line is wrong (including `CODE_REQUIRED`, see below) | | 3 | Success: a `--dry-run --exit-code` found changes (stdout holds `ok: true`) | | 4 | Not signed in, or the session expired: run `auth login` | | 5 | Refused (`FORBIDDEN`): read-only session (`READ_ONLY_SESSION`), Terms not accepted, or role; see `error.code` | | 6 | `APPROVAL_REQUIRED`: a person must approve this exact call, then rerun it | | 7 | The approval was refused (expired, already used, different call, too many pending) | | 8 | The console is unreachable at `--server` | | 9 | `NOT_FOUND`: the target does not exist | | 10 | `CONFLICT`: the state changed or the write was refused as a conflict | ## Signing in ```bash lobebase auth login --email you@company.com # emails a code; on a terminal it asks for it lobebase auth login --email you@company.com --code 123456 lobebase auth login --email you@company.com --write --code 123456 # may change data, 12 hours lobebase auth status --json lobebase auth logout lobebase sessions list # every signed-in CLI of yours on any machine: id, scope, IP and client, expiry; `current` is this one lobebase sessions revoke # end one you do not recognise (needs --write or the browser); --all ends every one but this lobebase auth unlock --token # file store only: clears the lock a crashed command left (code SESSION_STORE_LOCKED shows the token); a lock that is not JSON fails with `SESSION_STORE_LOCK_INVALID` and is left in place; nothing takes a lock over by itself ``` - Any address can sign in; a new address gets an account. Until its owner accepts the Terms of Service and Privacy Policy once in the console (`/welcome`, which also opens an organization of their own unless an invitation to their address is waiting), every command but `auth` fails with `SIGN_UP_TERMS_NOT_ACCEPTED` (exit 5); a new text version asks again. A session is **read-only for 30 days** by default; `--write` gives a session that may change data for **12 hours**. Neither is renewed by use: sign in again when it ends. - Without a terminal and without `--code`, `auth login` sends the code and exits 2 with `CODE_REQUIRED`; run it again with `--code` on the same machine against the same server within 15 minutes. `--code` for a server the code was not asked from is refused with `SIGN_IN_SERVER_MISMATCH`, and without that first step with `SIGN_IN_NOT_REQUESTED`; a first step for an address whose code another server asked for in those 15 minutes is refused with `SIGN_IN_PENDING_ELSEWHERE` (all exit 2, nothing sent). The record stays until it expires, also after a failed request or a finished sign-in. Two sign-ins on one machine take turns on that record; one still waiting after 10 seconds fails with `SIGN_IN_LOCKED` (exit 10). `--code -` reads the code from standard input, keeping it out of shell history. - The CLI follows no redirect: a server answering one fails with `REDIRECT_REFUSED` and nothing is sent on; pass the server's new origin with `--server` if it moved. - `--server ` or `LOBEBASE_SERVER_ORIGIN`; default `https://lobebase.com`. A server that is not this machine must be `https://`. The code prompt (and `CODE_REQUIRED`) names the server the code signs in to; enter the code only if it is the one you meant. - Sessions live in the system credential store. On a machine without one set `LOBEBASE_SESSION_STORE=file` (a `0600` file under `~/.config/lobebase`, or `LOBEBASE_SESSION_STORE_FILE` for another path). Switching stores ends and deletes the session the other store still holds; a damaged file is moved aside to `.corrupt`. ## Organizations, members and keys Every command below takes `--organization `; it may be left out when you belong to exactly one organization. Results are JSON; take the `callId` to quote a call. ```text lobebase organizations list | get lobebase invitations list | show | accept | decline # sign in with the invited address first; signing in does not accept lobebase organizations create # only while you belong to none (a user who signed up through an invitation gets none); ask us for more lobebase organizations rename # owner or admin lobebase members list | invitations | invite --email [--role admin|member] | revoke-invitation | remove | set-role | set-spending-limit --spending-limit lobebase api-keys create --name [--expires-in 1h|1d|7d|30d|90d|180d|1y] [--spending-limit usd] [--period p] [--models a,b*] [--ips cidr,...] [--group ] # the secret appears once, in this result only; --group picks the group (default: the default group) lobebase api-keys list | get | rename | disable | enable | revoke | set-expiry | set-spending-and-rate-limits [...] | transfer --member ``` `models list|prices --group` show the models and prices of a group on offer (the default group without it; by id, an unlisted group is refused `group_not_offered` and a retired one `group_retired`); `models list --key` always uses the key's own group. A key belongs to one group for life; it decides which models the key can call and at what rate (`api-keys get|list` print `group`: id, slug, name). Only groups on offer can be picked. A slug is looked up in `groups list`, so a slug not on offer (unknown, unlisted or retired alike) fails in the CLI with `INVALID_INPUT` (exit 2); the server codes `group_not_offered` (an unlisted or retired id) and `group_not_found` (an unknown id) answer only a `kgr_` id, and a key in a retired group is refused at the gateway with `group_retired`. `api-keys get|list` show `spent`, `held` and `periodStart` for the key's current limit period beside `spendingLimit`. A plain member sees and manages only their own keys (another member's key reads as not found) and cannot list members. Risky (approval, exit 6): `api-keys create|revoke`, `members invite|remove|set-role`, and `api-keys set-expiry|set-spending-and-rate-limits`, `members set-spending-limit` only when they raise a limit or extend or remove the expiry (lowering needs none). Refusals carry a stable `code` such as `ORGANIZATION_FROZEN`, `ROLE_FORBIDDEN`, `NOT_ORGANIZATION_MEMBER`, `OWNER_PROTECTED`, `MEMBER_REMOVED`, `KEY_REVOKED`, `KEY_EXPIRED` (a key at its spending limit is refused per request at admission, so raising the limit revives it). ## Models and prices ```text lobebase groups list [--organization ] # the groups you can pick for a new key: slug, name, description, rate (flat rate, or null when each model is priced on its own) and models; use the slug in api-keys create --group lobebase models list [--organization ] [--group ] # models you can call (inside your organization's model scope), with limits and capabilities lobebase models prices [name] [--at ] [--organization ] [--group ] # your price per model, any upcoming change, and off-peak schedule ``` Prices are what your organization pays (the platform price with your discount applied). A non-member and an unknown organization both answer `unknown_or_not_member`. A model you cannot call yet is not listed. ## Calling procedures ```text lobebase procedures [prefix] [--no-schema] # path, query or mutation, risky or not, input JSON Schema lobebase call [-i '' | -f ] # -f - reads stdin ``` A mutation on a read-only session fails with exit 5. A procedure marked `risky` stops with exit 6 and an `approvalId`, and opens its approval page in the browser unless the server is this machine (`localhost`, `127.0.0.1`, `[::1]`), where it is only printed (`--no-browser` only prints it, `--browser` always opens it). Its JSON opens with `nextStep`: the person approving sees only your messages, never this output, so first start `lobebase approvals wait ` as a background command (exit 0 when approved, exit 7 when rejected or expired), then send them the link and what it approves, then end your turn; its exit wakes you. Once it exits 0, rerun the **identical** call once with `lobebase --approval call ...`. An approval is single use, expires in 10 minutes, and is bound to the exact input and session. ## Balance ```text lobebase balance [--json] # paid, grant, debt, held, spendable, next expiry lobebase balance history [--limit n] [--cursor c] [--json] # credit lot entries, newest first (a lowered charge shows as a `correction` line with a date and amount only; each closed UTC day is one `usage` line, and the first page starts with one `live: true` "usage so far" line that is still changing and never repeats on later pages) lobebase balance lots-outside-top-ups [--organization o] [--limit n] [--cursor c] [--json] # grants and credit from a recorded payment or a returned dispute, newest first, in every state (`available`, `used`, `expired`; a voided lot reads `used`); `balance` lists only credit that can still be spent lobebase billing terms [--organization o] [--json] # the top-up terms in force (version), amount limits ($5-$10,000) and the top-up fee rule lobebase billing quote [--organization o] [--json] # credit, `topUpFee` and amount for an amount; the top-up fee is added on top of the credit lobebase billing top-up --accept-terms [--organization o] [--json] # owners and admins only: records your acceptance and returns a Stripe payment page `url` (always on `https://checkout.stripe.com`; any other link fails with `UNTRUSTED_PAYMENT_LINK`); open it and pay, credit arrives when Stripe confirms (never at this call), the card is saved lobebase billing top-ups list [--status s] [--limit n] [--cursor c] [--json] # online top-ups, newest first: status creating, open, processing, paid, failed, expired lobebase billing top-ups show [--json] # one top-up lobebase billing postpaid terms [--organization o] [--json] # postpaid terms version, whether accepted, the credit limit staff set (0 = not postpaid); refused with POSTPAID_NOT_OFFERED until staff offer postpaid to the organization (default: not offered) lobebase billing postpaid accept --accept-terms [--organization o] # owners and admins; opens no credit, staff set the limit afterwards; POSTPAID_NOT_OFFERED until staff offer postpaid lobebase billing postpaid billing-email [--organization o] [--json] # where monthly invoices are sent (null until set) lobebase billing postpaid set-billing-email [--organization o] # owners and admins; a credit limit needs it; POSTPAID_NOT_OFFERED until staff offer postpaid lobebase billing bills [--limit n] [--cursor c] [--organization o] [--json] # monthly bills, newest first: status pending, issued, no_charge; owners and admins lobebase billing bill [--organization o] [--json] # per-model lines and `hostedInvoiceUrl` (on `https://invoice.stripe.com`), where the invoice is paid lobebase billing auto-top-up terms [--organization o] [--json] # auto top-up terms version, defaults (threshold 5, target 10, monthly cap 200), limits lobebase billing auto-top-up show [--organization o] [--json] # your setting or null; `pausedReason` action_required, card_unusable or terms_changed means it stopped and needs you lobebase billing auto-top-up enable --accept-terms [--threshold usd] [--target usd] [--monthly-cap usd] [--organization o] # owners and admins; risky (approval); an omitted number is filled from the platform default in `terms` before approval: the saved card is charged when the available balance falls under the threshold, never past the cap lobebase billing auto-top-up disable [--organization o] [--json] # off, no approval lobebase billing auto-top-up attempts [--status s] [--limit n] [--cursor c] [--json] # automatic charges, newest first: charging, succeeded, declined (card refused, rests 24 h), needs_authentication (top up once in the console, then enable again), failed ``` Only an organization owner or admin may read these; a plain member gets `ROLE_FORBIDDEN`. ## Requests ```text lobebase requests list [--key ] [--model ] [--app ] [--tag ] [--status completed|partial|failed|rejected] [--since ] [--until ] [--limit n] [--cursor ] [--organization ] lobebase requests show [--organization ] # the id the gateway returned in `x-lobebase-request-id`; also a request the gateway refused ``` Newest first, paged by `nextCursor` (pass it as `--cursor`). Each request has `id`, `createdAt`, `keyId`, `keyName`, `app` (the app the client declared with OpenRouter's `HTTP-Referer` and `X-OpenRouter-Title` or `X-Title` headers: `{ origin, title }`, `null` when it named none; `--app ` filters by the origin), `tags` (what the request sent in `X-Lobebase-Tags`, `null` when none; `--tag feature=summarize` lists only requests with that value), `model`, `status` (`completed`, `partial`, `failed`, or `rejected` for a refusal), `errorCode`, `rejectionReason` (why a refusal was refused, the value of the `x-lobebase-reject-reason` header you already got; null otherwise), `usage` (billed quantity per meter, tokens for chat), `usageSource`, `charged` (what you were charged, net of corrections; `null` when nothing was), `latencyMs` and `ttftMs`. A plain member sees only requests of their own keys (another member's request reads as not found); owners and admins see the whole organization. Refusals are in the list too (an insufficient balance, a limit, a disabled key and so on: `status: rejected`, `charged: "0"`, no usage; the model is the one you sent, when the refusal knew it) and `--status rejected` lists only them; they are kept 30 days, not 90, and a refusal that named no key is for owners and admins only. A burst of refusals can fill the first pages: filter with `--status completed` to skip them. A request is never shown with its channel, provider or an upstream error text, and an upstream account problem reads `upstream_unavailable`. ## Usage ```text lobebase usage summary [--by day|model|key] [--from ] [--to ] [--key ] [--model ] [--organization ] lobebase usage peaks [--from ] [--to ] [--key ] [--organization ] lobebase usage statement --month YYYY-MM [--organization ] # owners and admins lobebase usage export [--kind usage|statement] [--month YYYY-MM] [--by day|model|key] [--detail] [--from] [--to] [--key] [--model] [--out ] lobebase usage cache-savings [--from] [--to] [--key] [--model] [--organization ] lobebase usage by-tag [--from] [--to] [--key] [--model] [--organization ] ``` Days are UTC; the default range is the 30 days ending today. Numbers come from the permanent nightly rollup (still there after the 90 day request window): every result has `coverage.uncoveredDays`, the days not counted yet (today, and yesterday until the nightly job ran), and `coverage.provisionalDays`, days counted but built within 7 days of their end, which a late settlement can still change (final after that), so never read a total as complete without checking both. `summary` rows carry `requests`, `amount` (charged before corrections), `corrections` (signed; negative lowered a charge, attributed by the day made, or the corrected charge's key or model) and `net`; the ranges are at most 366 days (peaks and cache-savings 92) and refuse with `USAGE_RANGE_TOO_LARGE` or `USAGE_RANGE_INVALID`. A plain member sees only their own keys and must pass `--key` to `peaks`; `statement` is `ROLE_FORBIDDEN` for them. `export` follows the `summary` grouping (`--by`, default day): one row per group with `gross_usd`, `corrections_usd`, `net_usd` and a final `total` row, and it returns the CSV in `csv` (or writes `--out`, which never overwrites); more than 10000 groups (a CSV must fit one HTTP response; the total row is extra) is `EXPORT_TOO_LARGE`. `cache-savings` compares each cached read with plain input at your discount and nets the premium of cache writes; `notComparable` tokens (no plain input line to compare with) make it a lower bound. `by-tag` is read live from the charges, not the rollup, so it has no coverage: one row per value of the tag with `requests` and `charged` (net of corrections, never below 0), the requests that did not send the tag last with `value: null`, and `total`; at most 92 days, and a range too slow to add up is `TAG_SPEND_TIMEOUT` (narrow it or pass `--key`). ## Limits ```text lobebase limits show [--organization ] ``` `organization` has `rpmLimit`, `tpmLimit` and `concurrencyLimit` (`null`: the platform default applies). `members` and `keys` each carry `limit` (the spending limit in USD, `null` for none), `period`, `periodStart`, `spent` and `held` for the current period; keys also show their own rate limits, `status` and `tightestSpendingLimitHolder` (`key` or `member`: which of the two spending limits runs out first; `null` when neither is set). Owners and admins see every member and key; a plain member sees only their own member row and keys. `charged` in `requests list|show` is net of corrections, the same amounts `balance history` adds up to. ## Generation task callbacks ```text lobebase callbacks signing-secret [--organization ] # whether there is a secret, its fingerprint, changedAt, previousExpiresAt (the replaced secret still signing); never the secret; owners and admins lobebase callbacks create-signing-secret [--organization ] # makes the organization's secret (whsec_...) and shows it once; refused when one exists; owners and admins; risky lobebase callbacks regenerate-signing-secret [--organization ] [--expire-old-now] # new secret shown once; the old one keeps signing 24 hours (or stops now with the flag); risky ``` The secret is shown only by the command that makes it: store it then; lobebase never shows it again (a lost secret is regenerated). A regenerate rolls the secret like Stripe: for 24 hours both secrets sign, so switch your receiver to the new one at leisure; every callback then carries one signature per secret, new first, so the header may hold several `v1` values and a receiver must accept the callback if any one matches. Use `--expire-old-now` when the old secret leaked: only the new one signs from then on, and a callback that was being sent under the old one and failed is sent again at once with the new one. Both commands answer its `fingerprint` (first 12 hex digits of its SHA-256), which names it in the audit trail without revealing it. A submit may carry a `callback_url` (https, a public address, at most 2048 characters, no credentials in it): Ark's on the native Seedance endpoint, OpenRouter's on the unified `/v1/videos`. The organization needs a signing secret first, or the submit is refused with `invalid_request` on `callback_url`. Answer 2xx within 10 seconds; anything else is retried after 5 s, 5 min, 30 min, 2 h, 5 h and 10 h (twice), then dropped, and 410 drops it at once. Redirects are not followed. Callbacks are best effort: keep reading the task (`GET`) as the truth. - **Native Ark tasks:** each status change (`queued`, `running`, `succeeded`, `failed`, `cancelled`, `expired`) is POSTed once with the JSON the task's `GET` gives (our `gen_` id, a download link when it succeeded), signed as [Standard Webhooks](https://www.standardwebhooks.com): headers `webhook-id` (the same on every retry of one delivery: dedupe on it), `webhook-timestamp` (Unix seconds: refuse a stale one) and `webhook-signature` (`v1,`; while a regenerated secret's predecessor is in its 24-hour window, several space-separated `v1,...` values, new first: accept if any matches). - **Unified video format (`/v1/videos`):** only the end of a generation task is sent, as OpenRouter sends it: `{ "type": "video.generation.", "created_at", "data" }`, where `data` holds `id`, `status`, `generation_id` and `model`, plus `unsigned_urls` (the content path, which redirects to a fresh link) and `usage.cost` when the generation task completed, or `error` when it did not; fetch the video through `unsigned_urls` or `GET /v1/videos/{id}`, as the body carries no signed link. Headers: `X-LobeHub-Idempotency-Key: -` (the same on every retry: dedupe on it) and `X-LobeHub-Signature: t=,v1=,">` (during a 24-hour regenerate window `t=,v1=,v1=`: accept if any `v1` matches), keyed by the secret string exactly as shown (prefix included). A receiver written for OpenRouter's `X-OpenRouter-*` headers verifies ours once the header names are changed. - **Continuing a job:** on Gemini Omni 1.2 Flash (the one model that takes it), `previous_job_id` names a completed, not deleted job of the same organization and model to edit or extend: the prompt says which ("make the boat red", "continue the scene"), and `provider.options["google-vertex"].task` is refused beside it. It is a new job, held and charged on its own, including the previous clip it reads back as input; any other `previous_job_id` is refused with one `invalid_request` answer on `previous_job_id`. ## Inbox and notification settings ```bash lobebase inbox list [--tab all|system|models|changelog] [--organization o] # newest 100: id (inb_ an organization notice, ann_ a lobebase announcement), source, category, tab, title, body, linkUrl, date, editedAt, read lobebase inbox unread [--organization o] # unread in all and per tab: the console bell badge lobebase inbox read [--organization o] | read-all [--organization o] # needs --write lobebase notification-settings get [--organization o] # every category: delivery, allowed, scope (member: this organization; user: every organization) lobebase notification-settings set [--organization o] # needs --write; audited ``` - Organization notices (`billing`, `balance`, `usage`) are the messages lobebase mails owners and admins (and the member a limit names); each lands in the Inbox too. `billing` (auto top-up results) is locked to Inbox and email; `balance` and `usage` may be Inbox only or off, per organization. - Announcements reach every console user in every organization, in the Inbox only. `incidents`, `price_changes` and `model_deprecations` cannot be turned off (`NOTIFICATION_DELIVERY_NOT_ALLOWED`); `models` and `product_updates` can. An announcement edited after you read it is unread again. - `--organization` is optional when you belong to one organization or none (then only announcements show). ## Profile picture ```bash lobebase avatar set # a PNG or WebP of at most 256 KB; returns { image } (its stored path); needs --write lobebase avatar clear # remove it; the console shows your initials again; needs --write ``` - The picture shows next to your name in the console (sidebar, members, limits). Square, 256 px is best; the Account page crops any image to that. ## Passkeys ```bash lobebase passkeys list # registered passkeys: id, name, deviceType, backedUp, createdAt; read-only ``` - Registering or removing a passkey is a web page action (Account) that needs a sign-in within the last 10 minutes; the CLI cannot do either. Passkeys approve risky actions only, never sign in.