# API reference

Generated from the API's own [OpenAPI document](https://ja.hilberon.com/api/openapi.json), version 1. Base URL: `https://api.hilberon.com`

## Conventions and versioning

Evaluate mathematical queries such as `integrate(x*exp(x), x)` and get the result with its verification and, on request, the derivation. Also: accounts, API keys, credits and CLI login.

Bodies are JSON, and strict: an unknown field is `400 invalid_request`, and so is a query parameter a route does not take. Every non-2xx response carries an `ErrorBody`, except `503` from `/readyz`. Within v1 changes are additive: ignore unknown fields and unknown enum values.

### Request headers

*Request headers*

| Name | Description |
| --- | --- |
| Accept-Language | The language the text of the answer is written in: the best of Hilberon's languages (`en`, `es`, `ja`, `zh-Hans`) the header names, by `q`; `es-MX` is Spanish, and every `zh` tag (`zh-CN`, `zh-TW`, `zh-HK`, `zh-Hant`…) is `zh-Hans`. English when it is absent or names none. The answer says which it used in `Content-Language`. |
| x-hilberon-client | Identifies the CLI, as `hilberon-cli/<semver>`. A CLI older than the server's minimum is refused with `426 upgrade_required`. |

## Authentication

`Authorization: Bearer <token>` with an API key (`hbk_…`, created with `POST /v1/keys`) or a CLI token (`hbc_…`, issued by the device login, or by `POST /oauth/token` to an MCP client). A CLI token runs queries, step checks and asks, reads `GET /v1/me` and `GET /v1/usage`, and logs itself out; a device's also lists keys and revokes them, which the token of an MCP client does not. Every other route refuses it with `403`. It spends the plan's credits, the same as the web, up to a daily limit if the person set one, which only a web session changes (`PATCH /v1/keys/{id}`).

Each endpoint below says which credentials it takes:

- `none`: anonymous calls are accepted, limited per client network
- `bearer`: `Authorization: Bearer` with an API key (`hbk_…`) or a sign-in token (`hbc_…`)
- `web session`: the web app's own sign-in, which programs do not use

## Endpoints

- POST /v1/query · Evaluate one query
- POST /v1/check · Check a query's syntax
- POST /v1/steps/check · Check a line of a derivation
- POST /v1/ask · Solve a problem in words or a photo
- GET /v1/functions · Function catalog
- GET /v1/methods · Method catalog
- GET /v1/me · Current account
- GET /v1/usage · What the account spent, per day or month
- GET /v1/keys · List API keys and CLI tokens
- POST /v1/keys · Create an API key
- PATCH /v1/keys/{id} · Change the daily limit of a CLI token
- DELETE /v1/keys/{id} · Revoke an API key or CLI token

### POST /v1/query

Evaluate one query

Credentials: none, bearer, web session

Evaluates a query and returns the result, the methods that contributed, optionally the verified derivation (`steps: true`, for the heads that `GET /v1/functions` marks with `steps`; every step has an `explanation` written from the catalog's template, with its `tex` variant when `format` asks for `tex`), and what it cost. A derivation that did not finish within its fuel allowance is not returned: the answer is complete and `steps` is a single unverified `engine` step with `cut` set; a higher `effort` gives a longer attempt. With `steps`, `alternatives` (1 to 2; 0, or leaving it out, asks for none, with or without `steps`; for a signed-in caller, an anonymous call that asks for any is refused with `401 unauthenticated`) also derives other methods of the same problem: `steps.method` names the method of the main derivation, and `steps.alternatives` lists up to that many others, each a verified derivation of its own (`method`, `items` explained like the main ones, `answer`, `check`, `assumptions`). There may be fewer, or none, when the problem has no other method that applies. The derivation an earlier request kept for the same `query`, `effort` and `format` (fifteen minutes) is reused, so asking for the other methods of a derivation just shown is charged for them and not for the derivation again. They run under an allowance of fuel of their own: if they do not finish within it, the answer is the main derivation with no `alternatives`, charged in full for the plain answer and the derivation and at half for the attempt, and asking the same again is charged without the attempt. Every evaluated query is a `200`, whatever its `status` (`solved`, `cut`, `partial`, `unevaluated`, `error`); a non-2xx answer means the service refused the request or could not finish it.

`effort` is what the query may use: a level, which sets the search bounds and the most it may spend (`quick` 30 credits, `standard` 300, `deep` 1,000, `exhaustive` 5,000), or a whole number of credits, at least 2, which is the limit and runs at the first level that reaches it. `exhaustive` always runs progressive: it evaluates at `quick` and walks up while a bound cut the answer. A level's credits are a ceiling, not a price, and are lowered to the plan's or the API tier's most when that is less (a visitor's `standard` is 100). Left out, what the account set for the surface runs (`efforts`, `PATCH /v1/account/settings`), or else the surface's default: `standard`, the same on every surface. A `partial` answer says what stopped it in `usage.limited_by` (`effort`, `plan`, `surface`, `day`, `key` or `balance`) and at how many credits in `usage.limit`, a hold that a low balance, the day or a key made smaller included. A `syntax_error` is never charged: the query is checked with the same diagnostics as `POST /v1/check` before any credit is reserved.

The request body is limited to 64 KiB (`413 payload_too_large`). Anonymous calls are limited per client IP and return a derivation without its steps (`truncated`, and no `items` in any method). So does a web session on the Free plan, since steps are for Lite, Plus and Pro; the query is charged what it ran, and what an API key bought is shown whole. API keys spend the `api` channel; sessions and CLI tokens the `interactive` channel. A query costs a multiple of a tenth of a credit; an API key with a `credit_limit` is never charged beyond it, nor a CLI token beyond its daily limit.

An answered query of at most 2,000 characters may be kept, apart from the account and without its IP address, key or exact time, as a sample to improve Hilberon: for sessions and CLI tokens unless the account turned `improve_with_queries` off, for anonymous calls always, and never for API keys, whatever the account or the request says. `improve: false` in the body refuses it for this request (see `PATCH /v1/account/settings`).

The text of the answer is in the language of `Accept-Language` (`Content-Language` says which): the step explanations and the diagnostics, the notes of the engine under an answer (`messages`), the names of the methods, the summaries of the functions. Names of functions, rule ids, codes and an error's `message` and `hint` are the same in every language.

Authentication is optional; a credential, when sent, must be valid.

#### Request body

*POST /v1/query · Request body*

| Field | Type | Description |
| --- | --- | --- |
| allow_unknown | boolean | Run the query even when a function name looks like a misspelt builtin (`integrat` for `integrate`, `Sin` for `sin`), which is otherwise refused free of charge with the checker's suggestion. Only for a function of the caller's own. |
| alternatives | integer or null | How many other methods to derive besides the main one (`Steps::alternatives`). 0, or leaving it out, asks for none, with or without `steps`; 1 to `MAX_ALTERNATIVES` need `steps`, and without it, or above the most, the request is invalid. An anonymous request that asks for any is refused (`unauthenticated`). There may be fewer: only methods that apply and whose derivation is verified are listed. They are charged like the rest of the query, the attempt at half if the fuel cut it. |
| effort | `EffortChoice` or null | What the query may use: a level, for how far the engine searches and the credits it may spend (`Effort::credits`), or a whole number of credits, the limit, at the first level whose credits reach it. `exhaustive` starts at `quick` and escalates while a bound cut the answer. When absent, the account's setting for the surface runs, or the surface's default. The plan's ceilings apply. |
| format | array of `Format` | Renderings of every returned expression; `["input"]` when absent. |
| improve | boolean or null | `false` keeps this query out of the samples Hilberon keeps to improve the engine, whatever the account's settings say. It can only refuse: `true` or absent leaves the decision to the account (signed in) or to the default (anonymous). |
| query required | string | The query in Hilberon syntax, e.g. `integrate(x*exp(x), x)`. |
| steps | boolean | Also return the verified derivation when the query supports it. |

#### Responses

*POST /v1/query · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 200 | `application/json` `QueryResponse` | The query was evaluated; `status` says how it went. |
| 400 | `application/json` `ErrorBody` | `invalid_request` (empty query, unknown field, `max_credits` or `progressive` in the body, an `effort` that is no level or whole number, a number under 2 or above the most the plan or tier allows, with both bounds in `details` (`min_credits`, `max_credits`), an `effort` above what the account set for the surface, with `details.limited_by` `surface` and `details.max_credits`, `alternatives` of 1 or more without `steps`, or above 2) or `syntax_error` (see `details.diagnostics`, at most 50 with the errors kept first, and `details.diagnostics_omitted` when there were more; this includes the habits of other systems, such as `Integrate[f, x]`, `integrate(f, x, 0, 1)` and `d/dx f`, each with a fix, input that reads as words (`reads_as_words`: `Solve the cubic equation x^3 - 1 = 0`, `lim x->0 sin(x)/x`), and a function name that looks like a misspelt builtin (`integrat(x^2, x)`, `Sin(x)`) unless `allow_unknown` is set). |
| 401 | `application/json` `ErrorBody` | A credential was sent but is malformed or revoked (`unauthenticated`), or the key expired (`key_expired`); omit it to query anonymously. `alternatives` of 1 or more without a credential is also `unauthenticated`, with a hint to sign in; nothing is charged. |
| 402 | `application/json` `ErrorBody` | `insufficient_credits`, `key_limit_reached` when the API key has spent its `credit_limit` or the CLI token its limit for the UTC day (`details` has the `limit`, what it `spent` and what running queries hold, `held`, and for a CLI token `resets_at`), or `effort_not_allowed` when `effort` is above what the plan allows. An `insufficient_credits` names its cause in its hint and `details`: when the credits come back (`resets_at`), and for a subscription past due `reason` `renewal_failed` with `url`, the account page's payment methods. |
| 403 | `application/json` `ErrorBody` | `forbidden` with `details.reason` set to `subscription_required`: a CLI token on the Free plan, or a number of credits named by an anonymous call or a web session on the Free plan (name a level, or leave `effort` out); nothing is charged. `captcha_required`: an anonymous call, or a web session on the Free plan, without a valid pass from `POST /v1/captcha`, while this server asks for one; nothing is counted or charged. Get a pass and retry. Paid plans, CLI tokens and API keys are never asked. |
| 413 | `application/json` `ErrorBody` | The body is over 64 KiB or the query text over 60 KiB (`payload_too_large`). |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | `rate_limited` (the plan's requests a second; wait `Retry-After` seconds) or `concurrency_limited` (the plan's queries at once are all running, whatever their effort; or the credits are on hold for that many running queries; `details.limit` is the queries at once, and `details.held` in credits for the second case; `Retry-After` 1. One at a time without an account). Nothing is charged. |
| 500 | `application/json` `ErrorBody` | Unexpected server failure (`internal`). |
| 503 | `application/json` `ErrorBody` | `overloaded`: the engine is busy (nothing is charged), the query ran over 60 s (it still finishes and is billed at its actual cost), or the authentication service is unavailable. |

### POST /v1/check

Check a query's syntax

Credentials:

