Three things that help once you use the command-line tool every day or in scripts. Each one also shows how to do the same in code with the SDKs or the API.
Several accounts: profiles
apidly login --profile NAME saves a key under a name, next to your default one. Choose a profile for one command with --profile NAME or the APIDLY_PROFILE environment variable, or make it the default with apidly config use NAME. apidly config profiles lists the profiles and apidly config profiles rm NAME removes one. When APIDLY_API_KEY is set, it wins over every saved profile.
apidly login --profile work
apidly config profiles
apidly servers --profile work
APIDLY_PROFILE=work apidly balance
apidly config use work
apidly config profiles rm workCode has no profiles: each key is its own client. Keep each key in its own environment variable, never in the code.
curl "https://apidly.com/api/v1/me" \
-H "Authorization: Bearer $APIDLY_WORK_KEY"import { Apidly } from "@apidly/sdk";
const personal = new Apidly({ apiKey: process.env.APIDLY_API_KEY });
const work = new Apidly({ apiKey: process.env.APIDLY_WORK_KEY });
console.log((await work.billing.balance()).balance);
console.log((await personal.billing.balance()).balance);import os
from apidly import Client
personal = Client(api_key=os.environ["APIDLY_API_KEY"])
work = Client(api_key=os.environ["APIDLY_WORK_KEY"])
print(work.billing.balance()["balance"])
print(personal.billing.balance()["balance"])Update the CLI
apidly update looks for a newer version, downloads it from this site, checks its checksum and installs it with npm after asking you. --check only reports, with exit code 3 when a newer version is out, which suits a CI step; --print prints the commands instead of running them. The current version and the checksum of every file are also in latest.json.
apidly --version
apidly update --check
apidly update --print
apidly update --yes
curl -fsS "https://apidly.com/downloads/latest.json" | jq -r '.version'const res = await fetch("https://apidly.com/downloads/latest.json");
const latest = await res.json();
const cli = latest.files.find((f) => f.kind === "cli");
console.log(latest.version, cli.name, cli.sha256);import json
import urllib.request
with urllib.request.urlopen("https://apidly.com/downloads/latest.json") as res:
latest = json.load(res)
cli = next(f for f in latest["files"] if f["kind"] == "cli")
print(latest["version"], cli["name"], cli["sha256"])Wait for a server in a script
apidly servers wait ID returns with exit code 0 once the server is running, or 1 when it cannot get there, for example when the launch failed. --for stopped or --for destroyed waits for those states, and --timeout gives up after that many seconds (600 by default). apidly deploy --wait and apidly stop --wait wait in the same command. Ctrl-C ends the wait with exit code 130 and leaves the server as it is. With the API, read the server's status every few seconds.
apidly servers wait ins_ID
apidly servers wait ins_ID --for stopped --timeout 300
apidly deploy --plan rtx-4090-1x --template pytorch --yes --wait
apidly stop ins_ID --wait
until [ "$(curl -fsS "https://apidly.com/api/v1/servers/ins_ID" \
-H "Authorization: Bearer $APIDLY_API_KEY" | jq -r '.server.status')" = running ]; do
sleep 5
doneimport { Apidly } from "@apidly/sdk";
const apidly = new Apidly({ apiKey: process.env.APIDLY_API_KEY });
for (;;) {
const { server } = await apidly.servers.get("ins_ID");
if (server.status === "running") break;
if (server.status === "error" || server.status === "destroyed") {
throw new Error(server.statusMessage ?? server.status);
}
await new Promise((r) => setTimeout(r, 5000));
}import os
import time
from apidly import Client
client = Client(api_key=os.environ["APIDLY_API_KEY"])
while True:
server = client.servers.get("ins_ID")["server"]
if server["status"] == "running":
break
if server["status"] in ("error", "destroyed"):
raise SystemExit(server.get("statusMessage") or server["status"])
time.sleep(5)Ready to try it?
Create a free account and add credit when you want to start a server. The smallest top-up is $10.
Was this helpful?