Usage and logs
Lookup endpoints you can call with just an API key (sk-…) — the key's quota and expiry, its recent usage records, and the legacy OpenAI-format quota endpoints.
The endpoints below only need an API key; you don't have to sign in to the console. They suit scripts, monitoring and your own programs that check balance and usage. They come from new-api, the open-source gateway CodaAPI is built on, follow the upstream version, and their fields may change between versions. The console's usage logs are authoritative for charges and usage.
| Method and path | What it returns |
|---|---|
GET /api/usage/token/ |
This key's quota, expiry and model limits; optionally the account balance |
GET /api/log/token |
This key's recent usage records |
GET /v1/dashboard/billing/subscription |
Total quota in the legacy OpenAI format |
GET /v1/dashboard/billing/usage |
Used quota in the legacy OpenAI format |
Console endpoints that need a signed-in session are out of scope for this page.
Request headers
| Name | Required | Description |
|---|---|---|
Authorization |
Yes | Bearer sk-…. These endpoints only read this header; x-api-key, x-goog-api-key and ?key= don't work. /api/usage/token/ requires the Bearer prefix |
A few things to note:
- If the key has an IP whitelist, these endpoints also only accept addresses on it; other addresses get 403.
/api/usage/token/and/api/log/tokenhave a stricter rate limit, counted per source IP; above it they return 429. Don't poll them frequently; cache the result for a while.- After a key expires or its quota runs out, you can still query it with
/api/usage/token/and/api/log/token; a disabled key can't./v1/dashboard/billing/*, like model calls, only accepts Enabled keys.
Quota units
The gateway keeps its accounts in "quota points". The first two endpoints return raw quota points; /v1/dashboard/billing/* returns numbers converted according to the site's display setting. The conversion uses a few fields of the public GET /api/status endpoint (see Status and pricing):
quota_display_type |
Amount shown in the console | Number returned by /v1/dashboard/billing/* |
|---|---|---|
USD |
quota points ÷ quota_per_unit, in US dollars |
Same |
CNY |
quota points ÷ quota_per_unit × usd_exchange_rate, in yuan |
Same |
CUSTOM |
quota points ÷ quota_per_unit × custom_currency_exchange_rate, shown with custom_currency_symbol |
quota points ÷ quota_per_unit, not multiplied by the custom rate |
TOKENS |
Raw quota points | Raw quota points |
quota_per_unit is the number of quota points per US dollar. The site sets the display type and may change it, so read these values from /api/status each time rather than hard-coding them.
Key quota
GET https://codaapi.com/api/usage/token/
Returns this key's own quota, expiry and model limits. No request parameters. Note the trailing / in the address.
curl
curl https://codaapi.com/api/usage/token/ \
-H "Authorization: Bearer $OPENAI_API_KEY"
Python (pip install requests)
import os
import requests
BASE = "https://codaapi.com"
headers = {"Authorization": f"Bearer {os.environ['OPENAI_API_KEY']}"}
usage = requests.get(f"{BASE}/api/usage/token/", headers=headers, timeout=20).json()["data"]
status = requests.get(f"{BASE}/api/status", timeout=20).json()["data"]
# Convert quota points to the amount shown in the console; see "Quota units" above
amount = usage["total_available"] / status["quota_per_unit"]
if status["quota_display_type"] == "CNY":
amount *= status["usd_exchange_rate"]
elif status["quota_display_type"] == "CUSTOM":
amount *= status["custom_currency_exchange_rate"]
print("Unlimited quota" if usage["unlimited_quota"] else f"This key has {amount:.2f} left")
Response
{
"code": true,
"message": "ok",
"data": {
"object": "token_usage",
"name": "my-server",
"total_granted": 5000000,
"total_used": 1234567,
"total_available": 3765433,
"unlimited_quota": false,
"model_limits": {"gpt-5.4-mini": true},
"model_limits_enabled": true,
"expires_at": 0,
"user_quota": {"total_available": 9876543, "total_used": 2345678}
}
}
The numbers are only examples. Note that success is marked by "code": true, not "success": true.
| Field | Description |
|---|---|
data.name |
The key's name |
data.total_granted |
The key's total quota (used + remaining), in quota points |
data.total_used |
Quota points this key has used |
data.total_available |
Quota points this key has left |
data.unlimited_quota |
true means Unlimited Quota: the key itself has no cap, the three numbers above don't say how much you can spend, and the account balance is the real limit |
data.model_limits_enabled, data.model_limits |
Whether Model Limits is on, and the models allowed |
data.expires_at |
Expiration time (Unix timestamp, seconds); 0 means it never expires |
data.user_quota |
The account's remaining (total_available) and used (total_used) quota points. Only present when the key has Allow querying user quota turned on |
Allow querying user quota is under Advanced Settings when you edit a key in the console (API Keys), and it's on by default for new keys. If user_quota is missing from the response, turn it on there. With this switch on, anyone holding the key can see your whole account's balance, so you may want it off for keys you give to others.
Usage records
GET https://codaapi.com/api/log/token
Returns this key's recent usage records, newest first, up to 1000. No request parameters, no paging and no time filter; to filter by time or model, or to export, use the console's usage logs. Records older than the retention period in the privacy policy are deleted automatically and can't be queried.
curl
curl https://codaapi.com/api/log/token \
-H "Authorization: Bearer $OPENAI_API_KEY"
Python (pip install requests)
import os
import requests
response = requests.get(
"https://codaapi.com/api/log/token",
headers={"Authorization": f"Bearer {os.environ['OPENAI_API_KEY']}"},
timeout=20,
)
for log in response.json()["data"][:10]:
print(log["created_at"], log["model_name"], log["prompt_tokens"], log["completion_tokens"], log["quota"])
Response
{
"success": true,
"message": "",
"data": [
{
"id": 1,
"created_at": 1764460800,
"type": 2,
"content": "…",
"token_name": "my-server",
"model_name": "gpt-5.4-mini",
"quota": 1234,
"prompt_tokens": 120,
"completion_tokens": 300,
"use_time": 3,
"is_stream": false,
"group": "…",
"request_id": "20261130…",
"other": "{…}"
}
]
}
| Field | Description |
|---|---|
id |
Position in this response (1 is the newest), not a fixed record ID |
created_at |
Time (Unix timestamp, seconds) |
type |
Record type. The common ones are 2 (consumption), 5 (error) and 6 (refund) |
model_name |
The requested model |
quota |
Quota points charged; for conversion, see Quota units |
prompt_tokens, completion_tokens |
Input and output token counts |
use_time |
Duration (seconds) |
is_stream |
Whether it was a streaming request |
group |
The group used for this request |
request_id |
The request ID, the same one as at the end of error messages and in the X-Oneapi-Request-Id response header. Include it when you report a problem |
content, other |
Extra notes and billing details; other is a JSON string. Their format changes with upstream versions, so don't rely on them in code |
Legacy OpenAI quota endpoints
GET https://codaapi.com/v1/dashboard/billing/subscription
GET https://codaapi.com/v1/dashboard/billing/usage
These two endpoints imitate OpenAI's old quota lookup endpoints, and some third-party clients (with a Base URL that includes /v1) use them to show the balance. /dashboard/billing/subscription and /dashboard/billing/usage without /v1 are the same endpoints. No request parameters; the usage endpoint ignores start_date and end_date and returns all quota used.
Whether they return this key's own quota or the whole account's depends on a site setting: upstream defaults to per-key numbers; if the site turns off per-key statistics, they return the whole account's balance and usage.
curl
curl https://codaapi.com/v1/dashboard/billing/subscription \
-H "Authorization: Bearer $OPENAI_API_KEY"
curl https://codaapi.com/v1/dashboard/billing/usage \
-H "Authorization: Bearer $OPENAI_API_KEY"
Response
subscription:
{
"object": "billing_subscription",
"has_payment_method": true,
"soft_limit_usd": 10,
"hard_limit_usd": 10,
"system_hard_limit_usd": 10,
"access_until": 0
}
usage:
{"object": "list", "total_usage": 250}
The numbers are only examples. How to read them:
hard_limit_usdis the total quota (remaining + used);soft_limit_usdandsystem_hard_limit_usdare the same.total_usageis the used quota × 100. Remaining quota =hard_limit_usd−total_usage÷ 100.- The field names contain
usd, but the unit isn't necessarily US dollars; it depends on the site's display type. See Quota units. - With per-key numbers and an Unlimited Quota key,
hard_limit_usdis always100000000, meaning no cap. access_untilis the key's expiration time (Unix timestamp, seconds);0means it never expires, or that the numbers are for the account.
Errors
/api/usage/token/and/api/log/tokenreturn{"success": false, "message": "…"}on errors: 401 when the key is missing or invalid, 403 when the IP isn't on the whitelist, and 429 when you call too often.- Authentication errors on
/v1/dashboard/billing/*come back in the OpenAI format ({"error": {"message": …}}); invalid, disabled, expired and exhausted keys all get 401.
For what to do about each status code, see Troubleshooting.
Billing
These lookup endpoints aren't billed.