> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Agent Gateway Quick Start

> Create an Agent Gateway, issue a key, and connect an agent to it.

## Prerequisites

* A WireGuard Interface on a [*Network*](https://developers.telnyx.com/docs/network/overview.md), as in the [WireGuard Interface Quick Start](https://developers.telnyx.com/docs/network/wireguard-interfaces/quick-start.md). This page uses the interface `c788eb40-a4c0-4bf5-8f84-976027960f8e`.
* An Edge Compute function and the `telnyx-edge` CLI, as in the [Edge Compute Quick Start](https://developers.telnyx.com/docs/edge-compute/quickstart.md).

An Agent Gateway instance sits on the user's [*Network*](https://developers.telnyx.com/docs/network/overview.md). This page creates one, issues a key, and connects an agent to it.

## Create the Agent Gateway

Send [`POST /v2/agent_gateways`](https://developers.telnyx.com/api-reference/agent-gateways/create-an-agent-gateway) with the WireGuard Interface's `id`:

```json theme={null}
{
  "name": "support-gw",
  "wireguard_interface_id": "c788eb40-a4c0-4bf5-8f84-976027960f8e"
}
```

The response returns the instance `pending`, with no `gateway_url` yet. `network_id` is the WireGuard Interface's *Network*.

```json theme={null}
{
  "data": {
    "id": "32ce035d-3165-4031-b1a7-a7c0c259590a",
    "name": "support-gw",
    "status": "pending",
    "gateway_url": null,
    "wireguard_interface_id": "c788eb40-a4c0-4bf5-8f84-976027960f8e",
    "network_id": "7ade8c3c-95a7-447b-92f2-c829f760159c",
    ...
  }
}
```

## Wait for the Gateway

Poll [`GET /v2/agent_gateways/{id}`](https://developers.telnyx.com/api-reference/agent-gateways/retrieve-an-agent-gateway) 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:

```json theme={null}
{
  "data": {
    "id": "32ce035d-3165-4031-b1a7-a7c0c259590a",
    "status": "ready",
    "gateway_url": "http://172.27.0.4:4000",
    ...
  }
}
```

## Issue a Key

The instance refuses a request without a [key](https://developers.telnyx.com/docs/agent-gateway/authentication/keys.md). Send [`POST /v2/agent_gateways/{id}/keys`](https://developers.telnyx.com/api-reference/agent-gateway-keys/create-a-key) with a name for the agent that holds it:

```json theme={null}
{
  "name": "support-agent"
}
```

The response carries the key's value in `key`, and no later response returns it:

```json theme={null}
{
  "data": {
    "id": "9b1f1703ade70a9e35be9ac96d439ce3bc8e68ca7fd0ae5fa4d847977d23f7bc",
    "key": "sk-EXAMPLE-KEY-VALUE",
    "name": "support-agent",
    "models": [],
    "blocked": false,
    ...
  }
}
```

## Connect an Agent

An agent on Edge Compute reaches the instance through a [network binding](https://developers.telnyx.com/docs/edge-compute/runtime/bindings/network.md) to the instance's WireGuard Interface. In the function's `func.toml`, bind the interface and set the instance's `gateway_url`:

```toml func.toml theme={null}
[network.PRIVATE_NET]
id = "c788eb40-a4c0-4bf5-8f84-976027960f8e"

[env_vars]
GATEWAY_URL = "http://172.27.0.4:4000"
```

Store the key from [Issue a Key](#issue-a-key) as a secret:

```bash Workstation theme={null}
telnyx-edge secrets add AGENT_GATEWAY_KEY "$AGENT_GATEWAY_KEY"
```

The function sends a chat completion to `gateway_url` through the binding, with the key:

```ts index.ts theme={null}
import * as http from "node:http";
import { env } from "@telnyx/edge-runtime";

const { GATEWAY_URL, AGENT_GATEWAY_KEY } = process.env;

const server = http.createServer(async (req, res) => {
  if (req.url === "/health" || req.url?.startsWith("/health/")) {
    res.writeHead(200); res.end(); return;
  }
  const response = await env.PRIVATE_NET.fetch(`${GATEWAY_URL}/v1/chat/completions`, {
    method: "POST",
    headers: { "Content-Type": "application/json", Authorization: `Bearer ${AGENT_GATEWAY_KEY}` },
    body: JSON.stringify({
      model: "GLM-5.3-Flash",
      messages: [{ role: "user", content: "Say hello in five words." }],
    }),
  });
  const completion = await response.json();
  res.writeHead(200, { "Content-Type": "application/json" });
  res.end(JSON.stringify({ answer: completion.choices[0].message.content }));
});

server.listen(process.env.PORT || 8080);
```

Generate the binding's types, and ship the function:

```bash Workstation theme={null}
telnyx-edge types
telnyx-edge ship
```

Send the function a request:

```bash Workstation theme={null}
curl https://acme-agent-6a01e98a-b.telnyxcompute.com
```

```json Output theme={null}
{"answer":"Hello, nice to meet you!"}
```

The instance's [spend logs](https://developers.telnyx.com/docs/agent-gateway/observability/spend-logs.md) list the request under the key `support-agent`.

## Delete the Agent Gateway

[`DELETE /v2/agent_gateways/{id}`](https://developers.telnyx.com/api-reference/agent-gateways/delete-an-agent-gateway) returns the instance `deleting`. The gateway stops answering at once, and seconds later `GET /v2/agent_gateways/{id}` returns `404`.

```json theme={null}
{
  "data": {
    "id": "32ce035d-3165-4031-b1a7-a7c0c259590a",
    "status": "deleting",
    ...
  }
}
```
