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_clientends 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_factoris what the route’s listed prices are multiplied by when the response has no charge of its own to count (Bedrock’susprofile costs more). - relay_
body 🔒 - A body (the upstream’s, or one made here from it) sent on through the meter.
streaming: it istext/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
chosenwhen 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).