API reference
Credits
Two endpoints read what your account and your key have spent, as OpenRouter's do. They cost nothing and only need your key. Use them to warn yourself before a request fails with 402 insufficient_balance.
Balance: GET /v1/credits
What the account of the key has loaded and spent, in dollars. Your balance is total_credits minus total_usage. Try it in the Playground.
curl https://api.libremodel.ai/v1/credits \
-H "Authorization: Bearer $LIBREMODEL_API_KEY"import os
import requests
response = requests.get(
"https://api.libremodel.ai/v1/credits",
headers={"Authorization": f"Bearer {os.environ['LIBREMODEL_API_KEY']}"},
)
print(response.json()["data"])const response = await fetch('https://api.libremodel.ai/v1/credits', {
headers: { Authorization: `Bearer ${process.env.LIBREMODEL_API_KEY}` },
})
const { data } = await response.json()
console.log(data)JSON
{ "data": { "total_credits": 25, "total_usage": 3.4182 } }| Field | Description |
|---|---|
data.total_credits | Everything loaded: top-ups and adjustments. |
data.total_usage | Everything spent, by every key of the account. |
Your key: GET /v1/key
The key you call with, its spending limit and what it spent. Try it in the Playground.
curl https://api.libremodel.ai/v1/key \
-H "Authorization: Bearer $LIBREMODEL_API_KEY"import os
import requests
response = requests.get(
"https://api.libremodel.ai/v1/key",
headers={"Authorization": f"Bearer {os.environ['LIBREMODEL_API_KEY']}"},
)
print(response.json()["data"])const response = await fetch('https://api.libremodel.ai/v1/key', {
headers: { Authorization: `Bearer ${process.env.LIBREMODEL_API_KEY}` },
})
const { data } = await response.json()
console.log(data)JSON
{
"data": {
"label": "sk-libremodel-...a3f9",
"limit": 50,
"limit_remaining": 41.25,
"limit_reset": "monthly",
"usage": 112.4,
"usage_daily": 1.1,
"usage_weekly": 4.35,
"usage_monthly": 8.75,
"is_free_tier": false
}
}| Field | Description |
|---|---|
label | The key, masked. |
limit | Its spending limit, in dollars, per window. null when it has none. |
limit_remaining | What is left of the limit in the current window. null when it has no limit. |
limit_reset | When the limit starts over: daily, weekly, monthly, or null if never. |
usage | Spent by this key, in total. |
usage_daily, usage_weekly, usage_monthly | Spent today, since Monday and since the 1st. |
is_free_tier | true if the account has never loaded credits. |
Amounts are in dollars and windows are in UTC. Spending limits are set per key in API keys.
Errors
Without a valid key both return 401 invalid_api_key. If the totals can't be read for a moment they return 503 upstream_unavailable with Retry-After: retry after that wait.