How do I rent a GPU with a spending cap?
Send max_spend_usd and max_runtime_s to POST /v1/quotes to cap a rental. Check worst_case_usd before booking. Set separate limits on the agent key.
What to do
| Control | What it limits |
|---|---|
max_spend_usd | Total for one rental, including any transfer allowance. |
max_runtime_s | How long the rental can run. |
lifetime_usd and hourly_usd | The lifetime limit counts charges and outstanding holds. The hourly limit counts holds placed in the past 60 minutes, even if X9 has released them. |
max_gpu_class and expires_at | Which GPU classes the key can book and when it stops working. Key expiry does not stop a rental. After expiry, use another spending key on the same account. |
Try it with curl
Use Bash, curl and jq. Set X9_API_URL to https://prod-api.x9si.com, X9_OWNER_KEY in a private shell, X9_KEY_REQUEST_ID to a saved UUID and X9_KEY_EXPIRES_AT to a future UTC time such as YYYY-MM-DDTHH:MM:SSZ. Run on a trusted machine. On a shared machine, pass the authorization header from a file readable only by you.
Use the returned api_key as X9_API_KEY in the booking example. A replay returns the key ID, not the secret. If you lose the secret, revoke that key before creating another.
Example (Bash)
#!/usr/bin/env bash
set -euo pipefail
: "${X9_API_URL:?Set X9_API_URL to your X9 endpoint}"
: "${X9_OWNER_KEY:?Set X9_OWNER_KEY in a private shell}"
: "${X9_KEY_REQUEST_ID:?Set and save a unique ID for this key request}"
: "${X9_KEY_EXPIRES_AT:?Set and save a future UTC timestamp}"
key_body=$(jq -nc --arg expires "$X9_KEY_EXPIRES_AT" \
'{name:"first rental",scopes:["read","spend"],caps:{
lifetime_usd:"0.99",hourly_usd:"0.99",max_gpu_class:"consumer",expires_at:$expires}}')
curl -fsS "$X9_API_URL/v1/keys" \
-H "Authorization: Bearer $X9_OWNER_KEY" \
-H 'Content-Type: application/json' -H "Idempotency-Key: $X9_KEY_REQUEST_ID" \
-d "$key_body"