Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ gpushed plans
| `t4` | 1x Tesla T4 16 GB | n1-standard-8 | $0.91 |
| `l4` (default) | 1x L4 24 GB | g2-standard-4 | $0.88 |
| `a100` | 1x A100 40 GB | a2-highgpu-1g | $4.44 |
| `h100` (coming soon) | 1x H100 80 GB | a3-highgpu-1g | $13.21 |

`h100` is listed but can't be created yet: it's waiting on GCP H100 quota.

Prices are GCP's on-demand cost of the machine, its 100 GB SSD and IP, plus
20%. A box is billed per second from when it's created until it's deleted. A
Expand All @@ -64,7 +67,8 @@ for your region, `gpushed plans --region asia-southeast1` for another, and

**Balance.** Credit is prepaid: the minimum top-up is $10, and you can top up
any amount above that at any time with `gpushed topup 25`. To create or start a
box you need at least one hour of its price in your balance.
box you need at least one hour of its price in your balance. Premium plans,
those at $10/hour or more (`h100`), need $100.

**Running out.** When your balance falls below $2 you get an email. When it's
nearly used up, your box is **stopped** (its disk is kept) and you get another
Expand Down
1 change: 1 addition & 0 deletions api/scripts/gcp-prices.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const PLANS = {
l4: { family: "G2 Instance", vcpu: 4, ramGb: 16, gpu: "Nvidia L4 GPU" },
a100: { family: "A2 Instance", vcpu: 12, ramGb: 85, gpu: "Nvidia Tesla A100 GPU" },
"a100-80": { family: "A2 Instance", vcpu: 12, ramGb: 170, gpu: "Nvidia Tesla A100 80GB GPU" },
h100: { family: "A3 Instance", vcpu: 26, ramGb: 234, gpu: "Nvidia H100 80GB GPU" },
};

const COMPUTE = "6F81-5844-456A"; // Compute Engine's service id in the catalog
Expand Down
1 change: 1 addition & 0 deletions api/scripts/gcp-zones.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const PLANS = {
l4: { machineType: "g2-standard-4", gpuType: "" },
a100: { machineType: "a2-highgpu-1g", gpuType: "" },
"a100-80": { machineType: "a2-ultragpu-1g", gpuType: "" },
h100: { machineType: "a3-highgpu-1g", gpuType: "" },
};

