# API reference: llm

The model gateway. One interface to AI models from Anthropic, OpenAI, Google Gemini and OpenRouter. Each call is metered and billed to the workspace, or made with the workspace's own key for that vendor.

## GET /v1/llm/models

`listLlmModels` · scope `none` · The AI models the hub offers, with their prices

Lists every AI model the hub can call, grouped by vendor. Each model carries its vendor's list price per million tokens and the price the hub charges for it.

The charged price is the list price plus the hub's markup when this hub takes payments. It is the list price when it does not. A call made with a workspace's own key for that vendor is not charged for the model.

`served` says whether this hub holds its own key for the vendor. A vendor the hub does not serve still works with a workspace's own key. Every price names the page it was read from and the date it was read.

Responses:

- `200`: The catalogue.
- `401`: Missing or invalid credentials.

## POST /v1/llm/messages

`createLlmMessage` · scope `key:train` · One AI model call for a MouseMouse agent

Sends one turn of an agent's conversation to a catalogue model and returns the model's answer. This serves MouseMouse's own agents only: the desktop app, the CLI and the hub's web agent. It is not a general model API, and the terms of use say so.

A request names its client in `X-MouseMouse-Client` and carries the agent's tool definitions. A request without both is `403` (`llm.internal_only`). Calls are limited per credential per minute.

Messages use MouseMouse's message format: text, images, tool calls and tool results as content blocks. The hub rebuilds every block from the fields the format documents, and refuses any other field with `422`. Images are base64 PNG, JPEG, GIF or WebP only, at most 5 MiB and 8000 pixels a side. No URL or file reference is passed to a vendor, and the hub sets its own prompt caching. The hub translates the blocks for the model's vendor and translates the answer back. With `stream: true` the answer is server-sent events: `message_start`, then `content_block_start`, `content_block_delta` and `content_block_stop` for each block, then `message_stop` carrying the whole message and its cost, or `error`.

Every call is billed to a workspace, yours by default. With the workspace's own key for the vendor the model costs nothing here. Without one, the hub's key answers and the call counts toward the plan. Before the call its most possible cost is held. After it the cost is settled on the vendor's reported usage. The hold counts each image by the vendor's own rule, text at one token per byte, and the full `max_tokens`. A call the vendor bills past its hold is charged in full. Until that excess fits the workspace's balance, the credential's next call is `402` (`llm.overshoot_unsettled`). A usage field the hub cannot price bills the whole hold. `402` also means there is no key the hub may use, or the workspace's limit or the key's cap would be passed. A vendor that keeps refusing or failing after the retries is `502` or `503`, naming the vendor.

Parameters:

- `X-MouseMouse-Client` (header, required): The MouseMouse client making the call and its version, such as `mousemouse-ide/0.1.0`, `mousemouse-cli/0.4.2` or `mousemouse-web/1`.

Request body: `application/json`, required.

Responses:

- `200`: The model's answer. With `stream: true` this is `text/event-stream`, and the last `message_stop` event carries the same object.
- `401`: Missing or invalid credentials.
- `402`: No key the hub may use for this vendor, or the call would pass a limit: the workspace's own key's monthly cap, or the workspace's balance. `type` and `errors[].type` say which: `model_key_required`, `model_cap_reached`, `billing.cap_reached` or `llm.overshoot_unsettled`. `settings_url` is where a person fixes it. Nothing was spent.
- `403`: Authenticated but not allowed (visibility, membership or scope).
- `422`: Request failed validation.
- `502`: The model's vendor failed the call after the hub's retries, or did not answer in time. The detail names the vendor.
- `503`: A service this endpoint needs is not configured in this deployment. The API boots with zero secrets. An endpoint that needs one says so instead of returning a stack trace.
- `504`: The model's vendor failed the call after the hub's retries, or did not answer in time. The detail names the vendor.
