# Get the authenticated account and logged-in user
Source: https://docs.sfcompute.com/api-reference/account/get-the-authenticated-account-and-logged-in-user
/openapi.json get /preview/v2/me
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Retrieve the authenticated account and user.
# List events
Source: https://docs.sfcompute.com/api-reference/events/list-events
/openapi.json get /preview/v2/events
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List the account's activity events. Only the last 7 days of events are returned.
# Create firewall
Source: https://docs.sfcompute.com/api-reference/firewalls/create-firewall
/openapi.json post /preview/v2/firewalls
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Create a workspace-scoped firewall with an ordered list of allow-only ingress rules.
# Delete firewall
Source: https://docs.sfcompute.com/api-reference/firewalls/delete-firewall
/openapi.json delete /preview/v2/firewalls/{id}
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Delete a firewall. The firewall must not be in use.
# Get firewall
Source: https://docs.sfcompute.com/api-reference/firewalls/get-firewall
/openapi.json get /preview/v2/firewalls/{id}
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Retrieve a firewall by ID or resource path.
# List firewalls
Source: https://docs.sfcompute.com/api-reference/firewalls/list-firewalls
/openapi.json get /preview/v2/firewalls
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List firewalls in a workspace, including the auto-managed 'default' firewall.
# Replace a firewall's rules
Source: https://docs.sfcompute.com/api-reference/firewalls/replace-a-firewalls-rules
/openapi.json put /preview/v2/firewalls/{id}
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Replace a firewall's rules. Rule order is preserved.
# Complete image upload
Source: https://docs.sfcompute.com/api-reference/images/complete-image-upload
/openapi.json post /v2/images/{id}/complete
Finalize a multipart image upload.
# Create image
Source: https://docs.sfcompute.com/api-reference/images/create-image
/openapi.json post /v2/images
Create an image and start a multipart upload.
# Delete image
Source: https://docs.sfcompute.com/api-reference/images/delete-image
/openapi.json delete /v2/images/{id}
Delete an image.
# Download image
Source: https://docs.sfcompute.com/api-reference/images/download-image
/openapi.json get /v2/images/{id}/download
Get a presigned URL to download an image.
# Get image
Source: https://docs.sfcompute.com/api-reference/images/get-image
/openapi.json get /v2/images/{id}
Retrieve an image by ID. Returns both user-owned and public images.
# Get upload part URL
Source: https://docs.sfcompute.com/api-reference/images/get-upload-part-url
/openapi.json post /v2/images/{id}/parts
Get a presigned URL to upload one part of a multipart image upload.
# List images
Source: https://docs.sfcompute.com/api-reference/images/list-images
/openapi.json get /v2/images
List images in a workspace.
# Reinstate image
Source: https://docs.sfcompute.com/api-reference/images/reinstate-image
/openapi.json post /v2/images/{id}/reinstate
Reinstate a revoked image, making it available for new instances again
# Revoke image
Source: https://docs.sfcompute.com/api-reference/images/revoke-image
/openapi.json post /v2/images/{id}/revoke
Revoke a private image so it can't back new instances. Existing instances keep running.
# Create InfiniBand partition
Source: https://docs.sfcompute.com/api-reference/infiniband-partitions/create-infiniband-partition
/openapi.json post /preview/v2/infiniband_partitions
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Create an InfiniBand partition on a fabric.
# Delete InfiniBand partition
Source: https://docs.sfcompute.com/api-reference/infiniband-partitions/delete-infiniband-partition
/openapi.json delete /preview/v2/infiniband_partitions/{id}
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Delete an InfiniBand partition. Fails while instances are attached.
# Get InfiniBand partition
Source: https://docs.sfcompute.com/api-reference/infiniband-partitions/get-infiniband-partition
/openapi.json get /preview/v2/infiniband_partitions/{id}
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Get an InfiniBand partition by ID or resource path.
# List InfiniBand partitions
Source: https://docs.sfcompute.com/api-reference/infiniband-partitions/list-infiniband-partitions
/openapi.json get /preview/v2/infiniband_partitions
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List InfiniBand partitions.
# List instances in an InfiniBand partition
Source: https://docs.sfcompute.com/api-reference/infiniband-partitions/list-instances-in-an-infiniband-partition
/openapi.json get /preview/v2/infiniband_partitions/{id}/instances
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List the instances you can see that are attached to an InfiniBand partition.
# Create instance template
Source: https://docs.sfcompute.com/api-reference/instance-templates/create-instance-template
/openapi.json post /preview/v2/instance_templates
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Create a reusable instance template.
# Delete instance template
Source: https://docs.sfcompute.com/api-reference/instance-templates/delete-instance-template
/openapi.json delete /preview/v2/instance_templates/{id}
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Delete an instance template. The template must not be in use by any capacity.
# Get instance template
Source: https://docs.sfcompute.com/api-reference/instance-templates/get-instance-template
/openapi.json get /preview/v2/instance_templates/{id}
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Retrieve an instance template by ID or resource path.
# List instance templates
Source: https://docs.sfcompute.com/api-reference/instance-templates/list-instance-templates
/openapi.json get /preview/v2/instance_templates
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List all instance templates.
# Create instance
Source: https://docs.sfcompute.com/api-reference/instances/create-instance
/openapi.json post /v2/instances
Create an instance.
# Delete instance
Source: https://docs.sfcompute.com/api-reference/instances/delete-instance
/openapi.json delete /v2/instances/{id}
Delete an instance.
# Get instance
Source: https://docs.sfcompute.com/api-reference/instances/get-instance
/openapi.json get /v2/instances/{id}
Retrieve an instance by ID or name.
# Get instance cloud-init user data
Source: https://docs.sfcompute.com/api-reference/instances/get-instance-cloud-init-user-data
/openapi.json get /v2/instances/{id}/cloud_init_user_data
Retrieve the cloud-init user data an instance was created with.
# Get instance logs
Source: https://docs.sfcompute.com/api-reference/instances/get-instance-logs
/openapi.json get /v2/instances/{id}/logs
Retrieve logs for an instance.
# Get instance SSH info
Source: https://docs.sfcompute.com/api-reference/instances/get-instance-ssh-info
/openapi.json get /v2/instances/{id}/ssh
Retrieve SSH connection details for an instance.
# List instances
Source: https://docs.sfcompute.com/api-reference/instances/list-instances
/openapi.json get /v2/instances
List all instances.
# Replace instance
Source: https://docs.sfcompute.com/api-reference/instances/replace-instance
/openapi.json post /v2/instances/{id}/replace
Replace an instance with a fresh one on the same capacity, running a new image. Subnet, firewall, public IPv4 setting, tags, and priority carry over.
# Terminate instance
Source: https://docs.sfcompute.com/api-reference/instances/terminate-instance
/openapi.json post /v2/instances/{id}/terminate
Terminates a running instance. Terminated instances can not be restarted.
# Update instance
Source: https://docs.sfcompute.com/api-reference/instances/update-instance
/openapi.json patch /v2/instances/{id}
Update an instance. Omitted fields are left unchanged.
# Get account limits
Source: https://docs.sfcompute.com/api-reference/limits/get-account-limits
/openapi.json get /preview/v2/limits
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List the limits in effect for your account, with usage where tracked.
# Get market depth
Source: https://docs.sfcompute.com/api-reference/orderbook/get-market-depth
/openapi.json get /preview/v2/orderbook/depth
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Depth of book for the given requirements and delivery window.
# Get market quote
Source: https://docs.sfcompute.com/api-reference/orderbook/get-market-quote
/openapi.json get /preview/v2/orderbook/quote
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Top-of-book quote for the given requirements and delivery window.
# List market fills
Source: https://docs.sfcompute.com/api-reference/orderbook/list-market-fills
/openapi.json get /preview/v2/orderbook/fills
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List fills matching the requirements and delivery window, newest first.
# List market orders
Source: https://docs.sfcompute.com/api-reference/orderbook/list-market-orders
/openapi.json get /preview/v2/orderbook/orders
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List open and filled orders from the last 30 days matching the requirements.
# List market windows
Source: https://docs.sfcompute.com/api-reference/orderbook/list-market-windows
/openapi.json get /preview/v2/orderbook/windows
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List delivery windows with resting orders matching the requirements in a time range.
# Cancel order
Source: https://docs.sfcompute.com/api-reference/orders/cancel-order
/openapi.json post /v2/orders/{id}/cancel
Request cancellation of an order. Cancellation is asynchronous.
# Create order
Source: https://docs.sfcompute.com/api-reference/orders/create-order
/openapi.json post /v2/orders
Place a buy or sell order.
# Estimate an order
Source: https://docs.sfcompute.com/api-reference/orders/estimate-an-order
/openapi.json post /preview/v2/order_preview
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Estimate a buy or sell order before placing it.
# Get order
Source: https://docs.sfcompute.com/api-reference/orders/get-order
/openapi.json get /v2/orders/{id}
Retrieve an order by ID.
# List orders
Source: https://docs.sfcompute.com/api-reference/orders/list-orders
/openapi.json get /v2/orders
List all orders.
# Get platform constants
Source: https://docs.sfcompute.com/api-reference/platform/get-platform-constants
/openapi.json get /preview/v2/platform_constants
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Returns current platform-wide settings. Values may change over time.
# Create pool
Source: https://docs.sfcompute.com/api-reference/pools/create-pool
/openapi.json post /v2/pools
Create a pool to hold compute.
# Create pool transfer
Source: https://docs.sfcompute.com/api-reference/pools/create-pool-transfer
/openapi.json post /v2/pool_transfers
Transfer some or all of one pool into another
# Delete pool
Source: https://docs.sfcompute.com/api-reference/pools/delete-pool
/openapi.json delete /v2/pools/{id}
Delete a pool. The pool must have no active dependencies.
# Get pool
Source: https://docs.sfcompute.com/api-reference/pools/get-pool
/openapi.json get /v2/pools/{id}
Retrieve a pool by ID, resource path, or name, including its compute schedule.
# Get pool transfer
Source: https://docs.sfcompute.com/api-reference/pools/get-pool-transfer
/openapi.json get /v2/pool_transfers/{id}
Retrieve a pool transfer by ID.
# List pool transfers
Source: https://docs.sfcompute.com/api-reference/pools/list-pool-transfers
/openapi.json get /v2/pool_transfers
List pool transfers for the caller's organization.
# List pools
Source: https://docs.sfcompute.com/api-reference/pools/list-pools
/openapi.json get /v2/pools
List all pools.
# Update pool
Source: https://docs.sfcompute.com/api-reference/pools/update-pool
/openapi.json patch /v2/pools/{id}
Update a pool. Omitted fields are left unchanged.
# Get SKU
Source: https://docs.sfcompute.com/api-reference/skus/get-sku
/openapi.json get /v2/skus/{id}
Retrieve a SKU by ID, including its properties.
# Get SKU availability
Source: https://docs.sfcompute.com/api-reference/skus/get-sku-availability
/openapi.json get /v2/skus/{id}/availability
The purchasable-capacity schedule of one SKU.
# List SKU availability
Source: https://docs.sfcompute.com/api-reference/skus/list-sku-availability
/openapi.json get /v2/skus/availability
The purchasable-capacity schedule of every SKU.
# List SKUs
Source: https://docs.sfcompute.com/api-reference/skus/list-skus
/openapi.json get /v2/skus
List the SKUs available on the market with their properties.
# Get user
Source: https://docs.sfcompute.com/api-reference/users/get-user
/openapi.json get /preview/v2/users/{id}
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
Returns user details by ID or resource path.
# List users
Source: https://docs.sfcompute.com/api-reference/users/list-users
/openapi.json get /preview/v2/users
> ⚠️ This endpoint is in [public preview](/preview/roadmap#feature-states).
List users that are members of the caller's organization.
# Create workspace
Source: https://docs.sfcompute.com/api-reference/workspaces/create-workspace
/openapi.json post /v2/workspaces
Create a workspace.
# Get workspace
Source: https://docs.sfcompute.com/api-reference/workspaces/get-workspace
/openapi.json get /v2/workspaces/{id}
Retrieve a workspace by ID or resource path.
# List workspaces
Source: https://docs.sfcompute.com/api-reference/workspaces/list-workspaces
/openapi.json get /v2/workspaces
List all workspaces for the authenticated account, newest first.
# Events
Source: https://docs.sfcompute.com/preview/events
Read an ordered log of what happened on your account, from instances starting to orders filling
This feature is in [public preview](/preview/roadmap#feature-states).
Events form an append-only log of what happens on your account, such as [instances](/preview/instances) starting and terminating or [orders](/preview/orders) filling. Only events from the last 7 days are available. Authenticate with a bearer token, as described in [Using the API](/preview/using-the-api).
```bash theme={null}
curl -H "Authorization: Bearer $SF_API_KEY" \
"https://api.sfcompute.com/preview/v2/events"
```
The response holds a page of events in `data`.
```json theme={null}
{
"object": "list",
"data": [
{
"object": "event",
"id": "evt_x7Kp2mQhTv9rWq3s",
"cursor": "evtc_...",
"action": "instance.terminated",
"occurred_at": 1755644312,
"actor": { "type": "token", "id": "tokn_..." },
"targets": [{ "type": "instance", "id": "inst_9dQpXk2LwZj" }]
}
],
"has_more": false,
"cursor": "evtc_..."
}
```
`action` names what happened, and `occurred_at` records when, as a Unix timestamp in seconds. `actor` is the API token whose request caused the event, or `{ "type": "system" }` for automated actions, such as a preemption or a scheduled end. `targets` lists the resources the event is about as `{type, id}` pairs. Each `id` is the same ID the rest of the API uses for that resource.
## Event types
The table below lists each event type and its target type. To filter by resource, pass a target type as `target_type` or a single resource's ID as `target`.
| Action | Target type | Meaning |
| - | - | - |
| `instance.created` | `instance` | The instance was created and is [awaiting allocation](/preview/instances#instance-lifecycle). |
| `instance.running` | `instance` | The instance started running. SSH access becomes available once its image finishes booting. |
| `instance.termination_imminent` | `instance` | The instance will be terminated soon because its allocation is ending, whether from preemption or a scheduled end. |
| `instance.terminated` | `instance` | The instance was terminated, whether by user request, replacement, preemption, deployment teardown, or a scheduled end. |
| `instance.failed` | `instance` | The instance reported itself unhealthy. This does not terminate the instance, though work on it may be lost. [Replace](/preview/instances#replace-an-instance) or terminate it. |
| `instance.connection_lost` | `instance` | The instance stopped responding. |
| `order.created` | `order` | The order was placed. |
| `order.filled` | `order` | The order filled completely. |
| `order.cancelled` | `order` | The order was cancelled. |
| `image.revoked` | `image` | The image was [revoked](/preview/images#revoking-an-image) and can no longer back new instances. |
| `image.reinstated` | `image` | The image was reinstated and can back new instances again. |
| `trust_level.updated` | `account` | Your account's trust level changed. |
| `instance_sku_override.updated` | `instance_sku` | SF Compute set or changed property overrides on a [SKU](/preview/instance-skus) for your account. |
| `instance_sku_override.deleted` | `instance_sku` | SF Compute removed the property overrides on a SKU for your account. |
New event types are added over time, so if you don't filter by `action`, expect actions that aren't in this table. For a given instance, `instance.created`, `instance.running`, and `instance.terminated` appear in that order. An instance terminated while still awaiting allocation has no `instance.running` event.
## Consuming the stream
List events with `GET /preview/v2/events`. Events are returned oldest first, up to `limit` per request. `limit` defaults to 50 and is capped at 200. To fetch the next page, pass the response's `cursor` back as `starting_after`. `has_more` tells you whether more events are already available.
When `data` is empty and `has_more` is false, you have read everything so far. That response carries no `cursor`, so keep the one you sent and poll with it again later.
Filter with `action` for an exact event type, `target` for one resource, `target_type` for one type of resource, and `since` and `until` for inclusive bounds on `occurred_at`, given as Unix timestamps. Filters combine, so a single request can ask for one event type on one resource.
```bash theme={null}
# Everything that happened to one instance
curl -H "Authorization: Bearer $SF_API_KEY" \
"https://api.sfcompute.com/preview/v2/events?target=inst_9dQpXk2LwZj&target_type=instance"
# All terminations since a point in time
curl -H "Authorization: Bearer $SF_API_KEY" \
"https://api.sfcompute.com/preview/v2/events?action=instance.terminated&since=1755043200"
# When one order filled
curl -H "Authorization: Bearer $SF_API_KEY" \
"https://api.sfcompute.com/preview/v2/events?action=order.filled&target=ordr_5Gh8kLm2Np4QwXz"
```
A cursor only works with the filters it was created with, and reusing it with different filters returns 400 Bad Request. If a saved cursor falls outside the 7-day retention window, requests with it return 410 Gone. In that case, start over without a cursor to read from the oldest available event.
## API reference
See the [Events API](/preview/api-reference/events/list-events) for every parameter and response field.
# Grants
Source: https://docs.sfcompute.com/preview/grants
Assign roles to users and tokens
This feature is in [public preview](/preview/roadmap#feature-states).
A grant assigns a [role](/preview/roles) to a user or [token](/preview/tokens) within a
[workspace](/preview/workspaces) or across the organization.
## Granting access to a user
Grant a role directly to a user by their email.
```bash theme={null}
sf grants create \
--workspace production \
--user alice@acme.co \
--role admin
```
Alice now has admin access to the `production` workspace.
As with other commands, `-w` and `SF_WORKSPACE` also set the workspace. `--org` overrides
`SF_WORKSPACE`, and can't be combined with `-w` or `--workspace`.
## Organization-wide grants
Use `--org` to grant a role across all workspaces in the organization.
```bash theme={null}
sf grants create \
--org \
--user alice@acme.co \
--role admin
```
Alice now has admin access to every workspace in the organization.
## Listing grants
List all grants in the organization. With a workspace set by `-w` or `SF_WORKSPACE`, the list shows
only the grants scoped to that workspace, not organization-wide ones.
```bash theme={null}
sf grants list
```
```text theme={null}
------------------------------------------------------------------------------------------------------------------
ID WORKSPACE ROLE TYPE PRINCIPAL CREATED
grnt_k3RnX9vLm7Qp2Yw5JdA4f (Org-wide) admin user alice@acme.co Feb 4, 2025, 12:00pm
grnt_8KvQ3mWxYpRtZn6Hb2C7j production training-operator user bob@acme.co Feb 3, 2025, 9:30am
grnt_9QwT4xNbVs2Lm7Cfj3W5d production viewer token tokn_5DhP2nLqWmKz8XvBt4Jc6 Feb 1, 2025, 8:15am
```
Filter by workspace or by user. Unlike `sf grants create`, which accepts an email, the `--user`
filter takes a user ID.
```bash theme={null}
sf grants list --workspace production
sf grants list --user usr_7d41c2a90b5f83e6
```
## Deleting a grant
Delete a grant by its ID, which `sf grants list` prints in the first column.
```bash theme={null}
sf grants delete grnt_k3RnX9vLm7Qp2Yw5JdA4f
```
You can also delete a workspace-scoped grant by its attributes. As with `sf grants list`, `--user`
takes a user ID.
```bash theme={null}
sf grants delete \
--workspace production \
--user usr_3e92f8b06c14da75 \
--role training-operator
```
Delete an organization-wide grant.
```bash theme={null}
sf grants delete \
--org \
--user usr_7d41c2a90b5f83e6 \
--role admin
```
## Multiple grants
A user or token can have multiple grants. SF Compute combines the permissions from every granted
role (a union).
```bash theme={null}
sf grants create --org --user bob@acme.co --role viewer
sf grants create --workspace production --user bob@acme.co --role training-operator
```
Bob has `viewer` access organization-wide and `training-operator` access in `production`.
## Token grants
Grant roles to tokens for CI/CD pipelines and other automation.
```bash theme={null}
sf grants create \
--workspace production \
--token ci-deploy \
--role training-operator
```
Alternatively, assign a role when creating the token. `sf tokens create` takes the same
`--workspace` and `--org` flags and creates 1 grant per role.
```bash theme={null}
sf tokens create --name ci-deploy --role training-operator --workspace production
```
See [Tokens](/preview/tokens#attaching-a-role).
## How grants interact with roles
Grants bind users or tokens to roles. Roles define which actions a user or token can perform.
When a request arrives, SF Compute collects every grant the user or token holds on the target
workspace, including organization-wide grants. It then evaluates the rules from all matched roles.
See [Roles](/preview/roles) for the rule effects and evaluation semantics.
## API reference
See the [Grants API](/preview/api-reference/grants/list-grants) for programmatic access.
# Instances and Pools
Source: https://docs.sfcompute.com/preview/guides/instances-and-pools
How instances and pools separate what you run from the compute time it runs on
You run workloads on instances and pay for the compute time they use from pools.
## Instances
An [instance](/preview/instances) is a GPU virtual machine booted from an [image](/preview/images).
Like instances on other clouds, it has hardware, an image, startup configuration, logs, SSH access,
and lifecycle state. You create it, connect to it, run your workload, and terminate it when you are
done.
The only difference is that an SF Compute instance consumes compute time when it runs. It won't
start until it has compute time allocated to it. That compute time comes from a pool.
## Pools
A [pool](/preview/pools) is a named container that holds an allocation of compute time. It
represents that allocation as a schedule. The schedule tracks how many nodes you own, on which
hardware, and for which windows of time. Each node runs 1 instance.
For example, a pool might have this schedule.
| Hardware | Window | Allocation |
| - | - | - |
| H100, EU North, InfiniBand, … | Mar 20, 09:00 → Mar 20, 17:00 | 4 nodes |
| H100, EU North, InfiniBand, … | Mar 20, 17:00 → Mar 21, 00:00 | 8 nodes |
| H200, US East, No RDMA, … | Mar 21, 09:00 → Mar 21, 17:00 | 2 nodes |
The pool's schedule changes as you buy, sell, or transfer compute time, or as it expires.
## SKUs
Each pool tracks a separate schedule for each stock-keeping unit (SKU). A
[SKU](/preview/instance-skus) represents a specific set of interchangeable hardware,
including the following.
* Accelerator type, such as H100 or H200
* Instance specs like number of CPUs, RAM, and local storage
* RDMA type, such as InfiniBand or RoCE
* Zone or location
* Other operator-defined hardware properties
You pin orders, transfers, and instances to a SKU. That tells SF Compute which hardware
the allocation comes from.
## Starting an instance
When you create an instance, you attach it to a pool. The instance starts in `awaiting_allocation`
if the pool does not currently have matching allocation for the hardware it will run on.
To add compute time, place a buy [order](/preview/orders) on the pool. When the order fills, it adds
compute time to the pool's allocation schedule for the order's SKU. Once the schedule
covers the current time and there is enough matching allocation, the instance starts booting.
```bash theme={null}
sf pools create --name dev
sf instances create \
--pool dev \
--image sfc:image:sfcompute:public:ubuntu-24.04-cuda-13.2 \
--cloud-init ./startup.sh \
--sku sku_4UpxzQw7A8N
# --max-rate is the most you'll pay, in dollars per node-hour.
sf orders create \
--side buy \
--pool dev \
--count 1 \
--start now \
--duration 2h \
--max-rate 20.00 \
--sku sku_4UpxzQw7A8N
```
You can create the instance before the order fills. It waits until matching allocation exists.
Instances define what should run. Pools define when there is compute time available to run it.
## Instance lifecycle
A pool's allocation determines whether attached instances can run.
| Pool state | Instance behavior |
| - | - |
| No matching allocation | Instance waits in `awaiting_allocation` |
| Allocation becomes available | Waiting instances start booting |
| Allocation covers the running instance | Instance stays `running` |
| Allocation shrinks below demand | SF Compute terminates instances until demand fits allocation |
Terminating an instance does not free its allocation. The allocation remains in the pool's
schedule until you sell it, transfer it, or let it expire.
When allocation grows, waiting instances can start. If you use a [deployment](/preview/deployments),
the deployment can also create more instances to match its target count. Those instances start when
allocation is available.
When allocation shrinks below the number of running instances, SF Compute terminates instances until
the running count fits the pool schedule. It terminates lower-priority instances first. Among
instances with the same priority, it terminates the newest first. If you need control over which
work survives a planned shrink, set [instance priority](/preview/instances) before selling,
transferring, or letting allocation expire.
Compute allocation stays separate from what you run. You can buy compute time before you launch
instances and recreate instances without losing reserved time. You can also sell unused time without
deleting the pool and move allocation between workloads.
Think of it like a power grid. Pools are the circuits.
Orders add compute time to those circuits. Transfers move it between circuits. Instances draw it
from the pool they are attached to.
If a circuit has enough scheduled compute time, the attached instances can run. If it does not, they
wait or terminate.
## One pool or many
You can attach multiple instances to a single pool, or create a separate pool for each instance or
workload.
Use a separate pool when you want to manage the instance independently.
* A personal dev box should usually have its own pool.
* A one-off debugging instance should usually have its own pool.
* A customer-isolated workload should use its own pool if selling or expiration should not affect
other customers.
Use one shared pool when the instances are part of the same fleet and can share allocation
decisions.
* An inference fleet should usually use one pool and one deployment.
* Batch workers for the same queue can usually share one pool.
* A training job with many identical workers can usually share one pool.
As a rule of thumb, put instances in the same pool only when you can scale, interrupt, extend,
sell, or transfer them together.
## Transfers
You can transfer compute time between pools. This lets you manage allocation like any other
resource. Assign it to projects, teams, or workloads, then move it when it is not being used.
For example, a platform team might buy a large block of H100 time into a shared pool. It can then
transfer pieces of that allocation to separate pools for `training`, `inference`, and `experiments`.
If `experiments` does not need its allocation, the team can transfer it back or move it to another
project.
Transfers affect the same schedule that orders affect. If compute time leaves a pool, attached
instances may terminate if the remaining allocation no longer covers them. If compute time arrives,
waiting instances can start.
## Next steps
* [Orders](/preview/orders) covers buying and selling compute time.
* [Pools](/preview/pools) is the command reference for pool operations, including transfers.
* [Instances](/preview/instances) is the command reference for instance lifecycle operations.
# Run a PyTorch job across multiple nodes
Source: https://docs.sfcompute.com/preview/guides/multi-node-training
Create an InfiniBand partition, start instances in it, and launch torchrun on every node
This guide takes you from no instances to a `torchrun` job on 2 nodes with 8 GPUs each. The nodes find each other over a private [subnet](/preview/networking/subnets) and exchange training data over an isolated [InfiniBand partition](/preview/networking/infiniband-partitions). By the end, you'll have trained [nanoGPT](https://github.com/karpathy/nanoGPT) on a small corpus of Shakespeare and generated text from it.
## Before you start
Set up your account, a partition, a subnet, and a [pool](/preview/pools) before you create any instances. A pool holds the allocation your instances run on. You need the `sf` CLI, logged in to your account. See the [Quickstart](/preview/quick-start#install-the-cli) to install it.
The examples use landsend, a [SKU](/preview/instance-skus) with 8 H100 GPUs per node: ID `sku_4EzdPrHcTps`, region `europe-north1`, zone `a`, on the InfiniBand fabric `europe-north1-a.fab1`. A fabric is the physical InfiniBand network that a SKU's nodes connect to. To use another SKU with InfiniBand, replace these values with its own.
Enroll your account so the `sf infiniband-partitions` commands and the `--infiniband-partition` flag become available.
```bash theme={null}
sf preview set infiniband-preview=true
```
Create a partition named `training` on your SKU's fabric.
```bash theme={null}
sf infiniband-partitions create --name training --fabric europe-north1-a.fab1
```
Only instances in the same partition can reach each other over InfiniBand. See [Create a partition](/preview/networking/infiniband-partitions#create-a-partition) for the other options.
Create a subnet named `training` in your SKU's region and zone.
```bash theme={null}
sf subnets create --name training --region europe-north1 --zone a \
--cidr 10.1.0.0/24
```
Note the subnet `id` in the output, which starts with `snet_`. You need it to delete the subnet later.
Instances in the subnet reach each other over private IPv4 addresses. `torchrun` uses the subnet to start the job, and the NVIDIA Collective Communications Library (NCCL) sends the training traffic over InfiniBand.
SF Compute public images ship with no SSH key. This script adds your public keys to the `root` user when the instance boots. The `$(cat ...)` lines run on your machine as you write the file. If you have none of these keys, create one with `ssh-keygen -t ed25519` first.
To use a key stored elsewhere, see [SSH into an instance](/preview/instances#ssh-into-an-instance).
```bash theme={null}
cat >startup.sh <