Open API

Query Your Balance with an API Key

Query the remaining quota of the current key with an sk- API key: GET /v1/user/balance returns is_active / balance / unit, and GET /v1/credits returns OpenRouter-style total_credits / total_usage, compatible with third-party clients such as cc-switch.

Use an sk- API key to query the remaining quota and availability of that key. It is intended for third-party clients that display a balance in their UI, or for scripts that monitor the balance.

These endpoints are read-only: they are not billed and do not consume quota. Authentication only validates the key itself, so you can still read the remaining quota even after the quota is used up and business requests would be rejected (in that case is_active is false).


1. Endpoint overview

EndpointClient format it matchesReturns
GET /v1/user/balancecc-switch generic balance templateis_active / balance / unit, plus used / total when the key has a total quota
GET /user/balanceSame as above, for a Base URL without /v1Identical to the row above
GET /v1/creditsOpenRouter styledata.total_credits / data.total_usage
ItemValue
Base URLhttps://api.lmuai.com
AuthenticationAuthorization: Bearer <sk-...>
Response formatJSON
Login requiredNo, the API key is enough

/user/balance is an alias of /v1/user/balance (used when a client's Base URL is set without /v1). /v1/credits has no root-path alias and must include /v1.


2. Which balance is returned

balance is not necessarily the account wallet balance — it is the remaining quota actually available to the current key, resolved in this order:

OrderKey situationWhat balance means
1The key has its own total quotaThat key's remaining quota (total - used)
2The key belongs to a subscription groupThe subscription's remaining quota (unit is requests when counted by request)
3Neither of the aboveThe account wallet balance

is_active additionally indicates whether the key can currently be used for business calls: it is true when the key is active, not expired and its total quota is not used up; it is also false when the key belongs to a subscription group with no active subscription.


3. GET /v1/user/balance

GET /v1/user/balance HTTP/1.1
Host: api.lmuai.com
Authorization: Bearer sk-xxxxxxxx

Response — wallet balance mode (key has no quota and is not in a subscription group):

{
  "is_active": true,
  "balance": 1575.13,
  "unit": "USD"
}

Response — the key has a total quota (in this case used and total are also returned):

{
  "is_active": true,
  "balance": 6,
  "unit": "USD",
  "used": 4,
  "total": 10
}

Response — subscription group counted by request:

{
  "is_active": true,
  "balance": 842,
  "unit": "requests"
}

Response fields

FieldTypeDescription
is_activeboolWhether the key can currently be used for business calls
balancenumberRemaining quota; see unit for the unit
unitstringUSD (default), or requests for subscription groups counted by request
usednumberOnly present when the key has a total quota — quota already used by this key
totalnumberOnly present when the key has a total quota — this key's total quota

used / total only have meaningful values in key-quota mode. Wallet balance and subscription modes do not return these fields — use balance and do not derive it from total - used.


4. GET /v1/credits

OpenRouter-style balance format; clients display the remaining quota as total_credits - total_usage.

GET /v1/credits HTTP/1.1
Host: api.lmuai.com
Authorization: Bearer sk-xxxxxxxx

Response:

{
  "data": {
    "total_credits": 20,
    "total_usage": 4
  }
}
FieldTypeDescription
data.total_creditsnumberUsed + remaining, so that total_credits - total_usage equals exactly the remaining quota
data.total_usagenumberQuota already used

total_credits is a composite value of "used + remaining" — it is not the literal quota limit. In wallet balance mode total_usage is 0 and total_credits equals the balance; when the quota is used up the remaining quota is clamped to 0, so total_credits then equals the amount used.


5. Configuring third-party clients

Client / scenarioHow to configure
cc-switch generic balance templateBase URL https://api.lmuai.com (without /v1) or https://api.lmuai.com/v1 (with /v1) — both work
OpenRouter-compatible clients (Kelivo, RikkaHub, etc.)Base URL https://api.lmuai.com/v1; the client will request /v1/credits
Your own scriptCall /v1/user/balance directly — its fields are easier to read
curl -s https://api.lmuai.com/v1/user/balance \
  -H "Authorization: Bearer sk-xxxxxxxx"

6. Error responses

Balance queries use the gateway's standard API key authentication, so errors come back in the same format as other API calls. When the request has no key:

{
  "code": "API_KEY_REQUIRED",
  "message": "API key is required in Authorization header (Bearer scheme), x-api-key header, or x-goog-api-key header"
}
Status codecodeScenario
200—Normal response; an exhausted quota, an expired key or a missing subscription also returns 200, with is_active: false meaning the key cannot be used
401API_KEY_REQUIREDThe request has no API key
401INVALID_API_KEYThe key does not exist or is malformed
401API_KEY_DISABLEDThe key has been disabled
403ACCESS_DENIEDThe key has an IP allowlist / blocklist and the current IP is not allowed

For general errors, see Error Codes.


7. Difference from "Export Usage Details"

The balance endpoints in this pageExport Usage Details
Authenticationsk- API keyAccount and password exchanged for a JWT
GranularityRemaining quota of the current keyAccount-level, per-request details
Use caseDisplaying the balance in a client, balance monitoringBilling export, reconciliation, feeding a BI system

GET /v1/usage sits between the two: it also takes an sk- key and returns today's / cumulative usage statistics and quota information for the current key, with more detailed fields.

Last updated:

京ICP备2020034311号-7

On this page