Skip to main content
A spot scaler automatically buys and sells compute to maintain a target number of nodes. It participates in the market on your behalf, placing bids within your price bounds.
The spot scaler does not guarantee continuous access. If someone outbids you or the market price exceeds your max_buy_price, your nodes may shut down.

How it works

The spot scaler places buy and sell orders automatically to maintain your desired_quantity. It considers your capacity’s existing allocation schedule including reservations from manual orders when deciding what to buy or sell.
  1. Buys compute when you have fewer nodes than desired_quantity
  2. Sells compute when you have more than desired_quantity
  3. Stays within max_buy_price and min_sell_price bounds when placing orders
  4. Plans allocation ahead using the managed_window_minutes setting

Using the spot scaler

Add a scheduler to your capacity to enable the spot scaler. You can set this up both by creating a new capacity or adding one to an existing capacity.
curl -X POST https://api.sfcompute.com/v2/capacities \
  -H "Authorization: Bearer $SF_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-capacity",
    "zones": ["richmond"],
    "node_template": "my-template",
    "start_nodes_automatically": true,
    "scheduler": {
      "type": "spot_scaler",
      "enabled": true,
      "desired_quantity": 4,
      "managed_window_minutes": 120,
      "max_buy_price_dollars_per_node_hour": "16.000000",
      "min_sell_price_dollars_per_node_hour": "8.000000"
    }
  }'
Use PATCH /v2/capacities/{id} to add or update the spot scaler on an existing capacity.
curl -X PATCH https://api.sfcompute.com/v2/capacities/my-capacity \
  -H "Authorization: Bearer $SF_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "scheduler": {
      "type": "spot_scaler",
      "enabled": true,
      "desired_quantity": 4,
      "managed_window_minutes": 120,
      "max_buy_price_dollars_per_node_hour": "16.000000",
      "min_sell_price_dollars_per_node_hour": "8.000000"
    }
  }'

Tuning the managed window

The managed_window_minutes setting controls how far ahead the spot scaler secures compute:
  • Higher values (e.g., 1440 = 24 hours): Secures compute further in advance, reducing risk of unavailability. But if you scale down, you’ll most likely sell remaining compute at a loss.
  • Lower values (e.g., 60 = 1 hour): More flexible, less commitment. But compute may not be available when you need it.
Orders are currently placed in 1-hour blocks, so the furthest hour is secured up to managed_window_minutes - 60 minutes before it begins.

Scaling up or down

To change desired_quantity, provide the full scheduler configuration:
curl -X PATCH https://api.sfcompute.com/v2/capacities/my-capacity \
  -H "Authorization: Bearer $SF_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "scheduler": {
      "type": "spot_scaler",
      "enabled": true,
      "desired_quantity": 8,
      "managed_window_minutes": 120,
      "max_buy_price_dollars_per_node_hour": "16.000000",
      "min_sell_price_dollars_per_node_hour": "8.000000"
    }
  }'
The spot scaler will place buy orders to reach the new target.
To sell all your compute, set desired_quantity to 0. The spot scaler will place sell orders for everything in the managed window.

Disabling the spot scaler

Set enabled to false to stop the spot scaler. This cancels all standing orders but does not affect compute you’ve already acquired.
curl -X PATCH https://api.sfcompute.com/v2/capacities/my-capacity \
  -H "Authorization: Bearer $SF_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "scheduler": {
      "type": "spot_scaler",
      "enabled": false,
      "desired_quantity": 8,
      "managed_window_minutes": 120,
      "max_buy_price_dollars_per_node_hour": "16.000000",
      "min_sell_price_dollars_per_node_hour": "8.000000"
    }
  }'