Skip to main content
A complete function that returns your Telnyx account balance — declared, typed, shipped, and called.

1. Create a function

telnyx-edge new-func --language ts --name balance-check
cd balance-check

2. Declare the binding

Add a [telnyx] block to the generated func.toml:
# func.toml
[edge_compute]
func_id = "60c5ce48-…"   # created by new-func
func_name = "balance-check"

[telnyx]
binding = "MY_TELNYX"

3. Generate types

telnyx-edge types
env.MY_TELNYX is now typed as the Telnyx client.

4. Write the handler

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

const port = Number(process.env.PORT ?? 8080);

http.createServer(async (req, res) => {
  if (req.url?.startsWith("/health/")) return res.writeHead(200).end();

  const { data } = await env.MY_TELNYX.balance.retrieve();
  res.writeHead(200, { "content-type": "application/json" });
  res.end(JSON.stringify(data));
}).listen(port);

5. Ship

telnyx-edge ship

6. Call it

ship prints your function URL. Hit it:
curl https://balance-check-<id>.telnyxcompute.com
{
  "credit_limit": "1000.00",
  "frozen": "0.00",
  "currency": "USD",
  "available_credit": "1100.00",
  "pending": "0.00",
  "balance": "100.00",
  "record_type": "balance"
}