const project = process.argv[2];
Expand Down
34 changes: 25 additions & 9 deletions api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type Box, type User, credit, getBox, meterBox, runMetering, updateBox, welcomeOnFirstTopup } from "./billing";
import { type Env, numVar } from "./env";
import { type ProvisionAction, dispatchProvision } from "./external";
import { DEFAULT_PLAN, PLANS, planPrice } from "./pricing";
import { DEFAULT_PLAN, PLANS, isPremium, planPrice, requiredBalanceMicros } from "./pricing";
import { REGIONS, byDistance, enabledRegions, regionOfZone, requestLocation } from "./regions";
import { PLAN_ZONES } from "./zones.generated";
import { type CheckoutSession, createCheckoutSession, topupCents, verifyStripeSignature } from "./stripe";
Expand Down Expand Up @@ -280,13 +280,22 @@ route("GET", "/plans", async (req, env) => {
plans: Object.values(PLANS).flatMap((p) => {
const price = planPrice(p, region.id, premium);
if (!price) return [];
// Enabled regions with a price and at least one zone offering the machine.
const where = enabledRegions(env.REGIONS, p.id).filter((r) => (PLAN_ZONES[p.id]?.[r.id] ?? []).length > 0);
const offered = where.some((r) => r.id === region.id);
return [
{
id: p.id,
label: p.label,
machine_type: p.machineType,
hourly_usd: usd(price.hourlyMicros),
stopped_hourly_usd: usd(price.stoppedHourlyMicros),
premium: isPremium(price.hourlyMicros),
min_balance_usd: usd(requiredBalanceMicros(price.hourlyMicros)),
// available: can be created now; unavailable: not offered yet (no GCP
// quota); elsewhere: offered, but not in this region.
status: !p.available || where.length === 0 ? "unavailable" : offered ? "available" : "elsewhere",
regions: p.available ? where.map((r) => r.id) : [],
},
];
}),
Expand Down Expand Up @@ -393,11 +402,19 @@ route("POST", "/stripe/webhook", async (req, env) => {

// ---------------------------------------------------------------- boxes

function balanceShortMessage(balanceMicros: number, planId: string, hourlyMicros: number, neededMicros: number): string {
const why = isPremium(hourlyMicros)
? `the $${usd(neededMicros)} minimum for ${planId}, a premium plan ($${usd(hourlyMicros)}/h)`
: `one hour of ${planId} ($${usd(neededMicros)})`;
return `balance $${usd(balanceMicros)} is less than ${why}; run gpushed topup`;
}

route("POST", "/box", async (req, env) => {
const user = await authUser(req, env);
const body = await readJson<{ plan?: string; ssh_public_key?: string; region?: string }>(req);
const plan = PLANS[body.plan ?? DEFAULT_PLAN];
if (!plan) throw new HttpError(400, `unknown plan; choose one of: ${Object.keys(PLANS).join(", ")}`);
if (!plan.available) throw new HttpError(503, `${plan.id} isn't available yet; see gpushed plans`);
// Drop the key's comment: it ends up in GCE metadata as "user:type key".
const key = String(body.ssh_public_key ?? "").trim().split(/\s+/).slice(0, 2).join(" ");
if (!SSH_KEY_RE.test(key) || key.length > 4096) throw new HttpError(400, "invalid SSH public key");
Expand All @@ -417,14 +434,12 @@ route("POST", "/box", async (req, env) => {
}
if (candidates.length === 0) throw new HttpError(503, `${plan.id} isn't available right now`);
const premium = numVar(env.PREMIUM_PCT, 20);
// At least an hour at the price shown for the first region (what plans shows).
// At least an hour at the price shown for the first region (what plans
// shows), or $100 for a premium plan.
const price = planPrice(plan, candidates[0].id, premium)!;
const needed = price.hourlyMicros;
const needed = requiredBalanceMicros(price.hourlyMicros);
if (user.balance_micros < needed) {
throw new HttpError(
402,
`balance $${usd(user.balance_micros)} is less than one hour of ${plan.id} ($${usd(needed)}); run gpushed topup`,
);
throw new HttpError(402, balanceShortMessage(user.balance_micros, plan.id, price.hourlyMicros, needed));
}
const now = nowSec();
const box: Box = {
Expand Down Expand Up @@ -479,8 +494,9 @@ route("POST", "/box/start", async (req, env) => {
const box = await activeBox(env, user.id);
if (!box) throw new HttpError(404, "you have no box");
if (box.status !== "stopped") throw new HttpError(409, `box is ${box.status}; only a stopped box can be started`);
if (user.balance_micros < box.hourly_micros) {
throw new HttpError(402, `balance $${usd(user.balance_micros)} is less than one hour of use; run gpushed topup`);
const needed = requiredBalanceMicros(box.hourly_micros);
if (user.balance_micros < needed) {
throw new HttpError(402, balanceShortMessage(user.balance_micros, box.plan, box.hourly_micros, needed));
}
const now = nowSec();
const updated = await updateBox(env, box, { status: "starting" }, now);
Expand Down
33 changes: 33 additions & 0 deletions api/src/pricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export interface Plan {
machineType: string;
gpuType: string; // "" when the machine type has the GPU built in (A2, G2)
gpuCount: number;
// False while GCP hasn't granted us quota for it: listed in `gpushed plans`
// with its price, but a box can't be created on it yet.
available: boolean;
}

// The machine each plan runs on. scripts/gcp-prices.mjs has the same plans
Expand All @@ -23,20 +26,34 @@ export const PLANS: Record<string, Plan> = {
machineType: "n1-standard-8",
gpuType: "nvidia-tesla-t4",
gpuCount: 1,
available: true,
},
l4: {
id: "l4",
label: "1x NVIDIA L4 24 GB, 4 vCPU, 16 GB RAM",
machineType: "g2-standard-4",
gpuType: "",
gpuCount: 0,
available: true,
},
a100: {
id: "a100",
label: "1x NVIDIA A100 40 GB, 12 vCPU, 85 GB RAM",
machineType: "a2-highgpu-1g",
gpuType: "",
gpuCount: 0,
available: true,
},
// GCP's on-demand H100 quota (GPUS_PER_GPU_FAMILY, NVIDIA_H100) is 0 in our
// project; flip `available` once it's granted. Spot quota doesn't count:
// boxes run on-demand.
h100: {
id: "h100",
label: "1x NVIDIA H100 80 GB, 26 vCPU, 234 GB RAM",
machineType: "a3-highgpu-1g",
gpuType: "",
gpuCount: 0,
available: false,
},
};

Expand All @@ -49,6 +66,7 @@ export const PLANS: Record<string, Plan> = {
// machineType: "a2-ultragpu-1g",
// gpuType: "",
// gpuCount: 0,
// available: true,
// },

export const DEFAULT_PLAN = "l4";
Expand Down Expand Up @@ -84,6 +102,21 @@ export function planPrice(plan: Plan, region: string, premiumPct: number) {
};
}

// Premium plans (H100 today) cost $10/hour or more, and need $100 in the
// balance to create or start a box, so a box isn't stopped for lack of credit
// a few minutes in. Every other plan needs an hour of use.
export const PREMIUM_HOURLY_USD = 10;
export const PREMIUM_MIN_BALANCE_USD = 100;

export function isPremium(hourlyMicros: number): boolean {
return hourlyMicros >= PREMIUM_HOURLY_USD * 1e6;
}

// Balance, in micro-dollars, needed to create or start a box at this rate.
export function requiredBalanceMicros(hourlyMicros: number): number {
return isPremium(hourlyMicros) ? Math.max(hourlyMicros, PREMIUM_MIN_BALANCE_USD * 1e6) : hourlyMicros;
}

// Charge for `seconds` at an hourly rate, rounded down to the micro-dollar.
export function chargeMicros(hourlyMicros: number, seconds: number): number {
if (seconds <= 0 || hourlyMicros <= 0) return 0;
Expand Down
17 changes: 11 additions & 6 deletions api/src/regions.generated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by scripts/gcp-prices.mjs from the Cloud Billing Catalog on 2026-11-14.
// Generated by scripts/gcp-prices.mjs from the Cloud Billing Catalog on 2026-11-16.
// Do not edit by hand. GCP on-demand list prices in USD: plans are per hour
// (cores + RAM + GPU), ssdGbMonth is pd-ssd per GB-month.

Expand All @@ -8,7 +8,8 @@ export const REGION_PRICES: Record<string, { plans: Record<string, number>; ssdG
"t4": 0.729998,
"l4": 0.706832,
"a100": 3.673385,
"a100-80": 5.027702
"a100-80": 5.027702,
"h100": 10.979058
},
"ssdGbMonth": 0.17
},
Expand All @@ -17,7 +18,8 @@ export const REGION_PRICES: Record<string, { plans: Record<string, number>; ssdG
"t4": 0.729998,
"l4": 0.706832,
"a100": 3.673385,
"a100-80": 5.027702
"a100-80": 5.027702,
"h100": 10.979058
},
"ssdGbMonth": 0.17
},
Expand All @@ -26,7 +28,8 @@ export const REGION_PRICES: Record<string, { plans: Record<string, number>; ssdG
"t4": 0.729998,
"l4": 0.706832,
"a100": 3.673385,
"a100-80": 5.027702
"a100-80": 5.027702,
"h100": 10.979058
},
"ssdGbMonth": 0.17
},
Expand All @@ -35,7 +38,8 @@ export const REGION_PRICES: Record<string, { plans: Record<string, number>; ssdG
"t4": 0.768336,
"l4": 0.742916,
"a100": 3.747972,
"a100-80": 5.535713
"a100-80": 5.535713,
"h100": 13.977149
},
"ssdGbMonth": 0.187
},
Expand All @@ -44,7 +48,8 @@ export const REGION_PRICES: Record<string, { plans: Record<string, number>; ssdG
"t4": 0.838772,
"l4": 0.872019,
"a100": 4.013758,
"a100-80": 6.20248
"a100-80": 6.20248,
"h100": 14.194376
},
"ssdGbMonth": 0.187
}
Expand Down
22 changes: 21 additions & 1 deletion api/src/zones.generated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated by scripts/gcp-zones.mjs on 2026-11-14. Do not edit by hand.
// Generated by scripts/gcp-zones.mjs on 2026-11-16. Do not edit by hand.
// Zones in each region offering each plan's machine type (and GPU).

export const PLAN_ZONES: Record<string, Record<string, string[]>> = {
Expand Down Expand Up @@ -93,5 +93,25 @@ export const PLAN_ZONES: Record<string, Record<string, string[]>> = {
"asia-southeast1": [
"asia-southeast1-c"
]
},
"h100": {
"us-central1": [
"us-central1-a",
"us-central1-b",
"us-central1-c"
],
"us-east1": [],
"us-west1": [
"us-west1-a",
"us-west1-b"
],
"europe-west4": [
"europe-west4-b",
"europe-west4-c"
],
"asia-southeast1": [
"asia-southeast1-b",
"asia-southeast1-c"
]
}
};
17 changes: 16 additions & 1 deletion api/test/pricing.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { meterRate } from "../src/billing";
import { IP_HOURLY_USD, PLANS, chargeMicros, diskHourlyUsd, gcpHourlyUsd, planPrice, withPremium } from "../src/pricing";
import { IP_HOURLY_USD, PLANS, chargeMicros, diskHourlyUsd, gcpHourlyUsd, isPremium, planPrice, requiredBalanceMicros, withPremium } from "../src/pricing";
import { REGIONS, byDistance, enabledRegions, regionOfZone } from "../src/regions";

describe("pricing", () => {
Expand Down Expand Up @@ -36,6 +36,21 @@ describe("pricing", () => {
expect(chargeMicros(1_000_000, -5)).toBe(0);
});

it("makes plans of $10/h or more premium, needing $100 to create", () => {
const h100 = planPrice(PLANS.h100, "us-central1", 20)!.hourlyMicros;
const a100 = planPrice(PLANS.a100, "us-central1", 20)!.hourlyMicros;
expect(isPremium(h100)).toBe(true);
expect(isPremium(a100)).toBe(false);
expect(requiredBalanceMicros(h100)).toBe(100_000_000);
expect(requiredBalanceMicros(a100)).toBe(a100); // just an hour of use
expect(requiredBalanceMicros(150_000_000)).toBe(150_000_000); // never less than an hour
});

it("lists H100 but doesn't offer it until GCP grants quota", () => {
expect(PLANS.h100.available).toBe(false);
expect(Object.values(PLANS).filter((p) => p.id !== "h100").every((p) => p.available)).toBe(true);
});

it("$10 buys about two hours of A100", () => {
const hours = 10e6 / planPrice(PLANS.a100, "us-central1", 20)!.hourlyMicros;
expect(hours).toBeGreaterThan(2);
Expand Down
22 changes: 19 additions & 3 deletions client/gpushed-cli
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,26 @@ case "$cmd" in
region=""
if [ "${1:-}" = --region ]; then region="${2:-}"; [ -n "$region" ] || die "Usage: gpushed plans [--region REGION]"; fi
NO_AUTH=1 api GET "/plans${region:+?region=$region}"
jq -r '"Prices in \(.region_name) (\(.region))\(if .nearest then ", the region nearest you" else "" end). Default plan: \(.default)\n",
(.plans[] | " \(.id | . + " " | .[0:8]) $\(.hourly_usd)/h \(.label)"),
"\nRegions: \([.regions[] | .id] | join(", "))"' <<<"$API_BODY"
jq -r '"Prices in \(.region_name) (\(.region))\(if .nearest then ", the region nearest you" else "" end). Default plan: \(.default)\n"' <<<"$API_BODY"
# One row per plan: id, GPU and machine, price, stopped price, minimum
# balance, status. Older APIs send no status: treat the plan as available.
jq -r '.plans[] | [
.id,
(.label | split(", ")[0] | sub("^1x NVIDIA "; "")),
"$\(.hourly_usd)",
"$\(.stopped_hourly_usd)",
"$\(.min_balance_usd // .hourly_usd)",
((.status // "available") as $s
| if $s == "unavailable" then "coming soon (no GPU quota yet)"
elif $s == "elsewhere" then "not here; in \(.regions | join(", "))"
else "available" end
+ (if .premium then ", premium" else "" end))
] | @tsv' <<<"$API_BODY" |
awk -F'\t' 'BEGIN { printf " %-8s %-18s %9s %9s %11s %s\n", "PLAN", "GPU", "PER HOUR", "STOPPED", "MIN BALANCE", "STATUS" }
{ printf " %-8s %-18s %9s %9s %11s %s\n", $1, $2, $3, $4, $5, $6 }'
jq -r '"\nRegions: \([.regions[] | .id] | join(", "))"' <<<"$API_BODY"
say "Prices include disk and IP, and differ a little by region. A stopped box costs only its disk."
say "Min balance is what you need to create or start a box: an hour of use, or \$100 for premium plans (\$10/h or more)."
say "Your box goes to the nearest region with free GPUs; pick one with: gpushed up [plan] --region REGION"
;;

Expand Down
3 changes: 2 additions & 1 deletion provisioner/terraform/scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ apt_install build-essential git git-lfs cmake ninja-build pkg-config \
echo "Installing Python 3.11..."
add-apt-repository -y ppa:deadsnakes/ppa
apt_retry update -y
apt_install python3.11 python3.11-venv python3.11-dev
# python3-venv too, so `python3 -m venv` (system 3.10) works as well as `python -m venv`.
apt_install python3.11 python3.11-venv python3.11-dev python3-venv
python3.11 -m ensurepip --upgrade
python3.11 -m pip install --no-cache-dir --upgrade pip
update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1
Expand Down
Loading