Syntax diagnostics for a query without running the engine. Free, and limited per client IP. At most 50 are sent, the errors kept first (`ok` is decided on all of them). These are the diagnostics `POST /v1/query` runs before it reserves credits: `ok` is false exactly when one of them is an error, and the query would then be refused with `syntax_error`, uncharged (a misspelt builtin runs when the query sets `allow_unknown`). A plain `=` between statements and an unknown function close to no builtin are warnings and do not block a query; a function name that looks like a misspelt builtin (`integrat(x^2, x)`, `Sin(x)`: `unknown_function` or `capitalized_function` with the builtin as a fix) is an error, as `POST /v1/query` refuses it without `allow_unknown`; input that reads as words is an error (`reads_as_words`: `Solve the cubic equation x^3 - 1 = 0`, `lim x->0 sin(x)/x`, `Solve x^2 = 4`); and notation from other systems that the engine cannot read is an error with a fix: `Integrate[f, x]` (`square_bracket_call`), `integrate(f, x, 0, 1)` (`integrate_bounds`), `limit(f, x, 0)` (`limit_point`) and `d/dx f` (`derivative_notation`).

The text of the answer is in the language of `Accept-Language` (`Content-Language` says which): the step explanations and the diagnostics, the notes of the engine under an answer (`messages`), the names of the methods, the summaries of the functions. Names of functions, rule ids, codes and an error's `message` and `hint` are the same in every language.

No authentication.

#### Request body

*POST /v1/check · Request body*

| Field | Type | Description |
| --- | --- | --- |
| query required | string |  |

#### Responses

*POST /v1/check · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 200 | `application/json` `CheckResponse` | The diagnostics; `ok` is false when any is an error. |
| 400 | `application/json` `ErrorBody` | The body is not valid (`invalid_request`). |
| 413 | `application/json` `ErrorBody` | The query is too long (`payload_too_large`). |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | Too many requests from this client (`rate_limited`); wait `Retry-After` seconds. `details.limit` names the limit that was hit: `ip` (all endpoints, per client network), `query` (requests that run the engine, per second), `anonymous_day`, `check`, `auth`, `device`, `device_pending`, `device_code`, `session` (session credentials the sign-in service has not accepted lately, per client network), `checkout`, `payment_method`, `billing_read`, `plan_change`, `refund`, `key`, `settings`, `export`, `captcha`, `contact`, `contact_all`, `support`, `support_all` or `ready`. |

### POST /v1/steps/check

Check a line of a derivation

Credentials: none, bearer, web session

Tells a student whether the line they wrote is a line of the verified derivation of a problem. The request names the problem (`query`, as sent to `POST /v1/query` with `steps`), the line the student is on (`state`: the query itself before the first step, then a `state` of the derivation) and the line they wrote (`candidate`), each in the language's syntax, at most 4 KiB, one expression or equation.

The lines of a derivation are the problem and the line each step with no `parent` leaves behind (its `state`, or its `to` where the engine keeps the problem in a call of its own: `solve(…)`, `solve_all(…)`, `union(…)`, `inverse(…)`, `eigenvalues(…)`, `eigenvectors(…)`, `linear_solve(…)`). Every line of a correct derivation equals the one before it, so the match is made on the form first. With `depth: form` (the default) the candidate is compared with `state` and then with each later line, and the first line it is the same expression as wins: `current` (the line the student is on, written again or in the same form) or `later` (a later line: the `step` it matches, the line as the derivation writes it in `matched`, and the lines it `skipped`). The same expression, the same canonical form and an equation with its sides exchanged or a term moved across the sign are the same form. An operator the line has not carried out (`integrate(…)`, `diff(…)`, `limit(…)`) is part of its form and is not evaluated. A candidate written as no line is `unmatched`, which does not say it is wrong: a derivation is one route among others. With `depth: value` the engine also proves or refutes: a candidate that equals a line without being written as one is `equivalent` (with the `step` and `matched` line it equals), one that equals none is `different` when every comparison was decided and `undecided` when one was not. `evidence` names what the verdict rests on: `identical`, `canonical`, `equation`, `exact`, `value` (the integrals, derivatives and limits had to be carried out), `witness` (a point where the two differ), `shape` or `sampled` (agreement at `points` sample points, which is never a match).

The derivation is the one `POST /v1/query` has just returned for the same `query`, `effort` and `format`: the API keeps it for fifteen minutes, with the other methods it found (`steps.alternatives`), so a check pays for the comparison only. When it is not kept the check derives it again and pays for that too. The lines of every method the derivation has are compared, the main derivation's first, and `method` in the response names the alternative whose line the candidate matches (absent for a line of the main derivation). `method` in the request, a rule id (the main derivation's own `steps.method`, or an alternative's), compares with the lines of that method only; a name that is not a rule of the catalog is `invalid_request`, free; a method the kept derivation has not derived is derived with the other methods by a signed-in check, which pays for them, and one that is still not among them is `invalid_request`, with that work charged. A check is charged like a small query: a multiple of a tenth of a credit, from a hold of at most what `effort` allows, on the channel of the credential. A check that names no `effort` runs at the level a query that names none runs at, where its derivation was kept, under credits of its own (50, or 100 with `depth: value`, and 15 for each other method it may pay for), never above what the account set for the surface or the plan's most. Finding a line of the derivation costs about a query; `depth: value` costs several times as much. A `syntax_error` in the query, the state or the candidate is never charged, and the diagnostics' spans are those of the text that has the error. As for a query, a refusal of the engine is free and what the engine answered is charged, also when the check is refused afterwards: a derivation it had to make, or one its fuel ran out on (`invalid_request`, charged the fuel used). The candidate is not kept as a sample. Anonymous calls count as a query of the day once the engine ran for them, and compare with the problem only, since a visitor is shown no step (`truncated`).

The query must be one of the heads that `GET /v1/functions` marks with `steps`.

The text of the answer is in the language of `Accept-Language` (`Content-Language` says which): the step explanations and the diagnostics, the notes of the engine under an answer (`messages`), the names of the methods, the summaries of the functions. Names of functions, rule ids, codes and an error's `message` and `hint` are the same in every language.

Authentication is optional; a credential, when sent, must be valid.

#### Request body

*POST /v1/steps/check · Request body*

| Field | Type | Description |
| --- | --- | --- |
| candidate required | string | The line the student wrote, in the language's syntax: an expression or an equation. |
| depth | `StepCheckDepth` or null | How far to go to match the candidate; `form` when absent. |
| effort | `EffortChoice` or null | What the check may use, as `crate::QueryRequest::effort`: its level is the effort of the derivation the lines come from, so it must be the level the derivation was asked at. When absent the level is `standard`, and the check may spend 50 credits for `form` and 100 for `value`, and 15 more for each other method it may pay for, under the same ceilings. It bounds the spending and not the charge: a check pays what it uses. |
| format | array of `Format` | Renderings of the matched line; `["input"]` when absent. |
| method | string or null | Compare with the lines of this method only, a rule id of the catalog (`Steps::method` of the main derivation, or `Alternative::method` of one of its alternatives). Absent: the lines of every method the derivation has are compared, the main one first. |
| query required | string | The problem, as sent to `POST /v1/query` with `steps`: `integrate(x*exp(x), x)`. |
| state required | string | The line the student is on, in the language's syntax. It is the query itself before the first step, and otherwise a line of the derivation as the response of `/v1/query` gives it (`Step.state`). |

#### Responses

*POST /v1/steps/check · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 200 | `application/json` `StepCheckResponse` | The candidate was compared; `result` says how it relates to the derivation. |
| 400 | `application/json` `ErrorBody` | `invalid_request` (an empty or compound line, a query with no derivation, an `effort` refused as for `POST /v1/query`, a `method` the derivation does not have) or `syntax_error` (see `details.diagnostics`; nothing is charged). |
| 401 | `application/json` `ErrorBody` | A credential was sent but is malformed or revoked (`unauthenticated`), or the key expired (`key_expired`); omit it to check anonymously. |
| 402 | `application/json` `ErrorBody` | `insufficient_credits`, `key_limit_reached` or `effort_not_allowed` when `effort` is above what the plan allows. An `insufficient_credits` names its cause in its hint and `details`: when the credits come back (`resets_at`), and for a subscription past due `reason` `renewal_failed` with `url`, the account page's payment methods. |
| 403 | `application/json` `ErrorBody` | `forbidden` (`subscription_required`) and `captcha_required`, as for `POST /v1/query`. |
| 413 | `application/json` `ErrorBody` | The body is over 64 KiB, the query text over 60 KiB or a line over 4 KiB (`payload_too_large`). |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | `rate_limited` (wait `Retry-After` seconds) or `concurrency_limited`, as for `POST /v1/query`. |
| 500 | `application/json` `ErrorBody` | Unexpected server failure (`internal`). |
| 503 | `application/json` `ErrorBody` | `overloaded`: the engine is busy (nothing is charged), the check ran over 60 s (it still finishes and is billed at its actual cost), or the authentication service is unavailable. |

### POST /v1/ask

Solve a problem in words or a photo

Credentials: bearer, web session

Reads a problem written in words (`text`, at most 2,000 characters), a photo of it (`image`: a JPEG, PNG or WebP of at most 2 MiB once decoded, in base64), or both, with a language model, which solves it with the engine and writes a short summary. It is not a chat: one problem, one answer, no history. The model writes queries in the language's syntax and the API runs each as a query of the account, as `POST /v1/query` would (holds, fuel, receipts and samples; they run at the ask's level, and `improve: false` keeps them out of the samples). A query whose syntax is wrong is not run, and the model is told why. The queries and calls of the model an ask may make are its effort's (below), and 60 s in all.

The answer is a stream of Server-Sent Events (`text/event-stream`, never compressed), each `event: <type>` and `data: <the AskEvent as JSON>`, with a comment (`: keep-alive`) every 10 s that nothing else is said: `status` (what the service is doing: `reading`, `solving`, `writing`), `query` (the engine is asked this, `id` naming it in what follows), `answer` (its answer, a `QueryResponse`), `query_failed` (it did not run: a syntax error the model may correct, or a refusal), `text` (the next piece of the summary: Markdown with paragraphs, short lists, bold and TeX in `$…$` and `$$…$$`), then `done` (the id of the main answer, `primary`, when there is one, and what the ask cost, `usage`) or `error` (the ask stopped: the model declined the problem, `forbidden` with `details.reason` `refused`; its reply ran too long, `internal`; the provider is down or the ask took over 60 s, `overloaded`; its credits ran out, `insufficient_credits`; what was spent is charged and is in `usage`).

