1. Create a function
2. Declare the binding
Add a[telnyx] block to the generated func.toml:
3. Generate types
env.MY_TELNYX is now typed as the Telnyx client.
4. Write the handler
5. Ship
6. Call it
ship prints your function URL. Hit it:
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Check out our upcoming events and meetups! View events →
Declare, type, and ship a function that returns your Telnyx account balance through the binding.
telnyx-edge new-func --language ts --name balance-check
cd balance-check
[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"
telnyx-edge types
env.MY_TELNYX is now typed as the Telnyx client.
// 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);
telnyx-edge ship
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"
}
Was this page helpful?