Skip to main content

Module model_gateway_handlers

Module model_gateway_handlers 

Source
Expand description

The model gateway: /api/v1/model/<route>/..., a streaming pass-through from an agent’s harness to a model route (docs/specs/SPEC_AGENT_MODEL_ROUTES_ANY_MODEL_SPAWN_AND_SWITCH_2026_11_06.md, section 4).

The caller proves itself with its gateway token, not the instance key, so these routes sit outside auth_middleware. srv reads the route’s key from the Vault, adds it to the upstream request and streams the answer back unbuffered, counting the usage that passes. The key is in this function’s memory for one request and nowhere else.

Structs§

Metered 🔒
The response body, reading usage from each chunk and writing it to the agent’s day when the body ends or the harness hangs up.

Constants§

CLOCKS_DIFFER 🔒
FRAMING 🔒
Response headers that describe the upstream’s framing, which this hop replaces.
MAX_REQUEST 🔒
The largest request body forwarded; a conversation is far below it.

Functions§

check_bound_peer 🔒
A token bound to a container’s address (a container agent’s turn) is used only from that container. Anything else showing it, including a request straight to srv with no proof of where it is from, is refused and the token ends. A token with no address (a host agent’s) is not asked for one.
denied 🔒
refuse, and the refusal in the log: its status, why, the route and, when the token is known, the agent and the account. Nothing of the token or of any key. A harness shows a refused request as a bare “HTTP 401 Not logged in”, so this line is where the cause is.
gateway_client 🔒
The client for model traffic. AppState::http_client ends every request 10 seconds after it starts, reading the body included, which would cut off a streamed answer; this one bounds connecting and each wait for the next chunk, and puts no limit on the whole answer.
handle_model_gateway 🔒
refuse 🔒
An error in the shape the harness already parses.
relay 🔒
The upstream’s answer, streamed through a meter that reads its usage. price_factor is what the route’s listed prices are multiplied by when the response has no charge of its own to count (Bedrock’s us profile costs more).
relay_body 🔒
A body (the upstream’s, or one made here from it) sent on through the meter. streaming: it is text/event-stream.
route_key 🔒
The route’s key from the Vault, or the answer that says it has none.
sensitive 🔒
A header value marked sensitive, so no log of the request prints it.
served_body 🔒
The request body with its model made one the route serves (the agent’s chosen when it names none that the route does).
verified_peer 🔒
Which container a gateway request is from, when it can be shown: the peer the container listener checked, or the one a forwarder’s stamp names with a proof made from this launch’s secret (container::gateway_fwd).