Recipe

Order a paid server from code

Spin up a paid server from a script, with the card already on your account, without ever buying two by accident.

← Panel API docsUpdated

Browse the docs

Turn on purchases for one key

No API key can spend money until you allow it. Make a key for this job alone, and in the panel give it the "make purchases" account scope (billing.purchase). Buying needs a card already saved on your account: buy once in the panel and it is kept for next time.

Each key may start 2 orders in any 24 hours, and you are emailed about every order a key starts.

Order with an Idempotency-Key

Send a unique Idempotency-Key header with the order, and keep it. If the request times out and you send it again with the same key, you get the order you already started rather than a second server. Use a new key for each server you mean to buy.

order.py

import os
import time
import uuid

import requests

API = "https://sillydev.co.uk/panel/api/client"
HEADERS = {"Authorization": f"Bearer {os.environ['SILLYDEV_API_KEY']}", "Accept": "application/json"}

order_key = str(uuid.uuid4())  # Save this somewhere before sending, to retry safely.

response = requests.post(
    f"{API}/billing/checkout",
    headers={**HEADERS, "Idempotency-Key": order_key},
    json={"name": "Music bot", "runtime": "nodejs", "use_saved_card": True},
    timeout=30,
)
response.raise_for_status()
order = response.json()["attributes"]
print("Order", order["order_uuid"])

Wait for the server

With a saved card the order goes straight to being built. While it is, it is listed in meta.pending_orders of GET /, the server list; once built it is in the list itself, under the name you gave it. If your bank asks you to confirm the payment, you are emailed a link, as for any renewal, and the server is built once you do.

Continuing order.py

for _ in range(60):
    servers = requests.get(f"{API}?per_page=100", headers=HEADERS, timeout=10).json()
    built = [s["attributes"] for s in servers["data"] if s["attributes"]["name"] == "Music bot"]
    if built:
        print("Ready:", built[0]["identifier"])
        break
    time.sleep(10)

Without a saved card

Leave out use_saved_card and the url in the response is a Stripe Checkout page. Nothing is bought until a person opens it and pays, so this suits a script that sends someone a payment link rather than one that buys on its own.

FAQ

Questions

Can a leaked key buy servers?

Only a key you gave the purchase scope, only a few times a day, and you are emailed each time with what was bought, so you can cancel it and delete the key. Keys without that scope cannot spend anything.

Read next