Read your OpenRouter key's status

When your organization brings its own OpenRouter key (BYOK), learners' AI replies are paid from that key. This endpoint reads the key's spending limit and state, so your portal can show how much is left and warn before learners stop getting replies. Cesura reads the key from OpenRouter for you, so your system never holds the OpenRouter key itself.

Before you start

  • Your organization uses BYOK and has an OpenRouter key set on the AI providers page.
  • An organization API key with the llm_credentials.read scope. It must be the key's only scope, and the key must expire within 1 year. See Organization API keys and scopes.

Get the key's status

curl -H "Authorization: Bearer ORG_API_KEY" \
  "https://app.cesura.ai/api/v1/organizations/ORG_ID/llm-credentials/openrouter"

The endpoint only reads. It never changes the key.

Response

{
  "provider": "openrouter",
  "key_suffix": "a1b2",
  "set_at": "2026-12-01T09:00:00Z",
  "state": "low",
  "state_changed_at": "2026-12-02T14:12:09Z",
  "limit": 1000.0,
  "limit_reset": "monthly",
  "limit_remaining": 182.4,
  "limit_remaining_checked_at": "2026-12-03T06:55:41Z",
  "last_error": null,
  "request_id": "6f1c2e0a-8f1b-4c55-9a51-0d6c2b8f4e7d"
}
Field Type Meaning
provider string Always openrouter.
key_suffix string The OpenRouter key's last 4 characters. The API never returns more of it.
set_at datetime or null When an admin last set or replaced the key.
state string ok, low, exhausted, or rejected. See Key states.
state_changed_at datetime or null When state last changed.
limit number or null The key's spending limit in US dollars. null when the key has no limit.
limit_reset string or null daily, weekly, or monthly, as OpenRouter reports it. null when the limit never resets.
limit_remaining number or null US dollars left of the limit, as of limit_remaining_checked_at.
limit_remaining_checked_at datetime or null When Cesura last read the key from OpenRouter.
last_error string or null OpenRouter's message from the last refused call, at most 300 characters, with any key text masked.
request_id string The request's ID. Quote it when you contact support.

Datetimes are ISO 8601 in UTC.

Show how much is used

The response has no "used" field. Compute it from the limit:

used = limit - limit_remaining
share_used = used / limit

Skip both when limit is null. This is the share Cesura uses for its own alert emails.

Key states

State Meaning What changes it back
ok The key works and has used less of its limit than the organization's highest alert threshold. Not applicable.
low The key works and has used as much of its limit as the highest alert threshold, or more. A read that shows less used, for example after the limit is raised or resets.
exhausted OpenRouter refused a call because the key's limit or the account's credits ran out. Learners get no AI replies. For the key's limit: a read that shows room left. For the account's credits: the next call that works.
rejected OpenRouter refused the key itself, for example because it was revoked. Learners get no AI replies. A read or a call that OpenRouter accepts.

Replacing the key on the AI providers page starts its state over at ok.

How fresh the numbers are

Cesura reads the key from OpenRouter at most once every 15 minutes for each organization. A request after that interval reads OpenRouter again before it answers; a request inside it returns the last read. Use limit_remaining_checked_at to see how old limit_remaining is.

A refused AI call changes state at once, without waiting for the next read.

Alerts Cesura sends

Cesura already emails every org admin when the share used reaches each alert threshold (80% and 95% unless an org admin changed them on the AI providers page), when the key runs out or is refused, and when it works again. The thresholds cannot be read through the API.

Rate limit

Each API key can make 60 requests a minute to this endpoint. Because Cesura reads OpenRouter at most every 15 minutes, polling more often than once a minute returns the same numbers.

Errors

Status code Cause
401 ORG_API_KEY_REQUIRED The request has no organization API key.
401 INVALID_ORG_API_KEY The API key is wrong, revoked, or expired.
403 INSUFFICIENT_SCOPE The API key does not hold llm_credentials.read.
403 BYOK_NOT_ENABLED The organization does not use BYOK.
404 ORGANIZATION_NOT_FOUND ORG_ID is not the API key's organization.
404 OPENROUTER_KEY_NOT_SET The organization has no OpenRouter key.
429 RATE_LIMITED More than 60 requests in a minute with this API key. Wait for the number of seconds in the Retry-After header.
503 BYOK_ENTITLEMENT_UNAVAILABLE Cesura could not check whether the organization uses BYOK. Retry later.
503 API_KEY_AUTH_UNAVAILABLE Cesura could not check the API key. Retry later.

For the error body, see Errors.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.