> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sfcompute.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Procurements

> Automate buying and selling compute time

<Warning>
  This feature is in [public preview](/preview/roadmap).
</Warning>

A procurement automatically buys and offers compute for sale to maintain a target allocation on a
[pool](/preview/pools). The target can be a fixed number of instances or follow the pool's
non-terminated instance count. The procurement participates in the market on your behalf within
your price bounds.

<Warning>
  A procurement does not guarantee continuous access. Your instances may shut down if the market
  price exceeds your buy limit or other buyers place reservations that consume the capacity. Design
  workloads to handle interruptions.
</Warning>

## Create a procurement

```bash theme={null}
sf procurements create \
  --pool dev \
  --target node_count \
  --max-buy-price 20.00 \
  --min-sell-price 10.00 \
  --window 1h
```

This creates a procurement on the `dev` pool that buys compute at up to \$20.00/node/hr and sells
excess at no less than \$10.00/node/hr. With `node_count` as the target, it matches the number of
non-terminated instances on the pool.

## Pin to an instance SKU

Every procurement is pinned to a single instance SKU; every order it places fills only on that SKU.
Pass `--instance-sku <id>`:

```bash theme={null}
sf procurements create --pool dev --target node_count \
  --max-buy-price 20.00 --min-sell-price 10.00 --window 1h \
  --instance-sku isku_4UpxzQw7A8N
```

Omitting `--instance-sku` opens an interactive picker that shows every registered SKU's name, id,
and properties. Run `sf instance-skus list` to browse them beforehand. See
[Instance SKUs](/preview/instance-skus) for the full model.

## How it works

For each complete minute in the managed window, the procurement compares the pool's allocation
with its target. It places standing buy orders for shortages at or below your buy limit and standing
sell orders for excess compute at or above your sell limit. Orders placed by a procurement follow
the same rules as manual orders and appear in `sf orders list`.

## Tuning the managed window

The `--window` setting controls the exact number of complete, tradeable minutes the procurement
manages, from `1m` through `90d`. The window begins with the next minute and rolls forward as time
passes. The procurement can buy shortages and offer excess compute only within this window.

A longer window gives the procurement more lead time to secure future compute, reducing the risk of
gaps. It can also commit purchased capacity farther into the future. If the target later decreases,
the procurement offers that excess at your configured sell limit. A filled sale can realize a loss
when the sell price is below the original purchase price. Until an offer fills, the capacity remains
in the pool.

A shorter window limits how far into the future orders can commit capacity, but provides less time
to acquire capacity before it is needed.

## Target modes

The `--target` flag accepts two kinds of values.

The value `node_count` uses the number of non-terminated instances on the pool as the target,
including instances awaiting allocation. This pairs well with [deployments](/preview/deployments):
the deployment decides how many instances to maintain, and the procurement buys compute to cover
them or offers compute left over after the instance count decreases.

The `node_count` target is pool-wide. It counts every non-terminated instance in the pool, not only
instances matching the procurement's pinned instance SKU.

```bash theme={null}
sf procurements create --pool dev --target node_count \
  --max-buy-price 20.00 --min-sell-price 10.00 --window 1h
```

A number maintains a fixed allocation regardless of how many instances exist.

```bash theme={null}
sf procurements create --pool dev --target 8 \
  --max-buy-price 20.00 --min-sell-price 10.00 --window 1h
```

## List procurements

```bash theme={null}
sf procurements list
```

```
NAME              POOL          TARGET      ON   STATUS  MESSAGE
prod-procurement  prod-cluster  50          yes  info    running
auto-scaler       dev-cluster   node_count  yes  info    running
```

## Get procurement details

```bash theme={null}
sf procurements get prod-procurement
```

```
│ PROCUREMENT ID  proc_k3RnX9vLm7Qp2Yw5Jd8F
│ NAME            prod-procurement
│ POOL            prod-cluster (pool_yIwQRIaE8bJo4Gs0000)
│ TARGET          50
│ BUY PRICE       $20.00/node/hr
│ SELL PRICE      $10.00/node/hr
│ WINDOW          60 minutes
│ ENABLED         yes
│ STATUS          info
│ MESSAGE         running
│ CREATED         Mar 23, 4:40pm PDT
└ UPDATED         Mar 30, 3:00pm PDT
```

## Update a procurement

Change price limits, the managed window, instance SKU, or enable/disable the procurement. During the
next reconciliation, the procurement cancels standing orders that no longer match its configuration
and places replacement orders as needed.

```bash theme={null}
sf procurements set prod-procurement --max-buy-price 25.00
```

Repoint the procurement to a different SKU. During the next reconciliation, it cancels its standing
orders for the previous SKU and places replacement orders for the updated SKU.

```bash theme={null}
sf procurements set prod-procurement --instance-sku isku_otherSku123
```

Disable a procurement to stop it from placing new orders and cancel its standing orders. Capacity
already allocated to the pool is unchanged.

```bash theme={null}
sf procurements set prod-procurement --enabled false
```

Re-enable it to resume.

```bash theme={null}
sf procurements set prod-procurement --enabled true
```

## Delete a procurement

```bash theme={null}
sf procurements delete prod-procurement
```

Deleting a procurement cancels all standing orders it placed. It does not sell existing allocations;
they remain in the pool until they expire or you otherwise transfer or sell them.

<Tip>
  To sell all your compute, set the target to 0 instead of deleting. The procurement will place sell
  orders for everything in the managed window.
</Tip>

## Status

Each procurement reports a reconciliation status with a state and a message.

| State   | Meaning                                           |
| ------- | ------------------------------------------------- |
| info    | Operating normally                                |
| warning | Non-critical issue                                |
| error   | Cannot place orders, such as insufficient balance |

Check the `MESSAGE` column in `sf procurements list` or the message field in
`sf procurements get` for details.

### API reference

See the [Procurements API](/preview/api-reference/procurements/list-procurements) for programmatic
access.