The model's tokens are charged in the account's credits, the same that queries spend (`usage.model_credits`), at the price of the model times the offering's cost multiple (2.5), valued at the account's own rate, fixed when the ask starts: the plan's monthly credits over the monthly price the account paid before tax, in US dollars. An account that paid less for its credits is charged more of them for the same model work. A charge is rounded up to a tenth of a credit, with a receipt of its own in `GET /v1/usage`; the queries are charged as queries (`usage.engine_credits`). `effort` is as for `POST /v1/query`, and is each query's: every query the model runs may spend what the effort gives a query on its own, a level's credits or the number named. It also sets how many queries the ask may run and how many calls of the model it may make, the same on every plan: at `standard` 2 queries and 3 calls, at `deep` 4 and 4, at `exhaustive` 6 and 10; `quick` is refused. The model's part costs at most 4,000 credits, at every level and on every plan. Before the stream starts, the most the model could cost is held of the account's credits, as a query's is; each query holds its own when it runs. An ask that the model's bound or a hold cut short says so in `usage.limited_by` (`effort` for the model's bound) and `usage.limit`. However the ask ends, the client gone included, it is charged what it spent and no more. One ask at a time per account; it counts as a request against the plan's requests a second, and so does each of its queries. Neither the text nor the image is kept or logged. The image is read as a file, never decoded: what is not the picture (EXIF and its GPS position, XMP, comments, thumbnails, colour profiles, anything after its end) is taken out before it is sent to the model, and a still picture of at most 8,000 pixels on a side is all that is taken.

The body is limited to 4.5 MiB (`413 payload_too_large`); it has 30 s to arrive.

The text of the answer is in the language of `Accept-Language` (`Content-Language` says which): the step explanations and the diagnostics, the notes of the engine under an answer (`messages`), the names of the methods, the summaries of the functions. Names of functions, rule ids, codes and an error's `message` and `hint` are the same in every language.

Requires a web session or a CLI token (`hbc_…`); API keys (`hbk_…`) are refused with `403`.

#### Request body

*POST /v1/ask · Request body*

| Field | Type | Description |
| --- | --- | --- |
| effort | `EffortChoice` or null | What the whole question may use, the model and its queries in one pool, as `crate::QueryRequest::effort`; the same default and ceilings. Below what the first model call needs the ask is refused, and `details.min_effort` names the level that is enough. |
| image | `AskImage` or null |  |
| improve | boolean or null | `false` keeps the ask's engine queries out of the samples. It can only refuse, as `crate::QueryRequest::improve`. |
| text required | string | What the person wrote; may be empty when there is an image. At most `MAX_ASK_TEXT_CHARS` characters. |

#### Responses

*POST /v1/ask · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 200 | `text/event-stream` `AskEvent` | The ask's events, as they come, until `done` or `error`. |
| 400 | `application/json` `ErrorBody` | `invalid_request`: an unknown field, no text and no image, an image that is not base64, not of its `media_type`, not a whole file, animated or with a side over 8,000 pixels, `max_credits` in the body, an `effort` that is no level or whole number, a number under 2 or above the most the plan allows (both bounds in `details`), an `effort` above what the account set for the surface (`details.limited_by` `surface`), an `effort` under `standard` (`details.min_effort`, the level to ask at), or a problem whose reading alone may cost more than the model's bound. |
| 401 | `application/json` `ErrorBody` | No credential, or one that is malformed or revoked (`unauthenticated`). |
| 402 | `application/json` `ErrorBody` | `insufficient_credits`: the account's credits cannot hold what the model may cost (the engine's queries are checked as queries are), `key_limit_reached`: nor can the sign-in's day, or `effort_not_allowed` when `effort` is above what the plan allows. An `insufficient_credits` names its cause in its hint and `details`: when the credits come back (`resets_at`), and for a subscription past due `reason` `renewal_failed` with `url`, the account page's payment methods. |
| 403 | `application/json` `ErrorBody` | `forbidden`: an API key, an account on Free or Lite (`details.reason` set to `subscription_required`: the Plus and Pro plans may ask), or a subscription period a discount paid in full (`details.reason` set to `price`: with nothing paid there is no rate for a token). |
| 413 | `application/json` `ErrorBody` | The body is over 4.5 MiB, the text over 2,000 characters or the image over 2 MiB (`payload_too_large`). |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | `rate_limited` (wait `Retry-After` seconds) or `concurrency_limited` (an ask of the account is already running, `details.limit` 1; or its queries at once are all running, as for `POST /v1/query`). |
| 500 | `application/json` `ErrorBody` | Unexpected server failure (`internal`). |
| 503 | `application/json` `ErrorBody` | `overloaded`: the server has no model configured, the provider is unavailable, or the authentication service is. |

### GET /v1/functions

Function catalog

Credentials:

The functions the query syntax accepts, with their signatures and examples: the same catalog the CLI embeds. `steps` marks the heads that can return a derivation.

The text of the answer is in the language of `Accept-Language` (`Content-Language` says which): the step explanations and the diagnostics, the notes of the engine under an answer (`messages`), the names of the methods, the summaries of the functions. Names of functions, rule ids, codes and an error's `message` and `hint` are the same in every language.

No authentication.

#### Responses

*GET /v1/functions · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 200 | `application/json` array of `FunctionInfo` | The functions. |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | Too many requests from this client (`rate_limited`); wait `Retry-After` seconds. `details.limit` names the limit that was hit: `ip` (all endpoints, per client network), `query` (requests that run the engine, per second), `anonymous_day`, `check`, `auth`, `device`, `device_pending`, `device_code`, `session` (session credentials the sign-in service has not accepted lately, per client network), `checkout`, `payment_method`, `billing_read`, `plan_change`, `refund`, `key`, `settings`, `export`, `captcha`, `contact`, `contact_all`, `support`, `support_all` or `ready`. |

### GET /v1/methods

Method catalog

Credentials:

The method and step-rule ids that `methods[].id` and `steps.items[].rule` refer to in query responses. Ids are stable and never reused. A rule row also carries its sentence (`template`, with `{key}` and `{?key|text}` slots), the kind of each bind (`kinds`) and its general formula in TeX (`formula`).

The text of the answer is in the language of `Accept-Language` (`Content-Language` says which): the step explanations and the diagnostics, the notes of the engine under an answer (`messages`), the names of the methods, the summaries of the functions. Names of functions, rule ids, codes and an error's `message` and `hint` are the same in every language.

No authentication.

#### Responses

*GET /v1/methods · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 200 | `application/json` array of `MethodInfo` | The catalog. |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | Too many requests from this client (`rate_limited`); wait `Retry-After` seconds. `details.limit` names the limit that was hit: `ip` (all endpoints, per client network), `query` (requests that run the engine, per second), `anonymous_day`, `check`, `auth`, `device`, `device_pending`, `device_code`, `session` (session credentials the sign-in service has not accepted lately, per client network), `checkout`, `payment_method`, `billing_read`, `plan_change`, `refund`, `key`, `settings`, `export`, `captcha`, `contact`, `contact_all`, `support`, `support_all` or `ready`. |

### GET /v1/me

Current account

Credentials: bearer, web session

The caller's account, plan, subscription, credit balances (with the prepaid packs that have credits left and the date each ends, `balances.packs`) and limits, and the version of the Terms of Service the account accepted when it was created (`terms_version`, `terms_accepted_at`; absent for accounts older than the record). `subscription.currency` is the currency the subscription is billed in (ISO 4217, lower case: the table of the buyer's country), the one a plan change charges in; it is absent until a price of the subscription is held, which does not mean US dollars. `caller` is what this credential may do now: its `surface`, the level that runs when a request names none (`effort`), the most a request may name (`max_credits`), and for a sign-in what it spent and may spend in the UTC day (`today`). The plan's credits are the web's, the CLI's and MCP's alike: no cap counts what the sign-ins spend apart. The ask has no meter of its own: its model spends the credits above. `limits` say the rate as `requests_per_second` (`requests_per_minute` is that times 60) and `concurrency` in queries at once. `allowed` says what the account may do now (`ask`, `mcp`, `cli_queries`, `api_keys`): clients read it, never the plan's name.

Requires a web session, a CLI token (`hbc_…`) or an API key (`hbk_…`).

#### Responses

*GET /v1/me · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 200 | `application/json` `Me` | The account. |
| 401 | `application/json` `ErrorBody` | Missing, malformed or revoked credentials (`unauthenticated`; a session credential that is no longer valid has `details.reason` set to `session`), or a key past its expiry (`key_expired`). |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | Too many requests from this client (`rate_limited`); wait `Retry-After` seconds. `details.limit` names the limit that was hit: `ip` (all endpoints, per client network), `query` (requests that run the engine, per second), `anonymous_day`, `check`, `auth`, `device`, `device_pending`, `device_code`, `session` (session credentials the sign-in service has not accepted lately, per client network), `checkout`, `payment_method`, `billing_read`, `plan_change`, `refund`, `key`, `settings`, `export`, `captcha`, `contact`, `contact_all`, `support`, `support_all` or `ready`. |
| 500 | `application/json` `ErrorBody` | Unexpected server failure (`internal`). |
| 503 | `application/json` `ErrorBody` | The request timed out or a dependency is unavailable (`overloaded`); retry after `Retry-After` seconds. |

### GET /v1/usage

What the account spent, per day or month

Credentials: bearer, web session

