> ## 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.

# Network Binding

> Send HTTP requests from an Edge Compute function to WireGuard peers via a WireGuard Interface.

A network binding joins a function to a WireGuard Interface. When the function deploys, it becomes a peer of that WireGuard Interface, and `env.<NAME>.fetch()` sends HTTP requests via the interface to its other peers. Each request is recorded in the function's logs.

## Requirements

* `telnyx-edge` v0.5.10 or later
* `@telnyx/edge-runtime` v0.16.0 or later
* A Network with a WireGuard Interface in `provisioned` status
* A host on the WireGuard Interface running the target HTTP service

<Note>
  The binding's `id` is the WireGuard Interface UUID, not the parent Network UUID.
</Note>

## Prepare the target service

Follow the [WireGuard Interfaces Quick Start](/docs/network/wireguard-interfaces/quick-start) to:

1. Create a Network with `POST /v2/networks`.
2. Create a WireGuard Interface with `POST /v2/wireguard_interfaces`.
3. Poll `GET /v2/wireguard_interfaces/{id}` until its status is `provisioned`. Provisioning takes a few minutes, and peers cannot be added while the interface is still provisioning.
4. Register the target host as a peer with `POST /v2/wireguard_peers`. Save the `private_key` from the create response; it is returned only once.
5. Retrieve the peer configuration with `GET /v2/wireguard_peers/{id}/config`, replace the private-key placeholder, and bring the tunnel up on the target host.

Run the HTTP service on the host's WireGuard address and a port, for example `172.27.0.2:8787`. Allow traffic from the WireGuard subnet in the host firewall.

## Declare the binding

Add a `[network.<name>]` block to `func.toml` or `telnyx.toml`. The block name becomes the property on `env`.

```toml theme={null}
[network.PRIVATE_NET]
id = "<wireguard-interface-uuid>"
```

Regenerate the TypeScript declarations after changing the manifest:

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

## Send a request through the binding

Pass a URL with the target host's WireGuard address to `fetch()`:

```ts theme={null}
import { env } from "@telnyx/edge-runtime";

const response = await env.PRIVATE_NET.fetch(
  "http://172.27.0.2:8787/health",
);

if (!response.ok) {
  throw new Error(`Private service returned ${response.status}`);
}

const body = await response.text();
```

`fetch()` accepts a URL string, `URL`, or `Request`, plus an optional `RequestInit`, and returns a `Promise<Response>`.

## Deploy and verify

Ship the function:

```bash theme={null}
telnyx-edge ship --timeout 15m
```

Deploying adds the function to the WireGuard Interface as a peer named `func-<function-id>`.

Call the function's HTTPS URL, then inspect its logs and deployment history:

```bash theme={null}
telnyx-edge logs <function> --since 10m
telnyx-edge deployments <function>
```

Each `env.<NAME>.fetch()` call appears in the logs with the WireGuard Interface ID:

```text theme={null}
[2026-10-12T15:42:49.156Z] [unknown] [network:f9885539-14e4-4ee3-bce5-ae3dc6c7d379] fetch GET http://[redacted]:8787/health
```

`GET /v2/wireguard_peers?filter[wireguard_interface_id]={id}` lists the function peer with the WireGuard Interface's other peers.
