Skip to main content

Prerequisites

An Agent Gateway instance sits on the user’s Network. This page creates one, issues a key, and connects an agent to it.
New instances currently cannot finish provisioning: they move from pending to failed at their database migration (AIPLAT-1702), so a newly created instance does not reach ready. The steps on this page ran on instances that provisioned before this regression.

Create the Agent Gateway

Send POST /v2/agent_gateways with the WireGuard Interface’s id:
The response returns the instance pending, with no gateway_url yet. network_id is the WireGuard Interface’s Network.

Wait for the Gateway

Poll GET /v2/agent_gateways/{id} until status is ready. The instance joins the WireGuard Interface as a peer named agw-32ce035d-3165-4031-b1a7-a7c0c259590a, which puts the interface in provisioning again. The instance is ready once the interface is provisioned and the instance answers through the tunnel. Here that took 172 seconds. gateway_url is its address on the interface:

Issue a Key

The instance refuses a request without a key. Send POST /v2/agent_gateways/{id}/keys with a name for the agent that holds it:
The response carries the key’s value in key, and no later response returns it:

Connect an Agent

An agent on Edge Compute reaches the instance through a network binding to the instance’s WireGuard Interface. In the function’s func.toml, bind the interface and set the instance’s gateway_url:
func.toml
Store the key from Issue a Key as a secret:
Workstation
The function sends a chat completion to gateway_url through the binding, with the key:
index.ts
Generate the binding’s types, and ship the function:
Workstation
Send the function a request:
Workstation
Output
The instance’s spend logs list the request under the key support-agent.

Delete the Agent Gateway

DELETE /v2/agent_gateways/{id} returns the instance deleting. The gateway stops answering at once, and seconds later GET /v2/agent_gateways/{id} returns 404.