สามเรื่องที่ช่วยได้เมื่อคุณใช้ เครื่องมือบรรทัดคำสั่ง ทุกวันหรือในสคริปต์ แต่ละเรื่องยังแสดงวิธีทำแบบเดียวกันในโค้ดด้วย SDK หรือ API
หลายบัญชี: โปรไฟล์
apidly login --profile NAME บันทึกคีย์ไว้ภายใต้ชื่อหนึ่ง ข้างคีย์ค่าเริ่มต้นของคุณ เลือกโปรไฟล์สำหรับคำสั่งเดียวด้วย --profile NAME หรือตัวแปรสภาพแวดล้อม APIDLY_PROFILE หรือตั้งเป็นค่าเริ่มต้นด้วย apidly config use NAME apidly config profiles แสดงรายการโปรไฟล์ และ apidly config profiles rm NAME ลบหนึ่งโปรไฟล์ เมื่อตั้ง APIDLY_API_KEY ไว้ ค่านี้จะมีผลเหนือทุกโปรไฟล์ที่บันทึกไว้
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โค้ดไม่มีโปรไฟล์ คีย์แต่ละตัวคือไคลเอนต์ของตัวเอง เก็บคีย์แต่ละตัวไว้ในตัวแปรสภาพแวดล้อมของตัวเอง ห้ามเก็บไว้ในโค้ด
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"])อัปเดต CLI
apidly update จะหาเวอร์ชันที่ใหม่กว่า ดาวน์โหลดจากเว็บไซต์นี้ ตรวจ checksum และติดตั้งด้วย npm หลังจากถามคุณ --check แค่รายงาน โดยออกด้วยรหัส 3 เมื่อมีเวอร์ชันใหม่กว่า ซึ่งเหมาะกับขั้นตอน CI ส่วน --print จะพิมพ์คำสั่งแทนการรัน เวอร์ชันปัจจุบันและ checksum ของทุกไฟล์มีอยู่ใน 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"])รอเซิร์ฟเวอร์ในสคริปต์
apidly servers wait ID จบด้วยรหัสออก 0 ทันทีที่เซิร์ฟเวอร์ทำงาน หรือ 1 เมื่อไปถึงสถานะนั้นไม่ได้ เช่น เมื่อการเริ่มใช้งานล้มเหลว --for stopped หรือ --for destroyed จะรอสถานะเหล่านั้น และ --timeout จะเลิกรอหลังจากจำนวนวินาทีที่กำหนด (ค่าเริ่มต้น 600) apidly deploy --wait และ apidly stop --wait รอในคำสั่งเดียวกัน Ctrl-C จะหยุดการรอด้วยรหัสออก 130 และปล่อยเซิร์ฟเวอร์ไว้ตามเดิม เมื่อใช้ API ให้อ่าน status ของเซิร์ฟเวอร์ทุกไม่กี่วินาที
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)พร้อมลองแล้วหรือยัง
สร้างบัญชีฟรีและเติมเครดิตเมื่อต้องการเริ่มเซิร์ฟเวอร์ ยอดเติมเงินขั้นต่ำคือ $10
เนื้อหานี้มีประโยชน์หรือไม่