Fly.io's Machines API lets you create, start, stop, and destroy VMs programmatically at the edge. Deploy containers to 30+ regions with a single API call.
Authentication
export FLY_API_TOKEN=$(flyctl auth token)
curl -H "Authorization: Bearer $FLY_API_TOKEN" \
https://api.machines.dev/v1/apps
Key Operations
List Apps
curl -H "Authorization: Bearer $FLY_TOKEN" \
https://api.machines.dev/v1/apps?org_slug=personal
Create a Machine
curl -X POST -H "Authorization: Bearer $FLY_TOKEN" \
-H "Content-Type: application/json" \
https://api.machines.dev/v1/apps/my-app/machines \
-d '{
"config": {
"image": "nginx:latest",
"guest": {"cpu_kind": "shared", "cpus": 1, "memory_mb": 256},
"services": [{"ports": [{"port": 443, "handlers": ["tls","http"]}], "protocol": "tcp", "internal_port": 80}]
},
"region": "ams"
}'
Stop/Start/Destroy
# Stop
curl -X POST https://api.machines.dev/v1/apps/my-app/machines/machine-id/stop
# Start
curl -X POST https://api.machines.dev/v1/apps/my-app/machines/machine-id/start
# Destroy
curl -X DELETE https://api.machines.dev/v1/apps/my-app/machines/machine-id
Scale to Multiple Regions
import requests
FLY_URL = "https://api.machines.dev/v1"
headers = {"Authorization": f"Bearer {TOKEN}", "Content-Type": "application/json"}
regions = ["ams", "lax", "nrt", "syd"]
for region in regions:
r = requests.post(f"{FLY_URL}/apps/my-app/machines",
headers=headers,
json={"config": {"image": "my-app:latest", "guest": {"cpus": 1, "memory_mb": 256}}, "region": region}
)
print(f"{region}: {r.json().get('id', 'error')}")
Why This Matters
- Edge computing: Deploy to 30+ regions in seconds
- Scale to zero: Machines stop when idle, saving costs
- Custom orchestration: Build your own PaaS on top of Fly
- GPU workloads: Spin up GPU machines on demand
Need custom edge deployment tools or distributed infrastructure? I build developer tools and data pipelines. Check out my web scraping actors on Apify or reach out at spinov001@gmail.com for custom solutions.
Top comments (0)