Skip to main content
Apidly Cloud
Cookie policy

Analytics and ad cookies stay off unless you accept. Cookie policy

We would like to use Google Analytics and Microsoft Clarity to understand how the public pages are used, including page views and session recordings, and the Reddit Pixel to measure whether our ads on Reddit lead to visits and sign-ups. You choose here whether they are on. Rejecting changes nothing about how the site works.

CLI profiles, updates and waiting

Keep several accounts in the apidly command with profiles, update it with a checked download, and make scripts wait until a server is running or stopped.

Last updated November 24, 20262 min read
View as Markdown

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 work

Code 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
done
import { 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.

Create a free account

Was this helpful?

Still stuck? Contact us