Totals of the account, newest first: per day (UTC) or per month, by channel, API key (on the `api` channel) and kind (`query`, `ask` for the model's part of an ask, `step_check`). No row is kept per query. Days are kept for the current month and the 12 before it; older months are one total each. The months answered sum the recent days.

Requires a web session, a CLI token (`hbc_…`) or an API key (`hbk_…`).

#### Query parameters

*GET /v1/usage · Query parameters*

| Name | Type | Description |
| --- | --- | --- |
| period | `"day"` or `"month"` | `day` (the default) or `month`. |
| limit | integer | How many days (1 to 400, 30 by default) or months (1 to 120, 12 by default) back, the current one included. |

#### Responses

*GET /v1/usage · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 200 | `application/json` array of `UsageTotal` | The totals. |
| 400 | `application/json` `ErrorBody` | `period` is neither `day` nor `month`, or `limit` is outside its range (`invalid_request`). |
| 401 | `application/json` `ErrorBody` | Missing, malformed or revoked credentials (`unauthenticated`; a session credential that is no longer valid has `details.reason` set to `session`), or a key past its expiry (`key_expired`). |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | Too many requests from this client (`rate_limited`); wait `Retry-After` seconds. `details.limit` names the limit that was hit: `ip` (all endpoints, per client network), `query` (requests that run the engine, per second), `anonymous_day`, `check`, `auth`, `device`, `device_pending`, `device_code`, `session` (session credentials the sign-in service has not accepted lately, per client network), `checkout`, `payment_method`, `billing_read`, `plan_change`, `refund`, `key`, `settings`, `export`, `captcha`, `contact`, `contact_all`, `support`, `support_all` or `ready`. |
| 500 | `application/json` `ErrorBody` | Unexpected server failure (`internal`). |
| 503 | `application/json` `ErrorBody` | The request timed out or a dependency is unavailable (`overloaded`); retry after `Retry-After` seconds. |

### GET /v1/keys

List API keys and CLI tokens

Credentials: bearer, web session

The live API keys and CLI tokens of the account, newest first. Secrets are never listed. A CLI token has `today`: what it spent in the UTC day and its daily limit, in credits.

Requires a web session or a device's CLI token (`hbc_…`); API keys (`hbk_…`) and the tokens of MCP clients are refused with `403`.

#### Responses

*GET /v1/keys · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 200 | `application/json` array of `ApiKey` and object | The keys. |
| 401 | `application/json` `ErrorBody` | Missing, malformed or revoked credentials (`unauthenticated`; a session credential that is no longer valid has `details.reason` set to `session`), or a key past its expiry (`key_expired`). |
| 403 | `application/json` `ErrorBody` | An API key or the token of an MCP client was used (`forbidden`); use a web session or a device's CLI token. |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | Too many requests from this client (`rate_limited`); wait `Retry-After` seconds. `details.limit` names the limit that was hit: `ip` (all endpoints, per client network), `query` (requests that run the engine, per second), `anonymous_day`, `check`, `auth`, `device`, `device_pending`, `device_code`, `session` (session credentials the sign-in service has not accepted lately, per client network), `checkout`, `payment_method`, `billing_read`, `plan_change`, `refund`, `key`, `settings`, `export`, `captcha`, `contact`, `contact_all`, `support`, `support_all` or `ready`. |
| 500 | `application/json` `ErrorBody` | Unexpected server failure (`internal`). |
| 503 | `application/json` `ErrorBody` | The request timed out or a dependency is unavailable (`overloaded`); retry after `Retry-After` seconds. |

### POST /v1/keys

Create an API key

Credentials: web session

Creates an API key (`hbk_…`) that never expires and has no credit limit unless `expires_in` or `credit_limit` say otherwise. The `secret` is in this response and never again. Only a web session may create a key, of an account that holds prepaid credits a key can spend now (`balances.api` above 0), on any plan: spent, expired or refunded ones do not count, nor a promotion's web half, and a subscription is none (`403` with `details.reason` `purchase_required`). An account holds at most 50 live API keys (CLI logins do not count) and creates 20 an hour (`429`, `details.limit` `key`). A key that has been revoked or has expired is deleted 90 days after its end, and an account keeps at most the 50 that ended last.

Requires a web session; CLI tokens (`hbc_…`) and API keys (`hbk_…`) are refused with `403`.

#### Request body

*POST /v1/keys · Request body*

| Field | Type | Description |
| --- | --- | --- |
| credit_limit | number or null | Most credits the key may spend in total, from 1 to 10,000,000. Absent: no limit. |
| expires_in | integer or null | Seconds until the key expires, from 3,600 (one hour) to 31,622,400 (366 days). Absent: the key never expires. |
| name required | string |  |

#### Responses

*POST /v1/keys · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 201 | `application/json` `CreatedKey` | The key and its secret. |
| 400 | `application/json` `ErrorBody` | The name is empty, too long or has control characters (invisible and bidirectional-control characters are removed, but for the joiners U+200C and U+200D), `expires_in` or `credit_limit` is out of range, or the body is not valid (`invalid_request`). |
| 401 | `application/json` `ErrorBody` | Missing, malformed or revoked credentials (`unauthenticated`; a session credential that is no longer valid has `details.reason` set to `session`), or a key past its expiry (`key_expired`). |
| 403 | `application/json` `ErrorBody` | A CLI token or an API key was used (`forbidden`); only a web session may. |
| 409 | `application/json` `ErrorBody` | The account already has 50 live API keys (`conflict`); revoke one first. |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | Too many requests from this client (`rate_limited`); wait `Retry-After` seconds. `details.limit` names the limit that was hit: `ip` (all endpoints, per client network), `query` (requests that run the engine, per second), `anonymous_day`, `check`, `auth`, `device`, `device_pending`, `device_code`, `session` (session credentials the sign-in service has not accepted lately, per client network), `checkout`, `payment_method`, `billing_read`, `plan_change`, `refund`, `key`, `settings`, `export`, `captcha`, `contact`, `contact_all`, `support`, `support_all` or `ready`. |
| 500 | `application/json` `ErrorBody` | Unexpected server failure (`internal`). |
| 503 | `application/json` `ErrorBody` | The request timed out or a dependency is unavailable (`overloaded`); retry after `Retry-After` seconds. |

### PATCH /v1/keys/{id}

Change the daily limit of a CLI token

Credentials: web session

Sets what a CLI token, a device's or an MCP client's, may spend in a UTC day: `daily_limit` in credits, from 1 to 10,000,000, or `null` for no limit. By default there is no additional daily limit. A custom limit cannot exceed the monthly credits of the effective subscription version (or 10,000,000 credits); GET /v1/keys reports this as today.max_limit. A limit below what the day has spent stops the token until the day ends. Changes count with the settings' (60 an hour).

Requires a web session; CLI tokens (`hbc_…`) and API keys (`hbk_…`) are refused with `403`.

#### Request body

*PATCH /v1/keys/{id} · Request body*

| Field | Type | Description |
| --- | --- | --- |
| daily_limit required | number or null |  |

#### Query parameters

*PATCH /v1/keys/{id} · Query parameters*

| Name | Type | Description |
| --- | --- | --- |
| id | string | The token's id from `GET /v1/keys`. |

#### Responses

*PATCH /v1/keys/{id} · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 204 |  | The limit is changed. |
| 400 | `application/json` `ErrorBody` | `daily_limit` is missing or out of range, or the body is not valid (`invalid_request`). |
| 401 | `application/json` `ErrorBody` | Missing, malformed or revoked credentials (`unauthenticated`; a session credential that is no longer valid has `details.reason` set to `session`), or a key past its expiry (`key_expired`). |
| 403 | `application/json` `ErrorBody` | A CLI token or an API key was used (`forbidden`); only a web session may. |
| 404 | `application/json` `ErrorBody` | No live CLI token with that id in this account, or the id is not a UUID (`not_found`). |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | Too many requests from this client (`rate_limited`); wait `Retry-After` seconds. `details.limit` names the limit that was hit: `ip` (all endpoints, per client network), `query` (requests that run the engine, per second), `anonymous_day`, `check`, `auth`, `device`, `device_pending`, `device_code`, `session` (session credentials the sign-in service has not accepted lately, per client network), `checkout`, `payment_method`, `billing_read`, `plan_change`, `refund`, `key`, `settings`, `export`, `captcha`, `contact`, `contact_all`, `support`, `support_all` or `ready`. |
| 500 | `application/json` `ErrorBody` | Unexpected server failure (`internal`). |
| 503 | `application/json` `ErrorBody` | The request timed out or a dependency is unavailable (`overloaded`); retry after `Retry-After` seconds. |

### DELETE /v1/keys/{id}

Revoke an API key or CLI token

Credentials: bearer, web session

Revokes a key of the account; it stops working at once.

Requires a web session or a device's CLI token (`hbc_…`); API keys (`hbk_…`) and the tokens of MCP clients are refused with `403`.

#### Query parameters

*DELETE /v1/keys/{id} · Query parameters*

| Name | Type | Description |
| --- | --- | --- |
| id | string | The key id from `GET /v1/keys`. |

#### Responses

*DELETE /v1/keys/{id} · Responses*

| Status | Body | Description |
| --- | --- | --- |
| 204 |  | The key is revoked. |
| 401 | `application/json` `ErrorBody` | Missing, malformed or revoked credentials (`unauthenticated`; a session credential that is no longer valid has `details.reason` set to `session`), or a key past its expiry (`key_expired`). |
| 403 | `application/json` `ErrorBody` | An API key or the token of an MCP client was used (`forbidden`); use a web session or a device's CLI token. |
| 404 | `application/json` `ErrorBody` | No live key with that id in this account, or the id is not a UUID (`not_found`). |
| 426 | `application/json` `ErrorBody` | The CLI named by `x-hilberon-client` is older than the minimum in `x-hilberon-min-cli` (`upgrade_required`). |
| 429 | `application/json` `ErrorBody` | Too many requests from this client (`rate_limited`); wait `Retry-After` seconds. `details.limit` names the limit that was hit: `ip` (all endpoints, per client network), `query` (requests that run the engine, per second), `anonymous_day`, `check`, `auth`, `device`, `device_pending`, `device_code`, `session` (session credentials the sign-in service has not accepted lately, per client network), `checkout`, `payment_method`, `billing_read`, `plan_change`, `refund`, `key`, `settings`, `export`, `captcha`, `contact`, `contact_all`, `support`, `support_all` or `ready`. |
| 500 | `application/json` `ErrorBody` | Unexpected server failure (`internal`). |
| 503 | `application/json` `ErrorBody` | The request timed out or a dependency is unavailable (`overloaded`); retry after `Retry-After` seconds. |

## Errors

Every answer that is not a 2xx carries this body:

*Errors*

| Field | Type | Description |
| --- | --- | --- |
| code required | `ErrorCode` |  |
| details | any |  |
| hint | string or null | What to do next, written for a person or an agent. |
| message required | string |  |

### Codes

*Codes*

| Code | HTTP | Charged | What to do |
| --- | --- | --- | --- |
| syntax_error | 400 | No | Fix the query. `details.diagnostics` lists each problem with its place and, often, a fix. `POST /v1/check` gives the same diagnostics. |
| invalid_request | 400 | No | Fix the request: `message` names the field or value. An `effort` outside what the credential may name comes with the bounds in `details`. |
| payload_too_large | 413 | No | Send a smaller body. Each endpoint below says its limit. |
| unauthenticated | 401 | No | Send a valid credential: `Authorization: Bearer` with an API key or a sign-in token. A revoked or unknown token is refused the same way. |
| key_expired | 401 | No | The key is past its `expires_at`. Create a new key, or sign in again with `hilberon login`. |
| forbidden | 403 | No | This credential may not do this. `details.reason`, when there is one, says why (see the reasons below). |
| captcha_required | 403 | No | Only anonymous calls and the Free plan on the web are asked: get a pass from `POST /v1/captcha` and retry. API keys and sign-in tokens are never asked. |
| insufficient_credits | 402 | No | Add credits, or name a lower `effort`. An account whose email is not verified has no credits until it is. |
| key_limit_reached | 402 | No | The API key spent its `credit_limit`, or the sign-in its daily limit: `details` has `limit`, `spent`, `held` and `resets_at`. Wait for `resets_at`, create a key with a higher limit, or raise the sign-in's limit in Settings → Devices. |
| effort_not_allowed | 402 | No | The plan does not reach this `effort` (`details.max_effort`). Name a lower one, or move to a plan that has it. |
| upgrade_required | 426 | No | Update the CLI: it is older than the version in `X-Hilberon-Min-Cli`. |
| rate_limited | 429 | No | Wait `Retry-After` seconds. `details.limit` names the limit. |
| concurrency_limited | 429 | No | Too much is running at once for this account: wait for a request in flight to finish, then retry. There is no `Retry-After`. |
| overloaded | 503 | Only a run cut at its deadline, for the fuel it used | Retry after `Retry-After` seconds. |
| billing_unavailable | 503 | No | Billing is not available now. Retry after `Retry-After` seconds. |
| upstream_unavailable | 502, 503 | Perhaps: check `GET /v1/usage` | The service is not reachable. Retry later, waiting longer each time: there is no `Retry-After`. |
| upstream_timeout | 504 | Perhaps: the request may have run | Check `GET /v1/usage` before you repeat a costly request. |
| not_found | 404 | No | No such endpoint, key or code. Check the path and the id. |
| conflict | 409 | No | The account's state does not allow it now, such as a key past the most an account may hold. `details.reason`, when there is one, says why. |
| internal | 500 | Perhaps: check `GET /v1/usage` | Retry once. If it fails again, write to support@hilberon.com with the time and the request. |
| authorization_pending | 400 | No | Device login: the person has not approved the code yet. Keep polling at the interval. |
| slow_down | 400 | No | Device login: poll more slowly, every `details.interval` seconds. |
| access_denied | 400 | No | Device login: the person denied the request. Stop polling. |
| expired_token | 400 | No | Device login: the code expired. Start again. |
| unknown | any | As its status | Never sent: it is how a client built for this version reads a code a later server adds. Act on the HTTP status. |

### Reasons

`forbidden`, `unauthenticated` and `conflict` may name a reason in `details.reason`:

*Reasons*

| Reason | Code | What to do |
| --- | --- | --- |
| session | `unauthenticated` | The web session is no longer valid. Sign in again. |
| subscription_required | `forbidden` | The Free plan does not include it: asks, and the queries of a CLI sign-in, need Plus or Pro. On Free, name an `effort` level, not a number of credits. |
| purchase_required | `forbidden` | API keys need prepaid credits held now: buy credits, then retry. A subscription's credits do not count. |
| price | `forbidden` | Asks need a subscription period that was paid for; one a discount paid in full cannot ask. Queries still run. |
| refused | `forbidden` | In an ask's `error` event: the model declined the problem. Put it another way, or write it as a query. |
| ran_out | `conflict` | MCP only: the same query came back `partial` and was sent again with no more credits. Nothing was charged; a higher `effort` is a new run, and it is charged. |

## What is charged

- A query that runs is charged for the work the engine did, whatever its answer's `status`: `solved`, `cut`, `partial`, `unevaluated` or `error`. A step check is charged the same way.
- `POST /v1/check`, the catalogs and the account's own routes cost nothing.
- A refusal costs nothing: a `400`, `401`, `402`, `403`, `404`, `409`, `413`, `426` or `429` comes before any credit is held.
- A run cut short is charged the fuel it used until it stopped: one past its deadline (`503 overloaded`), or one whose client closed the connection.
- An ask is charged what it spent, however it ends: its model's tokens and its queries, each with a receipt in `GET /v1/usage`.
- After a `504 upstream_timeout` the request may have run and been charged: check `GET /v1/usage` before you repeat a costly one.

## Retries and idempotency

- The API takes no idempotency key: a request sent again runs again.
- A query sent again is charged again, as if it ran, even when its answer comes from a result kept from an earlier run.
- `429 rate_limited` and every `503` of the API carry `Retry-After`: wait that many seconds.
- `429 concurrency_limited` carries `Retry-After` too: a request in flight must finish first, so wait at least that long.
- `502` and `503 upstream_unavailable` come from in front of the API, without `Retry-After`: retry later, waiting longer each time.
- A broken ask or MCP stream cannot be resumed: a retry is a new call, with its own charge.
- `GET` requests change nothing and can be repeated.

## MCP

`POST https://api.hilberon.com/mcp` is a remote MCP server over Streamable HTTP. It keeps nothing between two requests, and has tools only.

Every request needs `Authorization: Bearer`: an API key (`hbk_`, prepaid credits), or a sign-in token (`hbc_`) of the CLI or of an MCP client, which signs in with OAuth in the browser (the plan's credits, on Plus and Pro).

A tool call is the endpoint it names: the same limits, holds, charges and errors. A call that names no `effort` runs at `standard`.

A failure is a tool result, not a protocol error: `isError: true`, the error as text in `content`, and the error body below in `structuredContent`. Only a tool that does not exist is a protocol error.

How to connect each MCP client is on the [developers page](https://ja.hilberon.com/developers#mcp).

### Tools

*Tools*

| Tool | Runs | Spends |
| --- | --- | --- |
| hilberon_query | `POST /v1/query` | credits |
| hilberon_check | `POST /v1/check` | nothing |
| hilberon_check_step | `POST /v1/steps/check` | credits |
| hilberon_functions | the catalog of `GET /v1/functions`, searched | nothing |
| hilberon_guide | the language guide: what a query looks like, what it costs and what it answers | nothing |
| hilberon_account | `GET /v1/me` | nothing |

## Types

The schemas the endpoints above send and answer, from the document.

### Allowed

What the account may do now, as the server decides it (`Me::allowed`). A client reads these and never the plan's name: what each plan allows is the offering's, and changes without a client.

*Allowed*

| Field | Type | Description |
| --- | --- | --- |
| api_keys required | boolean | The account can make API keys now: it holds prepaid credits. |
| ask required | boolean | The credential of the request may ask (`POST /v1/ask`): the same as `Me::ask`. An API key never does. |
| cli_queries required | boolean | A CLI sign-in (`hilberon login`) runs queries and step checks, not only reads the account. |
| mcp required | boolean | An MCP client signs in with this account and runs queries (`/mcp`, `hbc_` tokens of an OAuth client). |

### Alternative

Another way to solve the problem of a `Steps`: a method and the derivation it gives. It is listed only when its derivation is verified, so it has no `verified` of its own.

*Alternative*

| Field | Type | Description |
| --- | --- | --- |
| answer | `Rendered` or null | This method's answer. It can be written differently from the main one: two antiderivatives can differ by a constant. |
| assumptions | array of `Rendered` | Conditions this derivation relies on. |
| check | `Check` or null |  |
| items required | array of `Step` | The steps of this method, numbered and linked by `parent` like the main derivation's. |
| method required | string | The method, as a rule id of the catalog (`integrate.substitution`): the first choice where this derivation differs from the main one. Its catalog name titles it. |

### ApiError

*ApiError*

| Field | Type | Description |
| --- | --- | --- |
| code required | `ErrorCode` |  |
| details | any |  |
| hint | string or null | What to do next, written for a person or an agent. |
| message required | string |  |

### ApiKey

*ApiKey*

| Field | Type | Description |
| --- | --- | --- |
| created_at required | string |  |
| credit_limit | number or null | Credits the key may spend in total; at the limit queries are refused with `key_limit_reached`. Absent: no limit (CLI tokens have none). |
| credits_spent | number | Credits queries made with this key have been charged so far. |
| expires_at | string or null | From then on the key is refused with `key_expired`. Absent: it never expires. |
| id required | string |  |
| kind required | `KeyKind` |  |
| last_used_at | string or null |  |
| name required | string |  |
| prefix required | string | The visible start of the secret, e.g. `hbk_3fA9`. |

### AskEvent

One event of an ask's stream: `event: <type>` and `data: <this, as JSON>`.

One of:

What the service is doing now.

*AskEvent*

| Field | Type | Description |
| --- | --- | --- |
| phase required | `AskPhase` |  |
| type required | `"status"` |  |

The engine is asked `query` (Hilberon syntax); `id` names it in the events that follow.

*AskEvent*

| Field | Type | Description |
| --- | --- | --- |
| id required | integer |  |
| query required | string |  |
| type required | `"query"` |  |

The answer to query `id`, as `POST /v1/query` gives it.

*AskEvent*

| Field | Type | Description |
| --- | --- | --- |
| id required | integer |  |
| response required | `QueryResponse` |  |
| type required | `"answer"` |  |

Query `id` did not run (the model may send a corrected one).

*AskEvent*

| Field | Type | Description |
| --- | --- | --- |
| error required | `ApiError` |  |
| id required | integer |  |
| type required | `"query_failed"` |  |

The next piece of the summary, as it is written.

*AskEvent*

| Field | Type | Description |
| --- | --- | --- |
| delta required | string |  |
| type required | `"text"` |  |

The ask ended: the id of the main answer, when there is one, and what it cost.

*AskEvent*

| Field | Type | Description |
| --- | --- | --- |
| primary | integer or null |  |
| type required | `"done"` |  |
| usage required | `AskUsage` |  |

The ask stopped; what was spent is charged.

*AskEvent*

| Field | Type | Description |
| --- | --- | --- |
| error required | `ApiError` |  |
| type required | `"error"` |  |
| usage | `AskUsage` or null |  |

An event this client does not know yet.

*AskEvent*

| Field | Type | Description |
| --- | --- | --- |
| type required | `"unknown"` |  |

### AskImage

A picture of the problem, at most `MAX_ASK_IMAGE_BYTES` once decoded.

*AskImage*

| Field | Type | Description |
| --- | --- | --- |
| data required | string | The image's bytes in base64, without a `data:` prefix. |
| media_type required | `AskImageType` |  |

### AskImageType

The format of an `AskImage`, as its media type.

`"image/jpeg"` or `"image/png"` or `"image/webp"`

### AskPhase

What the service is doing while it answers an ask.

*AskPhase*

| Value | Description |
| --- | --- |
| "unknown" |  |
| "reading" | The model reads the text and the image. |
| "solving" | The engine is asked. |
| "writing" | The model writes the summary. |

### AskRequest

`POST /v1/ask` body (web sessions on Plus and Pro; Lite has no ask): a problem in words, a picture of it, or both.

*AskRequest*

| Field | Type | Description |
| --- | --- | --- |
| effort | `EffortChoice` or null | What the whole question may use, the model and its queries in one pool, as `crate::QueryRequest::effort`; the same default and ceilings. Below what the first model call needs the ask is refused, and `details.min_effort` names the level that is enough. |
| image | `AskImage` or null |  |
| improve | boolean or null | `false` keeps the ask's engine queries out of the samples. It can only refuse, as `crate::QueryRequest::improve`. |
| text required | string | What the person wrote; may be empty when there is an image. At most `MAX_ASK_TEXT_CHARS` characters. |

### AskUsage

What an ask cost, in credits: the model's part and the engine's queries.

*AskUsage*

| Field | Type | Description |
| --- | --- | --- |
| balance | number or null | Credits left for this channel after the charge. |
| credits required | number | `model_credits` and `engine_credits` together. |
| engine_credits required | number |  |
| limit | number or null | How many credits that limit allowed; absent when nothing stopped the ask. |
| limited_by | `LimitSource` or null | What stopped the ask; absent when nothing did. |
| model_credits required | number |  |
| notice | `UsageNotice` or null | The notice of a charge of this ask, its model's or one of its queries' (whose `Answer` events never carry one): the last when several crossed a mark. |

### Balances

Spendable credits by source. `interactive` and `api` are what each channel can spend right now.

*Balances*

| Field | Type | Description |
| --- | --- | --- |
| api required | number |  |
| free required | number |  |
| free_claimed_elsewhere | boolean | This month's free credits went to another account at the same mailbox (one account a mailbox a month: an account deleted and made again, or one at an alias of the address), so `free` stays 0 until `next_reset`. |
| granted | number or null | What the plan's month and the month's free credits granted, spent or not: `interactive` is what is left of them (with any other credits the web and the CLI spend). After a plan changed within the month it is less than a month of the new plan. `None` for a payload that lacks it. |
| interactive required | number |  |
| next_reset | string or null | When the plan's credits come back: the end of the subscription's month where there is one, else of the month's free credits. |
| packs | array of `PrepaidPack` | The prepaid packs with credits left, the first to end first: `prepaid` is theirs, and each ends on its own date. Absent when there are none. |
| prepaid required | number |  |
| subscription required | number |  |

### BillingInterval

`"month"` or `"year"` or `"unknown"`

### BindKind

What a bind of a step holds, so a client knows how to show it.

*BindKind*

| Value | Description |
| --- | --- |
| "expression" |  |
| "symbol" |  |
| "equation" |  |
| "matrix" |  |
| "number" |  |
| "form" | A form named by the rule: an indeterminate form such as `0/0`, a trigonometric identity… |
| "direction" | The side of a one-sided limit, as a word: `right` or `left`. It is not math, so the explanation sets it in running text without delimiters ("on the right side"). |
| "list" | A list of values. A list that is a math span of its own in a sentence is written as an enumeration, each item in a span (`2` and `3`): see `crate::explain`. |
| "unknown" | A kind this client does not know yet. |

### CallerLimits

What a credential may do now: its plan's or tier's limits with the account's setting for the surface it is on, as the API decides them (`Me::caller`).

*CallerLimits*

| Field | Type | Description |
| --- | --- | --- |
| effort required | `Effort` | The highest level a request may name. |
| max_credits required | integer | The most a question may spend, in whole credits. |
| surface required | `Surface` |  |
| today | `CallerToday` or null | What it spent today, for a credential with a day to count. |

### CallerToday

What a credential spent today and what it may, in credits.

*CallerToday*

| Field | Type | Description |
| --- | --- | --- |
| limit | number or null | Absent when the day has no limit. |
| spent required | number |  |

### Channel

Which product pays for a request: `interactive` (web session or CLI token) spends subscription and free credits only; `api` (API key) spends prepaid credits only.

`"interactive"` or `"api"` or `"unknown"`

### ChannelLimits

*ChannelLimits*

| Field | Type | Description |
| --- | --- | --- |
| api required | `Limits` | API keys. |
| interactive required | `Limits` | Web session and CLI login. |

### Check

*Check*

| Field | Type | Description |
| --- | --- | --- |
| kind required | `CheckKind` |  |
| points | integer or null |  |

### CheckKind

How strongly an answer was verified, strongest first.

*CheckKind*

| Value | Description |
| --- | --- |
| "unknown" |  |
| "exact_residual" | Substituting the answer left exactly zero. |
| "pullback_identity" | A chain-rule identity. |
| "numeric" | Passed a sampled numeric check (`points` says how many). |
| "by_construction" | A named theorem was applied without recomputation. |

### CheckRequest

`POST /v1/check` body.

*CheckRequest*

| Field | Type | Description |
| --- | --- | --- |
| query required | string |  |

### CheckResponse

`POST /v1/check` response. `ok` is false when any diagnostic is an error.

*CheckResponse*

| Field | Type | Description |
| --- | --- | --- |
| diagnostics required | array of `Diagnostic` |  |
| ok required | boolean |  |

### CreateKeyRequest

`POST /v1/keys`

*CreateKeyRequest*

| Field | Type | Description |
| --- | --- | --- |
| credit_limit | number or null | Most credits the key may spend in total, from 1 to 10,000,000. Absent: no limit. |
| expires_in | integer or null | Seconds until the key expires, from 3,600 (one hour) to 31,622,400 (366 days). Absent: the key never expires. |
| name required | string |  |

### CreatedKey

The only response that ever contains the secret.

*CreatedKey*

| Field | Type | Description |
| --- | --- | --- |
| key required | `ApiKey` |  |
| secret required | string |  |

### Diagnostic

*Diagnostic*

| Field | Type | Description |
| --- | --- | --- |
| args | object | The values of the slots of the sentences `id` names, by name. |
| code required | string | Stable machine code, e.g. `unknown_function`, `arity`, `unclosed_bracket`. |
| fixes | array of `Fix` |  |
| hint | string or null | How to fix it, written for a person or an agent. |
| id | string or null | Which sentences `message` and `hint` are, so that a client can write them in another language: the id of the pair in `hilberon-assist`'s tables, which is `code` or `code` and a variant (`arity.primed`), with `args` for their `{{name}}` slots. `message` and `hint` stay English. Absent when the diagnostic has no translation to offer. |
| message required | string |  |
| severity required | `Severity` |  |
| span required | `Span` |  |

### Effort

How far the engine's searches may go, and with `Effort::credits` what a question may spend. The credits stay the only runtime limit; effort bounds the shape of the searches (degrees, candidates, dimensions).

*Effort*

| Value | Description |
| --- | --- |
| "quick" |  |
| "standard" |  |
| "deep" |  |
| "exhaustive" |  |
| "unknown" | An effort this client does not know yet. Only responses carry it: a request that names one is refused. |

### EffortChoice

A level, or a whole number of credits: the limit, at the first level whose credits reach it.

*EffortChoice*

| Value | Description |
| --- | --- |
| "quick" |  |
| "standard" |  |
| "deep" |  |
| "exhaustive" |  |

### EffortReport

The effort an answer was computed at and whether more effort could change it.

*EffortReport*

| Field | Type | Description |
| --- | --- | --- |
| cut required | boolean | A bound refused some search, so a larger effort may answer more. |
| level required | `Effort` |  |
| lifts_at | `Effort` or null | The cheapest effort at which the answer could change. |

### EngineMessage

*EngineMessage*

| Field | Type | Description |
| --- | --- | --- |
| head required | string |  |
| text required | string |  |

### ErrorBody

`{"error": {...}}`

*ErrorBody*

| Field | Type | Description |
| --- | --- | --- |
| error required | `ApiError` |  |

### ErrorCode

Stable machine-readable error codes.

*ErrorCode*

| Value | Description |
| --- | --- |
| "invalid_request" |  |
| "payload_too_large" |  |
| "unauthenticated" |  |
| "forbidden" |  |
| "insufficient_credits" |  |
| "effort_not_allowed" |  |
| "upgrade_required" |  |
| "rate_limited" |  |
| "concurrency_limited" |  |
| "overloaded" |  |
| "not_found" |  |
| "conflict" |  |
| "internal" |  |
| "unknown" |  |
| "syntax_error" | `details.diagnostics` holds `crate::Diagnostic`s. Nothing was charged. |
| "captcha_required" | The request needs a fresh pass from `POST /v1/captcha` (the engine, anonymous or on the Free plan, from the web). Nothing was charged. |
| "key_expired" | The API key or CLI token is past its `expires_at`. Create a new key or run `hilberon login`. |
| "key_limit_reached" | The API key has spent its `credit_limit`. `details` holds `limit` and `spent`, in credits. Nothing was charged. |
| "billing_unavailable" | Billing is not set up on this server, or the product is not on sale. Not a temporary overload: retrying does not help until the operator configures it. |
| "upstream_unavailable" | The API, or the identity service behind it, is down or not reachable. Only the edge answers it (with a `503` or a `502`), never the API itself. Retry later. |
| "upstream_timeout" | The API, or the identity service behind it, took too long to answer. Only the edge answers it (`504`), never the API itself. The request may still have run and been charged: check the usage before repeating a costly one. |
| "authorization_pending" | Device login: the user has not approved the code yet. |
| "slow_down" | Device login: poll more slowly. |
| "access_denied" | Device login: the user denied the request. |
| "expired_token" | Device login: the code expired; start again. |

### EvidenceKind

What the verdict rests on.

*EvidenceKind*

| Value | Description |
| --- | --- |
| "identical" | The two are the same expression. |
| "canonical" | The two are the same in the engine's canonical form (a sum in another order). |
| "exact" | The engine proved the difference of the two zero, exactly. |
| "value" | The two have the same value once the integrals, derivatives and limits in them are carried out. |
| "equation" | Two equations were compared: the same relation, a term moved across, a constant multiple, or equal solution sets of a polynomial equation. |
| "witness" | A point where a certified evaluation of the two differs: they are not the same. |
| "shape" | The two have different kinds (an equation and an expression), or different lengths. |
| "sampled" | The two agree at sample points (`points` says how many). Evidence, never a proof. |
| "unknown" | Evidence this client does not know yet. |

### Explanation

A step in words: the rule's template with the step's binds filled in.

*Explanation*

| Field | Type | Description |
| --- | --- | --- |
| tex | string or null | The same sentences with math as `$…$` (TeX). Present when TeX was requested. |
| text required | string | One or two plain English sentences; math is input syntax in backticks. |
| why | `Why` or null | Why a reader would choose this method: one sentence, rendered from the rule's `why` template. Absent on bookkeeping rules, which make no choice. |

### Fix

A text edit that fixes a diagnostic.

*Fix*

| Field | Type | Description |
| --- | --- | --- |
| args | object | The values of the slots of the sentence `code` names, by name. |
| code | string or null | Which sentence `title` is, so that a client can write it in another language (`use`, `remove_space`...): the id of the sentence in `hilberon-assist`'s tables, with `args` for its `{{name}}` slots. Absent when the title has no translation to offer. |
| replacement required | string |  |
| span required | `Span` |  |
| title required | string |  |

### Format

A rendering of an expression.

*Format*

| Value | Description |
| --- | --- |
| "input" | The engine's surface syntax; it can be sent back as a query. |
| "tex" | LaTeX for display. Not accepted as input. |

### FunctionAccepts

One thing a parameter accepts, with a way to write it.

*FunctionAccepts*

| Field | Type | Description |
| --- | --- | --- |
| example required | string | An argument of that kind written in the language: `x^2 - 4 = 0`. |
| text required | string | What it is, as a phrase: `an equation`, `a list of variables`. |

### FunctionInfo

One entry of `GET /v1/functions`: a builtin of the language, as `hilberon_assist::catalog` documents it.

*FunctionInfo*

| Field | Type | Description |
| --- | --- | --- |
| aliases required | array of string |  |
| category required | string |  |
| described | boolean | The summary and the examples were written for this function. When it is false they are what the catalog could say from the name alone (a summary may be empty), and a client may say the function has no description yet. |
| examples required | array of string | One runnable example per variant that matters. |
| name required | string |  |
| signatures required | array of string | The label of each variant: the forms the function is called with. |
| steps | boolean | The head can return steps (it is in `STEPS_HEADS`). |
| summary required | string |  |
| variants | array of `FunctionVariant` | Each form of a call with its parameters: what each one accepts and means. `signatures` is these labels, in order, and `examples` the examples of all of them. |
| visibility | `Visibility` | How prominent the function is: a client suggests and lists `core` first, keeps `advanced` one step behind and never offers `internal`. |

### FunctionParam

A parameter of a `FunctionVariant`.

*FunctionParam*

| Field | Type | Description |
| --- | --- | --- |
| about required | string | What the argument means for this function, in one short sentence; empty when the catalog has nothing to say. |
| accepts required | array of `FunctionAccepts` | What it accepts, one entry for each alternative; empty when unknown. |
| label required | string | As written in the label: `f`, `x = a..b`, `order = n`, `...`. |

### FunctionVariant

One form of a call: `solve(equations, variables, domain = real|complex)`.

*FunctionVariant*

| Field | Type | Description |
| --- | --- | --- |
| about required | string | What this form does, in a few words; empty when the summary says it. |
| examples required | array of string | Calls of this form that run, the one that shows it best first. |
| label required | string | The call written with its parameters, as the signature help shows it. |
| params required | array of `FunctionParam` | The parameters in order: one for each argument written in `label`. |

### KeyKind

*KeyKind*

| Value | Description |
| --- | --- |
| "unknown" |  |
| "api" | `hbk_…`, channel `api`. |
| "cli" | `hbc_…` issued by `hilberon login`, channel `interactive`. |

### LegacyPrice

A price a subscription keeps after the plan's price changed: what it pays every `interval` for `plan`, for as long as it keeps both. Any change of plan or interval leaves it for the price offered then, and is made only when the request accepts that (`PlanChangeRequest::accept_price_change`).

*LegacyPrice*

| Field | Type | Description |
| --- | --- | --- |
| amount_cents required | integer | What it bills each interval, tax included, in the minor unit of `currency` (cents; yen for `jpy`). |
| currency | string | ISO 4217, lowercase: the currency the subscription is billed in (`eur` where the price's table for the buyer's country is in euros). A server that did not send it meant US dollars. |
| interval required | `BillingInterval` |  |
| plan required | `PlanId` |  |

### LimitSource

What set the limit a run or a refusal met (`Usage::limited_by`, `details.limited_by`).

*LimitSource*

| Value | Description |
| --- | --- |
| "effort" | The effort the request ran at: a level's credits, or the number it named. |
| "plan" | The most a question may spend on the plan or the API tier (`crate::Limits::max_credits`). |
| "surface" | The account's setting for the surface (`crate::AccountSettings::efforts`). |
| "day" | The daily limit of the sign-in. |
| "key" | The credit limit of the API key. |
| "balance" | What was left of the balance. |
| "unknown" | A limit this client does not know yet. |

### Limits

What a principal may do on one channel.

*Limits*

| Field | Type | Description |
| --- | --- | --- |
| concurrency required | integer | The queries a principal may have under way at once: a query or a step check holds one slot, whatever its effort, an ask's model part none. |
| max_credits required | integer | The most a question may spend on this plan or tier, in whole credits, whatever its effort. Also read from `default_max_credits`, the name the field had. |
| max_effort required | `Effort` |  |
| requests_per_minute required | integer | The requests a minute: `requests_per_second` times 60, for a client that counts in minutes. The server counts requests in whole seconds; read `Limits::per_second`. |
| requests_per_second | integer | The most requests a second, counted in fixed one-second windows. 0 when a payload says only `requests_per_minute`: `Limits::per_second` reads either. |

### Me

`GET /v1/me`

*Me*

| Field | Type | Description |
| --- | --- | --- |
| allowed | `Allowed` or null | What the account may do now, as the server decides it. `None` for a payload that lacks it. |
| api_tier required | integer | 0 without purchases; grows with lifetime purchases (API rate limits). |
| ask | boolean | This account may ask now (`POST /v1/ask`): its plan has the ask (Plus and Pro; Free and Lite do not) and the server offers it. False when a payload lacks it. `Allowed::ask` says it too. |
| balances required | `Balances` |  |
| caller | `CallerLimits` or null | What the credential of this request may do now. `None` for a payload that lacks it. |
| email | string or null |  |
| email_verified required | boolean |  |
| id required | string |  |
| limits required | `ChannelLimits` |  |
| plan required | `PlanId` |  |
| subscription | `SubscriptionInfo` or null |  |
| terms_accepted_at | string or null |  |
| terms_version | string or null | The terms of service version the user accepted; absent before acceptance is recorded. |

### MethodInfo

*MethodInfo*

| Field | Type | Description |
| --- | --- | --- |
| binds required | array of string | Keys this rule fills in a step's `bind`. |
| formula | string or null | The rule's general formula in TeX, for example `\int u\,dv = uv - \int v\,du`. |
| id required | string |  |
| kind required | `MethodKind` |  |
| kinds | array of array of any | The kind of each bind. Every key of `binds` has one on a rule. |
| name required | string |  |
| routine | boolean | A routine rule: bookkeeping a textbook states without dwelling on it, so a client may fold it at the brief and standard levels of detail and show it at the full one. The rule of thumb: the step applies a law or a lookup, or tidies up, and takes no decision a student must follow (linearity, a constant or a table lookup, the power rule, `simplify`, collecting like terms or the result). A step that carries the method is not routine: a technique, a choice, a row operation, a factoring, the solving of an equation, a check. Rule rows only; the engine's own rows are never routine. |
| template | `Template` or null | The sentence of the step; absent on engine algorithms and the fallback. |
| why | `Template` or null | Why a reader would choose this method: one sentence, in the syntax of `template`, for the rules where a choice is made (a technique, a form of the answer, a case). Absent on bookkeeping rules and on rules that only carry out a decision made before them. It may use only binds that `template` needs, so it renders whenever the step does. `explain` renders it into `Explanation::why`. |

### MethodKind

*MethodKind*

| Value | Description |
| --- | --- |
| "rule" | A textbook rule a person would write as a step. |
| "algorithm" | An engine algorithm with no hand-written counterpart (Risch, Hermite…). |
| "fallback" | A step the derivation could not narrate; the engine's value is shown as is. |

### MethodRef

A method or rule that contributed to the result; ids come from `crate::catalog::METHODS`.

*MethodRef*

| Field | Type | Description |
| --- | --- | --- |
| id required | string |  |

### PlanId

*PlanId*

| Value | Description |
| --- | --- |
| "free" |  |
| "plus" |  |
| "pro" |  |
| "unknown" |  |
| "lite" | Engine only, for personal use: no ask. |

### PrepaidPack

A pack of prepaid credits bought for API keys (`Balances::packs`). What is left of it on `expires_at` ends then and cannot be extended.

*PrepaidPack*

| Field | Type | Description |
| --- | --- | --- |
| amount required | number | Credits bought. |
| expires_at required | string |  |
| remaining required | number | Credits left. |

### QueryError

Why the engine rejected a query (`status: error`).

*QueryError*

| Field | Type | Description |
| --- | --- | --- |
| kind required | string |  |
| message required | string |  |

### QueryRequest

`POST /v1/query` body.

*QueryRequest*

| Field | Type | Description |
| --- | --- | --- |
| allow_unknown | boolean | Run the query even when a function name looks like a misspelt builtin (`integrat` for `integrate`, `Sin` for `sin`), which is otherwise refused free of charge with the checker's suggestion. Only for a function of the caller's own. |
| alternatives | integer or null | How many other methods to derive besides the main one (`Steps::alternatives`). 0, or leaving it out, asks for none, with or without `steps`; 1 to `MAX_ALTERNATIVES` need `steps`, and without it, or above the most, the request is invalid. An anonymous request that asks for any is refused (`unauthenticated`). There may be fewer: only methods that apply and whose derivation is verified are listed. They are charged like the rest of the query, the attempt at half if the fuel cut it. |
| effort | `EffortChoice` or null | What the query may use: a level, for how far the engine searches and the credits it may spend (`Effort::credits`), or a whole number of credits, the limit, at the first level whose credits reach it. `exhaustive` starts at `quick` and escalates while a bound cut the answer. When absent, the account's setting for the surface runs, or the surface's default. The plan's ceilings apply. |
| format | array of `Format` | Renderings of every returned expression; `["input"]` when absent. |
| improve | boolean or null | `false` keeps this query out of the samples Hilberon keeps to improve the engine, whatever the account's settings say. It can only refuse: `true` or absent leaves the decision to the account (signed in) or to the default (anonymous). |
| query required | string | The query in Hilberon syntax, e.g. `integrate(x*exp(x), x)`. |
| steps | boolean | Also return the verified derivation when the query supports it. |

### QueryResponse

`POST /v1/query` response, `200` for every evaluated query whatever its status.

*QueryResponse*

| Field | Type | Description |
| --- | --- | --- |
| check | `Check` or null |  |
| effort required | `EffortReport` |  |
| error | `QueryError` or null |  |
| id required | string | This answer's id, for support. The service keeps it nowhere: usage is kept as totals per day. |
| messages | array of `EngineMessage` |  |
| methods | array of `MethodRef` |  |
| result | `Rendered` or null |  |
| status required | `Status` |  |
| steps | `Steps` or null |  |
| steps_available | boolean | Whether the same query with `steps` gives a derivation: the engine narrates problems of this shape (`solve` of one equation, not yet of a system). `FunctionInfo.steps` says it for a head, this for the query. False when a payload lacks it. |
| usage required | `Usage` |  |

### Rendered

One expression in the renderings the request asked for.

*Rendered*

| Field | Type | Description |
| --- | --- | --- |
| input | string or null |  |
| tex | string or null |  |

### ScheduledChange

The plan and interval a subscription moves to at `at`, the end of its current period.

*ScheduledChange*

| Field | Type | Description |
| --- | --- | --- |
| at required | string |  |
| interval required | `BillingInterval` |  |
| plan required | `PlanId` |  |

### Severity

*Severity*

| Value | Description |
| --- | --- |
| "hint" |  |
| "unknown" |  |
| "error" | The engine would reject the query; sending it wastes credits. |
| "warning" | The query parses but probably does not mean what was intended. |

### Span

A byte range of the query text (UTF-8). Editors that index UTF-16 code units convert at their boundary.

*Span*

| Field | Type | Description |
| --- | --- | --- |
| end required | integer |  |
| start required | integer |  |

### Status

What happened to a query that reached the engine.

*Status*

| Value | Description |
| --- | --- |
| "solved" | A result was produced: a closed form or the engine's numeric/asymptotic fallback. |
| "cut" | No full answer, and an effort bound refused some search: retry at `effort.lifts_at`. |
| "partial" | The credits ran out (`Usage::limited_by` says which limit). At `exhaustive`, `result` is the last completed effort's answer. |
| "unevaluated" | No closed form was found and nothing was cut. |
| "error" | The engine rejected the query; see `error`. |
| "unknown" | A status this client does not know yet. |

### Step

One step of a verified derivation. No prose: clients explain the step from `rule` and `bind`.

*Step*

| Field | Type | Description |
| --- | --- | --- |
| bind | object | The rule's data: `u`, `dv`, `du`, `v` for parts; `u`, `du` for substitution… |
| explanation | `Explanation` or null | The step in words, rendered by the API from the rule's catalog template; the engine never fills it. |
| id required | integer |  |
| method | string or null | For `engine` steps: the engine method that produced the value, when known. |
| on required | `Rendered` | The expression the rule is applied to. |
| parent | integer or null | The step whose sub-expression this one works on. |
| rule required | string | A rule id from the catalog, or `engine` for a step the derivation could not narrate. |
| state | `Rendered` or null | The whole expression after this step, remaining integrals included. |
| to | `Rendered` or null | What `on` became. |

### StepCheckDepth

How far a check goes to match the candidate with a line.

*StepCheckDepth*

| Value | Description |
| --- | --- |
| "form" | Is the candidate written as a line of the derivation? Cheap. The default. |
| "value" | Also: when it is written as none, does it equal one? Proves and refutes, and can cost several times as much. |

### StepCheckRequest

`POST /v1/steps/check` body.

*StepCheckRequest*

| Field | Type | Description |
| --- | --- | --- |
| candidate required | string | The line the student wrote, in the language's syntax: an expression or an equation. |
| depth | `StepCheckDepth` or null | How far to go to match the candidate; `form` when absent. |
| effort | `EffortChoice` or null | What the check may use, as `crate::QueryRequest::effort`: its level is the effort of the derivation the lines come from, so it must be the level the derivation was asked at. When absent the level is `standard`, and the check may spend 50 credits for `form` and 100 for `value`, and 15 more for each other method it may pay for, under the same ceilings. It bounds the spending and not the charge: a check pays what it uses. |
| format | array of `Format` | Renderings of the matched line; `["input"]` when absent. |
| method | string or null | Compare with the lines of this method only, a rule id of the catalog (`Steps::method` of the main derivation, or `Alternative::method` of one of its alternatives). Absent: the lines of every method the derivation has are compared, the main one first. |
| query required | string | The problem, as sent to `POST /v1/query` with `steps`: `integrate(x*exp(x), x)`. |
| state required | string | The line the student is on, in the language's syntax. It is the query itself before the first step, and otherwise a line of the derivation as the response of `/v1/query` gives it (`Step.state`). |

### StepCheckResponse

`POST /v1/steps/check` response.

*StepCheckResponse*

| Field | Type | Description |
| --- | --- | --- |
| capped | boolean | The check reached the credits of its `effort` before it could decide, so `result` is `undecided` and nothing is known of the candidate: the engine was not given enough to try, which is not the engine failing to prove or refute. The derivation is kept, so a retry with a higher `effort` pays for the comparison only. |
| cut | boolean | The derivation had only the engine's one step (its budget ran out), so only `state` and the answer could be compared. |
| evidence | `EvidenceKind` or null | The kind of evidence the verdict rests on: for `current` and `later` that the candidate is the line's expression (`identical` or `canonical`); for `equivalent` the proof that it equals the line; for `different` what told it from `state`; for `undecided` `sampled` when the two agreed at sample points, else absent. |
| id required | string | This answer's id, for support. The service keeps it nowhere: usage is kept as totals per day. |
| matched | `Rendered` or null | The line the candidate matches or equals, as the derivation writes it (absent for `current`). |
| method | string or null | The method whose line the candidate matches, when it is an alternative of the main derivation (`Alternative::method`). Absent for a line of the main derivation. |
| points | integer or null | For `sampled` evidence: the number of points at which the two agreed. |
| result required | `StepCheckResult` |  |
| skipped | integer | For `later`: the lines of the derivation between `state` and the matched one, which the candidate skips. |
| step | integer or null | The step whose line the candidate matches: `Step.id`. For `current`, the step that produced `state` when `state` is one of its lines (absent for the problem itself); for `later` and `equivalent`, the step whose line it is. |
| truncated | boolean | Only the first steps of the derivation were compared (anonymous use). |
| usage required | `Usage` |  |

### StepCheckResult

How the candidate relates to the derivation.

*StepCheckResult*

| Value | Description |
| --- | --- |
| "current" | The candidate is `state` written again, or written in the same form (a sum in another order): no step was made. |
| "later" | The candidate is a later line of the derivation, in its form: `step` says which. |
| "equivalent" | The candidate is written as no line, but equals one in value (an expanded form of a factored line, the answer with the integral carried out): `step` and `matched` say which. It is a correct line that the derivation does not write. For an indefinite integral: the candidate is an antiderivative, with any constant. |
| "unmatched" | With `depth: form`: the candidate is written as none of the lines. Nothing more is claimed. |
| "different" | With `depth: value`: the candidate matches no line and equals none, and every comparison was decided: it is not equal to `state`, nor to a later line. For an indefinite integral: the candidate is not an antiderivative. |
| "undecided" | The candidate matches no line, and the engine could not decide some comparison (it neither proved the two lines equal nor refuted it). |
| "unknown" | A result this client does not know yet. |

### Steps

*Steps*

| Field | Type | Description |
| --- | --- | --- |
| alternatives | array of `Alternative` | Other methods that solve the same problem, each with its own verified derivation, when `QueryRequest::alternatives` asked for them. Empty when none was asked for or none applies. |
| answer | `Rendered` or null | The final answer, also when it is a list, a set or a matrix. |
| assumptions | array of `Rendered` | Conditions the derivation relies on: `x > 0`, `x != 2`, `a != 0`… |
| check | `Check` or null |  |
| cut | boolean | The narration ran out of its work budget; some sub-problems are `engine` steps. |
| explanation_version | integer or null | The catalog template version (`TEMPLATE_VERSION`) the explanations were rendered with. |
| items required | array of `Step` |  |
| method | string or null | The method of this derivation, as a rule id of the catalog (`integrate.parts`): the technique it took at the first choice point of the problem. It titles the main derivation beside its \[`alternatives`\](Steps::alternatives). Absent when the problem splits before any choice (a sum), has one route, or the derivation is not verified. |
| task | string or null | What was asked: `diff`, `integrate.definite`, `limit`… |
| truncated | boolean | Only a preview was returned (anonymous use). |
| verified required | boolean | The derivation reproduces the engine's answer. When false, `items` is a single `engine` step carrying the answer. |

### SubscriptionInfo

*SubscriptionInfo*

| Field | Type | Description |
| --- | --- | --- |
| cancel_at_period_end required | boolean |  |
| currency | string or null | ISO 4217, lowercase: the currency the subscription is billed in (`eur` where the price's table for the buyer's country is in euros). Absent while the server holds no price of the subscription, and from a server that does not send it: neither means US dollars. |
| current_period_end required | string |  |
| interval required | `BillingInterval` |  |
| legacy_price | `LegacyPrice` or null | The subscription pays a price that is no longer offered for its plan and interval. Absent on the price offered now. |
| plan required | `PlanId` |  |
| scheduled_change | `ScheduledChange` or null | A plan change that waits for the end of the current period. |
| status required | `SubscriptionStatus` |  |

### SubscriptionStatus

Mirrors Paddle's subscription status.

`"active"` or `"trialing"` or `"past_due"` or `"canceled"` or `"paused"` or `"unknown"`

### Surface

Where a request came from, taken from the credential and the route, never from a client's word.

*Surface*

| Value | Description |
| --- | --- |
| "web" | A visitor or a web session. |
| "cli" | A device `hbc_` token on REST. |
| "agents" | Anything on `/mcp`, and an OAuth `hbc_` token anywhere. |
| "api" | An `hbk_` key on REST. |
| "unknown" | A surface this client does not know yet. |

### Template

The sentence of a rule. A slot is `{key}`, a bind of the rule; `{?key|text}` is `text` only when `key` is bound. `crate::explain` renders it.

*Template*

| Field | Type | Description |
| --- | --- | --- |
| tex required | string | The sentence for `Explanation::tex`; the same slots. |
| text required | string | The sentence for `Explanation::text`. |

### Usage

What the query cost.

*Usage*

| Field | Type | Description |
| --- | --- | --- |
| balance | number or null | Credits left for this channel after the charge (absent for anonymous use). |
| credits required | number |  |
| limit | number or null | How many credits that limit allowed; absent when nothing stopped the run. |
| limited_by | `LimitSource` or null | What stopped the run; absent when nothing did. |
| notice | `UsageNotice` or null | Something to tell the person, carried by the one response whose charge crossed its mark; absent from every other. Only the web's and the CLI's credits (sessions and CLI sign-ins) have notices. |

### UsageKind

What a `UsageTotal` counts.

*UsageKind*

| Value | Description |
| --- | --- |
| "unknown" |  |
| "query" | Engine queries, an ask's included. |
| "ask" | The model's part of the asks (`POST /v1/ask`). |
| "step_check" | Checks of a line written under a derivation (`POST /v1/steps/check`). |

### UsageNotice

A notice of a charge (`Usage::notice`, `crate::AskUsage::notice`): each client words it itself. A mark is crossed by exactly one charge of a period (charges of an account are settled one at a time), so a client shows what it is given and keeps nothing to show it only once.

One of:

With this charge the month's credits of the plan, or the free month's, went under `below_percent` percent left: 25, then 10 (a charge that passes both says 10).

*UsageNotice*

| Field | Type | Description |
| --- | --- | --- |
| allowance required | number | The month's credits. |
| below_percent required | integer |  |
| kind required | `"credits_low"` |  |
| left required | number | What is left of them, in credits. |
| resets_at required | string | When they come back, as `crate::Balances::next_reset`. |

With this charge the CLI sign-in's daily limit went under `below_percent` percent left (10).

*UsageNotice*

| Field | Type | Description |
| --- | --- | --- |
| below_percent required | integer |  |
| kind required | `"daily_limit_low"` |  |
| left required | number | What is left of the limit today, in credits. |
| limit required | number |  |
| resets_at required | string | The end of the UTC day, when it starts again (as `details.resets_at` of a refusal at the limit). |

The subscription is past due: its renewal payment failed, and the plan's credits wait for it. The first charge of each UTC day carries it while it lasts.

*UsageNotice*

| Field | Type | Description |
| --- | --- | --- |
| kind required | `"renewal_failed"` |  |
| url required | string | The page where the card is updated (`/account#payment-methods` on the site). |

A notice this client does not know yet.

*UsageNotice*

| Field | Type | Description |
| --- | --- | --- |
| kind required | `"unknown"` |  |

### UsagePeriod

How long a `UsageTotal` covers.

*UsagePeriod*

| Value | Description |
| --- | --- |
| "unknown" |  |
| "day" | A day, in UTC. |
| "month" | A calendar month, in UTC. |

### UsageTotal

One line of `GET /v1/usage`: what the account spent in one period, on one channel, with one API key, on one kind of work.

*UsageTotal*

| Field | Type | Description |
| --- | --- | --- |
| channel required | `Channel` |  |
| count required | integer | How many were charged. |
| credits required | number |  |
| date required | string | The period's first day, `YYYY-MM-DD` (UTC). |
| key_id | string or null | The API key that spent it; absent for the web and the CLI. |
| kind required | `UsageKind` |  |
| period required | `UsagePeriod` |  |

### Visibility

How prominent a function is.

*Visibility*

| Value | Description |
| --- | --- |
| "core" | What a student meets first: suggested and listed first. |
| "advanced" | A function for a narrower task: suggested after the core ones and listed behind them. |
| "internal" | A helper of the engine: still read by the parser, never suggested or listed. |
| "unknown" | A visibility this client does not know yet. |

### Why

The reason for a method, in the two forms of an `Explanation`.

*Why*

| Field | Type | Description |
| --- | --- | --- |
| tex | string or null | The same sentence with math as `$…$` (TeX). Present when TeX was requested. |
| text required | string | One plain English sentence; math is input syntax in backticks. |

---
Source: https://ja.hilberon.com/developers/api
