#!/usr/bin/env python3
"""Find the cheapest GPU offer, procure it, and print SSH access details."""
import time
import requests
BASE_URL = "https://supply-api.compute-desk.com"
TOKEN = "YOUR_TOKEN"
SSH_PUBLIC_KEY = "ssh-ed25519 AAAA... your-key"
headers = {"Authorization": f"Bearer {TOKEN}"}
# Step 1: Get offers
yaml_spec = """
compute:
gpu_type: H100
gpu_count: 1
max_price_per_gpu_hour: 5
contract_type: ondemand
"""
print("Fetching offers...")
resp = requests.post(
f"{BASE_URL}/get_offers",
data=yaml_spec,
headers={**headers, "Content-Type": "application/yaml"},
timeout=30,
)
resp.raise_for_status()
offers = resp.json()["offers"]
if not offers:
print("No offers found")
exit(1)
# Step 2: Pick the cheapest
cheapest = min(offers, key=lambda o: o["gpu_price_per_hour"])
offer_id = cheapest["offer_id"]
print(f"Cheapest: {cheapest['vendor']} — ${cheapest['gpu_price_per_hour']:.4f}/GPU/hr")
# Step 3: Procure
print(f"Procuring {offer_id}...")
resp = requests.post(
f"{BASE_URL}/procure_offer",
json={"offer_id": offer_id, "ssh_public_key": SSH_PUBLIC_KEY},
headers=headers,
timeout=300,
)
resp.raise_for_status()
print(f"Status: {resp.json()['status']}")
# Step 4: Poll until ready
print("Waiting for instance...")
for _ in range(120): # up to 30 minutes
status = requests.get(
f"{BASE_URL}/offers/{offer_id}/status", headers=headers
).json()
procurement = status["procurement_status"]
if procurement == "ready":
instance = status["instances"][0]
ip = instance.get("external_ip")
ssh_cmd = instance.get("ssh_command")
print(f"\nInstance ready!")
print(f" IP: {ip}")
print(f" SSH: ssh -i ~/.ssh/your_private_key {ssh_cmd.split('ssh ')[-1] if ssh_cmd else f'root@{ip}'}")
break
if procurement == "failed":
print(f"Failed: {status.get('failure_reason')}")
exit(1)
print(f" {procurement}...")
time.sleep(15)
# Step 5: Clean up (uncomment when done)
# resources = requests.get(
# f"{BASE_URL}/resources?offer_id={offer_id}", headers=headers
# ).json()["resources"]
# for r in resources:
# requests.delete(
# f"{BASE_URL}/resources/{r['resource_id']}?force=true", headers=headers
# )
# print(f"Deleted {r['resource_id']}")
import fetch from "node-fetch";
const BASE_URL = "https://supply-api.compute-desk.com";
const TOKEN = "YOUR_TOKEN";
const SSH_PUBLIC_KEY = "ssh-ed25519 AAAA... your-key";
const headers = {
Authorization: `Bearer ${TOKEN}`,
"Content-Type": "application/json",
};
async function main() {
// Step 1: Get offers
const yamlSpec = `
compute:
gpu_type: H100
gpu_count: 1
max_price_per_gpu_hour: 5
contract_type: ondemand
`;
console.log("Fetching offers...");
const offersResp = await fetch(`${BASE_URL}/get_offers`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/yaml" },
body: yamlSpec,
});
const { offers } = (await offersResp.json()) as any;
if (!offers?.length) {
console.log("No offers found");
return;
}
// Step 2: Pick the cheapest
const cheapest = offers.reduce((a: any, b: any) =>
a.gpu_price_per_hour < b.gpu_price_per_hour ? a : b
);
const offerId = cheapest.offer_id;
console.log(
`Cheapest: ${cheapest.vendor} — $${cheapest.gpu_price_per_hour.toFixed(4)}/GPU/hr`
);
// Step 3: Procure
console.log(`Procuring ${offerId}...`);
const procureResp = await fetch(`${BASE_URL}/procure_offer`, {
method: "POST",
headers,
body: JSON.stringify({
offer_id: offerId,
ssh_public_key: SSH_PUBLIC_KEY,
}),
});
const procureResult = (await procureResp.json()) as any;
console.log(`Status: ${procureResult.status}`);
// Step 4: Poll until ready
console.log("Waiting for instance...");
for (let i = 0; i < 120; i++) {
const statusResp = await fetch(`${BASE_URL}/offers/${offerId}/status`, {
headers,
});
const status = (await statusResp.json()) as any;
const procurement = status.procurement_status;
if (procurement === "ready") {
const instance = status.instances[0];
console.log(`\nInstance ready!`);
console.log(` IP: ${instance.external_ip}`);
console.log(` SSH: ssh -i ~/.ssh/your_private_key root@${instance.external_ip}`);
break;
}
if (procurement === "failed") {
console.error(`Failed: ${status.failure_reason}`);
return;
}
console.log(` ${procurement}...`);
await new Promise((r) => setTimeout(r, 15000));
}
// Step 5: Clean up (uncomment when done)
// const resources = await fetch(
// `${BASE_URL}/resources?offer_id=${offerId}`, { headers }
// ).then(r => r.json()) as any;
// for (const r of resources.resources) {
// await fetch(`${BASE_URL}/resources/${r.resource_id}?force=true`, {
// method: "DELETE", headers,
// });
// console.log(`Deleted ${r.resource_id}`);
// }
}
main().catch(console.error);
What this does
- Get offers — queries all vendors for H100 x1 under $5/GPU/hr
- Pick cheapest — selects the lowest-priced offer
- Procure — provisions the instance with your SSH key
- Poll — waits up to 30 minutes for the instance to be ready
- Clean up — code to delete the resource (commented out by default)
Customizing
Change the YAML spec to match your needs. See the YAML Spec guide for all available options:yaml_spec = """
region: EU
vendor: nebius
compute:
gpu_type: A100
gpu_count: 8
max_price_per_gpu_hour: 2.50
contract_type: ondemand
cloud_init: |
#cloud-config
packages:
- htop
- nvidia-container-toolkit
"""