> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.xapi.to/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.xapi.to/_mcp/server.

# 创建 Sandbox 实例

POST https://sandbox.xapi.to/v1/sandboxes
Content-Type: application/json

创建一个连接真实供应商、会产生费用的 Sandbox。获取报价不会创建资源；只有调用本接口后，
服务才会预留费用并开始供应实例。

## 选择创建方式

`selection` 中必须且只能提供以下一种方式：

| 方式             | 适用场景                                               | 需要注意                                                      |
| -------------- | -------------------------------------------------- | --------------------------------------------------------- |
| `quoteId`      | **推荐。** 先按能力、资源和预算调用 `POST /v1/quotes`，确认匹配结果后立即创建 | 报价有效期较短且只用于一个业务创建；过期或对应 offering 已变化时需要重新报价               |
| `offeringId`   | 已通过 `GET /v1/offerings` 确认并希望固定使用某个具体规格            | 不会按 requirements 重新选择，也没有 `maxEstimatedHourlyUsd` 创建时价格上限 |
| `requirements` | 希望服务在创建时动态选择兼容 offering，或允许供应商/规格变化                | 可同时提供 `maxEstimatedHourlyUsd` 作为硬性价格上限；没有兼容规格时返回 `404`    |

`maxEstimatedHourlyUsd` 只适用于 `requirements` 方式。需要 Shell、文件、端口或 GPU 时，
应显式声明相应 capability/资源，不要假设所有 offering 都支持。

## 幂等重试

每次业务创建生成一个稳定且唯一的 `idempotencyKey`（最长 160 个字符），并在请求超时、
连接中断或未收到响应时复用同一个值。这样可以取回同一次创建，而不是误建第二个计费实例。

* 同一个业务创建重试：复用原 key，并保持 `selection`、`policy` 等创建参数不变。
* 新建另一个实例：使用新的 key。
* 使用 `quoteId` 时，同一 key 的重试可复用该报价；不同 key 复用同一报价会返回 `409`。
* 同一 key 搭配不兼容的选择或策略：返回 `409 Conflict`。

## `202 Accepted` 之后

`202` 仅表示服务已受理创建请求。响应会立即返回实例 `id`，此时
`observedState` 通常是 `PROVISIONING`，**还不能执行命令或读写文件**。

1. 立即保存响应中的 `id`，它也是后续查询、操作和清理实例的唯一标识。
2. 轮询 `GET /v1/sandboxes/{id}`，例如每 2 秒一次，并设置客户端总超时（建议不超过 5 分钟）。
3. `RUNNING` 表示实例已就绪；只有此时才能调用 exec、files 或 ports 接口。
4. `FAILED` 或 `TERMINATED` 是终态，不能继续等待 `RUNNING`；应查看操作与事件审计定位原因。
5. 客户端等待超时不代表实例没有创建。先按 `id` 查询并清理，不要换新 key 盲目重试。

## 计费与清理

创建前服务会检查账户余额并预留初始运行费用及关机费用，余额不足返回 `402`。
供应中或运行中的实例都可能产生费用；响应中的初始 `totalCost` 为 `0` 不代表后续免费。

将 `POST /v1/sandboxes/{id}/terminate` 放在 `finally` 中，并继续轮询实例，直到
`observedState` 为 `TERMINATED` 或 `FAILED`。最后读取 `totalCost`、operations、events、
usage segments 和 billing periods，确认没有开放账期或遗留活动实例。

## 常见失败

* `400`：选择方式不合法、requirements 无效、quote 无效/过期，或 offering 不支持 `resumeOnAccess`。
* `402`：余额不足，无法完成初始费用预留。
* `404`：offering 不可用，或 requirements 没有匹配的 offering。
* `409`：报价对应的 offering 已变化、报价被另一业务创建使用、达到活动实例上限、幂等参数冲突，或供应商暂时不能创建。
* `429`：请求过快；遵循响应中的重试提示，并继续复用原 `idempotencyKey`。

Reference: https://docs.xapi.to/sandbox/api-reference/lifecycle/create-sandbox

## Authentication

- `XAPI-Key` header (required) — 在 xAPI Console 创建的 API Key。只会发送给 *.xapi.to。

## Servers

- `https://sandbox.xapi.to` (Production, default)
- `https://sandbox.test.xapi.to` (Test)

## Request

### Body (application/json)

This endpoint expects a CreateSandboxRequest.

- `selection` (Selection, required) — quoteId、offeringId 或 requirements 三选一，不能同时提供。
- `idempotencyKey` (string, required) — 本次业务创建的稳定唯一键。请求结果不确定时复用原值和原参数；创建另一个实例时换新值。
- `policy` (CreateSandboxRequestPolicy, optional) — 实例访问与生命周期策略。使用前先确认目标 offering 声明支持相应策略。
- `metadata` (map from string to any, optional) — 用于关联客户端、任务或模型日志的非敏感元数据。不要写入 API key、令牌或其他密钥。

## Response

### 202

创建请求已接受并返回实例记录；实例通常仍处于 PROVISIONING，尚不可执行任务。

- `id` (string, required) — 实例 UUID；所有查询、执行、文件、端口、审计和清理接口都使用此值。
- `offeringId` (string, required) — 实际选中的 offering UUID；即使按 requirements 创建也会返回具体值。
- `observedState` (enum, required) — Gateway 最近确认的供应商实际状态；判断是否可执行、是否已清理应以此字段为准。
  - Allowed values: `PROVISIONING`, `RUNNING`, `SUSPENDED`, `TERMINATED`, `FAILED`, `UNKNOWN`
- `totalCost` (string, required) — 服务端已结算账期的累计实际费用（USD 十进制字符串）；不要用本地墙钟时间自行替代。
- `createdAt` (datetime, required) — Gateway 创建实例记录并开始供应的时间。
- `updatedAt` (datetime, required) — 实例记录最近一次状态、费用或审计摘要更新的时间。
- `idempotencyKey` (string, optional) — 创建实例时使用的业务幂等键，可用于历史检索和重复创建核对。
- `desiredState` (enum, optional, nullable) — 最近一次生命周期操作希望达到的目标状态；没有进行中的状态目标时可能为 null。
  - Allowed values: `PROVISIONING`, `RUNNING`, `SUSPENDED`, `TERMINATED`, `FAILED`, `UNKNOWN`
- `lifecyclePhase` (enum, optional) — 由 desiredState 与 observedState 推导的用户可读阶段，可区分 SUSPENDING/RESUMING/TERMINATING 过渡过程。
  - Allowed values: `PROVISIONING`, `RUNNING`, `SUSPENDING`, `SUSPENDED`, `RESUMING`, `TERMINATING`, `TERMINATED`, `FAILED`, `UNKNOWN`
- `lastConfirmedState` (enum, optional) — 最近一次有供应商或可靠事件证据确认的状态；observedState=UNKNOWN 时可用于故障排查，不能替代最新状态。
  - Allowed values: `PROVISIONING`, `RUNNING`, `SUSPENDED`, `TERMINATED`, `FAILED`, `UNKNOWN`
- `stateVersion` (integer, optional) — 每次有效状态变化递增的版本号，用于检测状态是否更新和防止乱序覆盖。
- `policy` (SandboxPolicy, optional) — 创建时生效的实例生命周期策略。
- `resources` (ResourceSnapshot, optional) — 创建时冻结的实际资源快照，用于执行能力和费用核对。
- `reservedUntil` (datetime, optional, nullable) — 当前滚动费用预留覆盖到的时间；不是实例保证存活时间，也不是自动终止时间。
- `terminatedAt` (datetime, optional, nullable) — 实例首次确认进入 TERMINATED 的时间；尚未终止时为 null。
- `offering` (Offering, optional) — 选中 offering 的完整快照；部分列表响应可能省略。
- `operations` (list of Operation, optional) — 最近的操作审计摘要；完整记录使用 audit?kind=operations 分页读取。
- `events` (list of StateEvent, optional) — 最近的状态事件；完整记录使用 audit?kind=events。
- `usageSegments` (list of UsageSegment, optional) — 最近的用量段；终态验收时所有段应有 endsAt 且不处于 OPEN。
- `billingPeriods` (list of BillingPeriod, optional) — 已返回的账期与结算明细；totalCost 应与 SETTLED 账期金额汇总一致。
- `auditCounts` (AuditCounts, optional) — 四类完整审计记录总数。
- `autoResume` (boolean, optional, deprecated) — 兼容旧客户端的字段；新客户端使用 policy.resumeOnAccess。

## Errors

### 400 Bad Request Error

请求参数无效或没有兼容规格

- `statusCode` (integer, optional) — HTTP 状态码的数值形式，例如 400、401、402、404、409 或 429。
- `message` (ErrorMessage, optional) — 面向调用方的错误原因；校验失败时可能是多条消息数组。
- `error` (string, optional) — HTTP 错误类别，例如 Bad Request、Unauthorized 或 Conflict。

### 401 Unauthorized Error

API Key 缺失或无效

- `statusCode` (integer, optional) — HTTP 状态码的数值形式，例如 400、401、402、404、409 或 429。
- `message` (ErrorMessage, optional) — 面向调用方的错误原因；校验失败时可能是多条消息数组。
- `error` (string, optional) — HTTP 错误类别，例如 Bad Request、Unauthorized 或 Conflict。

### 402 Payment Required Error

账户余额或密钥额度不足

- `statusCode` (integer, optional) — HTTP 状态码的数值形式，例如 400、401、402、404、409 或 429。
- `message` (ErrorMessage, optional) — 面向调用方的错误原因；校验失败时可能是多条消息数组。
- `error` (string, optional) — HTTP 错误类别，例如 Bad Request、Unauthorized 或 Conflict。

### 404 Not Found Error

实例或资源不存在，或者不属于当前账户

- `statusCode` (integer, optional) — HTTP 状态码的数值形式，例如 400、401、402、404、409 或 429。
- `message` (ErrorMessage, optional) — 面向调用方的错误原因；校验失败时可能是多条消息数组。
- `error` (string, optional) — HTTP 错误类别，例如 Bad Request、Unauthorized 或 Conflict。

### 409 Conflict Error

实例状态不允许当前操作，或已有状态变更正在执行

- `statusCode` (integer, optional) — HTTP 状态码的数值形式，例如 400、401、402、404、409 或 429。
- `message` (ErrorMessage, optional) — 面向调用方的错误原因；校验失败时可能是多条消息数组。
- `error` (string, optional) — HTTP 错误类别，例如 Bad Request、Unauthorized 或 Conflict。

### 429 Too Many Requests Error

创建实例频率超过限制

- `statusCode` (integer, optional) — HTTP 状态码的数值形式，例如 400、401、402、404、409 或 429。
- `message` (ErrorMessage, optional) — 面向调用方的错误原因；校验失败时可能是多条消息数组。
- `error` (string, optional) — HTTP 错误类别，例如 Bad Request、Unauthorized 或 Conflict。

## Types

### Selection

实例规格选择器。quoteId、offeringId、requirements 必须且只能提供一个。 推荐先报价再传 quoteId；需要创建时动态匹配才使用 requirements。

- `quoteId` (string, optional) — POST /v1/quotes 返回的短期报价凭证。应在 expiresAt 前尽快使用；每个业务创建单独报价，同一 idempotencyKey 的重试可复用。
- `offeringId` (string, optional) — 固定选择 GET /v1/offerings 返回的具体规格，不进行动态重选。
- `requirements` (Requirements, optional) — 创建时按能力、资源、环境和区域约束动态选择兼容 offering。
- `maxEstimatedHourlyUsd` (string, optional) — 仅与 requirements 一起使用的每小时预估价格硬上限；超出上限不会创建实例。

### CreateSandboxRequestPolicy

实例访问与生命周期策略。使用前先确认目标 offering 声明支持相应策略。

- `resumeOnAccess` (boolean, optional, default: false) — 访问已暂停实例时是否自动恢复；offering 不支持该能力时创建会失败。

### SandboxPolicy

创建时生效的实例生命周期策略。

- `resumeOnAccess` (boolean, optional) — 访问暂停实例时是否尝试自动恢复；必须由 offering 支持。

### ResourceSnapshot

实例实际分配或 offering 声明的资源快照；供应商可以附加扩展资源字段。

- `cpu` (double, optional) — vCPU 数量。
- `memoryGiB` (double, optional) — 内存容量，单位 GiB。
- `volumeGiB` (double, optional) — 工作卷/持久卷容量，单位 GiB。
- `snapshotGiB` (double, optional) — 快照存储容量或计费基数，单位 GiB。
- `gpu` (list of ResourceSnapshotGpuItems, optional) — 分配的 GPU 型号与数量；CPU-only offering 通常省略。
- `environment` (map from string to any, optional) — 供应商返回的运行环境快照，例如镜像、语言或框架信息。

### Offering

可创建 Sandbox 的实时规格、能力、生命周期和计费声明。

- `id` (string, required) — offering 的稳定 UUID；可用于 selection.offeringId 固定选型。
- `name` (string, required) — 面向用户展示的规格名称。
- `resources` (ResourceSnapshot, required) — 该规格默认分配和计费使用的资源快照。
- `capabilities` (SandboxCapabilities, required) — 可用的标准能力、扩展 ID 和暂停语义。
- `description` (string, optional, nullable) — 规格用途和供应商适配说明。
- `region` (string, optional, nullable) — 默认/固定区域；null 表示区域由供应商自动选择或未固定。
- `lifecycle` (OfferingLifecycle, optional) — 规范化生命周期声明。
- `billing` (OfferingBilling, optional) — 按状态计算的预估小时费用摘要。
- `rateCard` (RateCard, optional) — 用于实际预留和结算的费率规则。
- `rateCardVersion` (integer, optional) — 数据库中的 offering 费率修订号；变更后旧 quote 可能失效。
- `rollingWindowSeconds` (integer, optional) — 每次预留的滚动用量窗口长度（秒）；不是实例最大运行时间。
- `shutdownGraceSeconds` (integer, optional) — 为安全销毁预留的关机宽限时长（秒）。
- `retentionWindowSeconds` (integer, optional) — 终态数据/供应商资源的声明保留窗口（秒）；不等于文件永久保留承诺。
- `provider` (ProviderSummary, optional) — 提供该规格的服务商展示信息。

### Operation

一次生命周期或数据面调用的持久化审计记录。

- `id` (string, optional) — 操作记录 UUID，用于日志关联，不是实例 ID。
- `idempotencyKey` (string, optional) — 此操作的幂等键；重复请求是否属于同一操作由实例 ID 和该值共同确定。
- `type` (enum, optional) — 操作类型。生命周期操作改变状态；EXEC/FILE/PORT/EXTENSION 是实例内的数据面调用。
  - Allowed values: `CREATE`, `SUSPEND`, `RESUME`, `TERMINATE`, `EXEC`, `EXTENSION`, `FILE_READ`, `FILE_WRITE`, `FILE_LIST`, `PORT_OPEN`
- `status` (enum, optional) — 操作执行状态；HTTP 已接受不代表这里已经 SUCCEEDED。
  - Allowed values: `PENDING`, `RUNNING`, `SUCCEEDED`, `FAILED`, `TIMED_OUT`, `CANCELLED`
- `expectedState` (enum, optional, nullable) — 生命周期操作期望实例最终达到的状态；数据面操作通常为 null。
  - Allowed values: `PROVISIONING`, `RUNNING`, `SUSPENDED`, `TERMINATED`, `FAILED`, `UNKNOWN`
- `error` (string, optional, nullable) — 操作失败、超时或取消时的诊断信息；成功时为 null。
- `input` (map from string to any, optional) — 已脱敏/裁剪的操作输入摘要；文件写入只记录路径、编码和大小，不保存文件内容。
- `requestedAt` (datetime, optional) — Gateway 接受操作请求的时间。
- `startedAt` (datetime, optional, nullable) — 适配器实际开始处理的时间；尚未开始时为 null。
- `completedAt` (datetime, optional, nullable) — 操作进入终态的时间；仍在执行时为 null。
- `durationMs` (integer, optional) — 操作实际执行耗时，单位毫秒；并非实例总运行时长。
- `exitCode` (integer, optional) — EXEC 操作的远端进程退出码；0 通常表示成功，非零表示命令失败但 HTTP 请求可能仍成功。
- `stdoutPreview` (string, optional) — 为审计保存的标准输出前缀，不保证是完整 stdout。
- `stderrPreview` (string, optional) — 为审计保存的标准错误前缀，不保证是完整 stderr。
- `outputTruncated` (boolean, optional) — stdoutPreview 或 stderrPreview 是否因日志大小限制被截断。

### StateEvent

供应商状态变化经 Gateway 规范化后的事件；按 sequence 判断实例状态演进顺序。

- `id` (string, optional) — xAPI 保存的事件 UUID。
- `sequence` (integer, optional) — 当前供应商分配内单调递增的事件序号，用于去重和排序。
- `eventType` (enum, optional) — 规范事件类型；当前为 sandbox.state_changed。
  - Allowed values: `sandbox.state_changed`
- `previousState` (enum, optional) — 变化前状态；首个事件或供应商未提供时可能省略。
  - Allowed values: `PROVISIONING`, `RUNNING`, `SUSPENDED`, `TERMINATED`, `FAILED`, `UNKNOWN`
- `currentState` (enum, optional) — 此事件确认的新状态。
  - Allowed values: `PROVISIONING`, `RUNNING`, `SUSPENDED`, `TERMINATED`, `FAILED`, `UNKNOWN`
- `reason` (string, optional, nullable) — 供应商给出的状态变化原因或失败说明；没有原因时为 null。
- `effectiveAt` (datetime, optional) — 状态变化实际生效时间。
- `observedAt` (datetime, optional) — 供应商或适配器观测到该状态的时间。
- `receivedAt` (datetime, optional) — Gateway 收到并保存该事件的时间；可能晚于 observedAt。
- `timestampSource` (enum, optional) — 时间来源：供应商原生事件、适配器轮询观测或 Gateway 推断。
  - Allowed values: `PROVIDER_NATIVE`, `ADAPTER_OBSERVED`, `INFERRED`
- `resources` (ResourceSnapshot, optional) — 状态变化时确认的资源快照。
- `status` (enum, optional) — Gateway 对事件的处理结果；REJECTED 事件不应被视为有效状态证据。
  - Allowed values: `ACCEPTED`, `PROCESSED`, `REJECTED`

### UsageSegment

实例在同一状态和同一资源快照下的一段连续用量，是费用结算的时间基础。

- `id` (string, optional) — 用量段 UUID。
- `state` (enum, optional) — 此用量段持续期间的规范实例状态。
  - Allowed values: `PROVISIONING`, `RUNNING`, `SUSPENDED`, `TERMINATED`, `FAILED`, `UNKNOWN`
- `startsAt` (datetime, optional) — 用量段开始时间。
- `endsAt` (datetime, optional, nullable) — 用量段结束时间；活动段可能为 null，终态验收时不应存在开放段。
- `durationSeconds` (string, optional, nullable) — 服务端按事件时间计算的持续秒数，以十进制字符串返回以避免精度损失。
- `amount` (string, optional, nullable) — 此用量段最终结算金额（USD）；未结算时可能为 null。
- `resources` (ResourceSnapshot, optional) — 该用量段采用的资源数量快照。
- `timestampSource` (enum, optional) — 开始/结束时间的可信来源。
  - Allowed values: `PROVIDER_NATIVE`, `ADAPTER_OBSERVED`, `INFERRED`
- `status` (enum, optional) — OPEN=仍计量；CLOSED=已结束待结算；SETTLED=已结算；UNVERIFIED=状态时间待确认；VOID=不计费。
  - Allowed values: `OPEN`, `CLOSED`, `SETTLED`, `UNVERIFIED`, `VOID`

### BillingPeriod

一次用量窗口、关机预留或按操作计费的资金预留与结算记录。

- `id` (string, optional) — 账期 UUID。
- `kind` (enum, optional) — USAGE=状态/资源用量；SHUTDOWN=安全销毁预留；OPERATION=按次调用费用。
  - Allowed values: `USAGE`, `SHUTDOWN`, `OPERATION`
- `status` (enum, optional) — RESERVED=已预留未完成；SETTLED=已扣费；RELEASED=未使用并释放；UNVERIFIED=等待人工/系统核对。
  - Allowed values: `RESERVED`, `SETTLED`, `RELEASED`, `UNVERIFIED`
- `startsAt` (datetime, optional) — 账期或资金预留开始时间。
- `endedAt` (datetime, optional, nullable) — 账期终止时间；活动账期可能为 null。
- `amount` (string, optional, nullable) — 最终实际结算金额（USD）；RESERVED 阶段可能尚未确定。
- `breakdown` (BillingBreakdown, optional) — 此账期的计算明细；没有产生费用时可能为空或省略。

### AuditCounts

当前实例四类完整审计记录的总数；详情响应可能只内嵌最近若干条，应通过 audit 接口分页读取全部。

- `operations` (integer, optional) — 操作审计记录总数。
- `events` (integer, optional) — 状态事件总数。
- `usageSegments` (integer, optional) — 用量段总数。
- `billingPeriods` (integer, optional) — 账期记录总数。

### ErrorMessage

面向调用方的错误原因；校验失败时可能是多条消息数组。

- string
- list of string

### Requirements

资源、环境和能力约束。未声明的资源由选中的 offering 使用默认值。

- `environmentId` (string, optional) — GET /v1/environments 返回的预置环境 ID，例如 python-3.12；只匹配支持该环境的 offering。
- `cpu` (MinimumRequirement, optional) — 最低 vCPU 数量要求。
- `memoryGiB` (MinimumRequirement, optional) — 最低内存容量，单位 GiB。
- `volumeGiB` (MinimumRequirement, optional) — 最低持久/工作卷容量，单位 GiB；具体保留行为由 offering 生命周期声明决定。
- `gpu` (GpuRequirement, optional) — GPU 最低数量与型号要求。
- `regions` (list of string, optional) — 允许创建实例的区域白名单；匹配其中任意一个区域即可。
- `capabilities` (list of string, optional) — 必须具备的能力名称。常用值：exec=执行命令、backgroundExec=后台长驻命令、 files=文件读写、ports=端口访问、snapshot=快照；扩展能力以实时 offering 声明为准。

### ResourceSnapshotGpuItems

- `model` (string, optional) — GPU 型号。
- `count` (integer, optional) — 该型号 GPU 数量。

### SandboxCapabilities

offering 对标准 Sandbox 能力和供应商扩展的声明；调用能力接口前应检查对应布尔值。

- `exec` (boolean, optional) — 是否支持执行 Shell 命令。
- `backgroundExec` (boolean, optional) — 是否支持 background=true，在 HTTP 响应后继续保留供应商托管的后台命令会话；启动 Web 服务前应检查此字段。
- `files` (boolean, optional) — 是否支持文件读取、写入和目录枚举。
- `terminal` (boolean, optional) — 是否支持交互式终端能力；REST command 接口仍以 exec 为准。
- `ports` (boolean, optional) — 是否支持把实例内监听端口映射为外部访问地址。
- `snapshot` (boolean, optional) — 是否支持快照相关能力；具体调用方式可能由扩展提供。
- `fork` (boolean, optional) — 是否支持从现有实例/快照派生新实例。
- `gpu` (boolean, optional) — 是否提供 GPU 资源；仍需核对 resources.gpu 和具体扩展。
- `extensionIds` (list of string, optional) — 允许调用的供应商扩展 ID 白名单；不要调用列表之外的扩展。
- `suspension` (SuspensionCapabilities, optional) — 规范化后的暂停、恢复和自动唤醒能力。

### OfferingLifecycle

offering 的生命周期能力与状态保留语义。

- `suspension` (SuspensionCapabilities, optional) — 暂停状态支持、恢复方式、保留内容和暂停时预估费用。

### OfferingBilling

根据当前 rate card 和资源计算出的各状态预估费用摘要；最终费用以实例 totalCost 为准。

- `currency` (enum, optional) — 所有价格和费用字段使用的货币。
  - Allowed values: `USD`
- `estimatedHourlyUsdByState` (map from string to string, optional) — 按 PROVISIONING、RUNNING、SUSPENDED 等状态给出的每小时预估费用，值为 USD 十进制字符串。
- `computeDefaultState` (enum, optional) — 默认产生计算资源费用的状态。
  - Allowed values: `RUNNING`
- `storageContinuesWhileSuspended` (boolean, optional) — 暂停时是否仍存在卷/快照等存储费用；false 不代表所有其他费用必然为零。

### RateCard

服务端用于预留和结算费用的费率快照。

- `version` (enum, required) — rate card 数据格式版本。
  - Allowed values: `1`, `2`
- `currency` (enum, required) — 费率货币。
  - Allowed values: `USD`
- `components` (list of RateCardComponent, required) — 组成总费用的计费规则列表。

### ProviderSummary

实际提供该 offering 的 Sandbox 服务商展示信息。

- `name` (string, optional) — 服务商名称。
- `logoUrl` (string, optional, nullable) — 服务商 Logo URL；未配置时为 null。

### BillingBreakdown

账期金额的可审计计算明细。

- `lines` (list of BillingBreakdownLine, optional) — 每项状态、资源或操作费用明细。
- `totalUsd` (string, optional) — 所有明细行金额之和。
- `durationSeconds` (string, optional) — 此账期计入费用的总时长（秒）；操作计费可能为 0。

### MinimumRequirement

某项资源的最低要求；服务可以选择数值更高的 offering，但不会选择更低的规格。

- `min` (double, required) — 允许的最小资源数量。CPU 以 vCPU 计，内存和磁盘由所属字段决定单位。

### GpuRequirement

GPU 数量和可选型号约束；GPU 实例通常费用更高，应同时设置价格上限。

- `count` (integer, required) — 所需 GPU 的最少数量。
- `model` (string, optional) — 期望的 GPU 型号或供应商可识别的型号名；省略表示不限定型号。

### SuspensionCapabilities

offering 的暂停、恢复和访问时唤醒语义；不要从 supported 推断文件、内存和进程都保留。

- `supported` (boolean, required) — 是否支持显式 suspend 操作。
- `preservesFilesystem` (boolean, optional) — 暂停后恢复时工作区文件是否保留。
- `preservesMemory` (boolean, optional) — 暂停后恢复时内存内容是否保留。
- `preservesProcesses` (boolean, optional) — 暂停后恢复时原进程是否继续存在。
- `capacityReserved` (boolean, optional) — 暂停期间供应商是否仍为该实例保留计算容量；可能影响费用和恢复速度。
- `resumeSupported` (boolean, optional) — 暂停后是否支持显式 resume。
- `resumeOnAccessSupported` (boolean, optional) — 是否支持访问 exec/files/ports 时自动恢复。
- `resumeOnAccessMode` (enum, optional) — NATIVE=供应商原生唤醒；ADAPTER=xAPI 适配器先恢复再执行；UNSUPPORTED=不可用。
  - Allowed values: `NATIVE`, `ADAPTER`, `UNSUPPORTED`
- `wakeOperations` (list of string, optional) — 可以触发访问时唤醒的操作名，例如 exec、files.read、ports.connect。
- `estimatedHourlyUsd` (string, optional) — 实例处于 SUSPENDED 时的预估小时费用，USD 十进制字符串。

### RateCardComponent

一条计费规则；具体计费基数由 kind 决定。

- `kind` (enum, required) — STATE_TIME=按实例状态时长；RESOURCE_TIME=按资源数量和时长；OPERATION=按调用次数。
  - Allowed values: `STATE_TIME`, `RESOURCE_TIME`, `OPERATION`
- `unit` (enum, required) — 计费单位；时长规则为 SECOND，调用规则为 COUNT。
  - Allowed values: `SECOND`, `COUNT`
- `priceUsd` (string, required) — 每单位价格，USD 十进制字符串。
- `state` (enum, optional) — 该规则适用的实例状态；OPERATION 规则通常省略。
  - Allowed values: `PROVISIONING`, `RUNNING`, `SUSPENDED`, `TERMINATED`, `FAILED`, `UNKNOWN`
- `category` (enum, optional) — 费用分类，用于账单归类。
  - Allowed values: `COMPUTE`, `CAPACITY_RESERVATION`, `STORAGE`, `OTHER`
- `resource` (enum, optional) — RESOURCE_TIME 规则计费的资源类型。
  - Allowed values: `CPU`, `MEMORY_GIB`, `VOLUME_GIB`, `SNAPSHOT_GIB`, `GPU`
- `resourceKey` (string, optional) — 细分资源键，例如具体 GPU 型号；普通 CPU/内存规则通常省略。
- `operation` (string, optional) — OPERATION 规则计费的操作名。

### BillingBreakdownLine

账期内某一条 rate card 规则产生的费用明细。

- `quantity` (string, optional) — 使用量；按时长规则通常是秒数，按操作规则通常是次数。
- `amountUsd` (string, optional) — 该明细行费用，USD 十进制字符串。
- `component` (RateCardComponent, optional) — 计算该行费用所使用的费率规则快照。

## Examples

### 使用 quoteId 创建（推荐）

**Request**

```json
{
  "selection": {
    "quoteId": "REPLACE_WITH_QUOTE_ID"
  },
  "idempotencyKey": "docs-create-quote-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "sandbox-api-test"
  }
}
```

**Response**

```json
{
  "id": "33333333-3333-4333-8333-333333333333",
  "offeringId": "11111111-1111-4111-8111-111111111111",
  "observedState": "PROVISIONING",
  "totalCost": "0",
  "createdAt": "2026-08-13T08:19:50.000Z",
  "updatedAt": "2026-08-13T08:19:50.000Z",
  "idempotencyKey": "docs-create-quote-20260813-001",
  "desiredState": "RUNNING"
}
```

**SDK Code**

```python 使用 quoteId 创建（推荐）
import requests

url = "https://sandbox.xapi.to/v1/sandboxes"

payload = {
    "selection": { "quoteId": "REPLACE_WITH_QUOTE_ID" },
    "idempotencyKey": "docs-create-quote-20260813-001",
    "policy": { "resumeOnAccess": False },
    "metadata": {
        "client": "fern-docs",
        "purpose": "sandbox-api-test"
    }
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 使用 quoteId 创建（推荐）
const url = 'https://sandbox.xapi.to/v1/sandboxes';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"selection":{"quoteId":"REPLACE_WITH_QUOTE_ID"},"idempotencyKey":"docs-create-quote-20260813-001","policy":{"resumeOnAccess":false},"metadata":{"client":"fern-docs","purpose":"sandbox-api-test"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 使用 quoteId 创建（推荐）
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes"

	payload := strings.NewReader("{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 使用 quoteId 创建（推荐）
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java 使用 quoteId 创建（推荐）
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}")
  .asString();
```

```php 使用 quoteId 创建（推荐）
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes', [
  'body' => '{
  "selection": {
    "quoteId": "REPLACE_WITH_QUOTE_ID"
  },
  "idempotencyKey": "docs-create-quote-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "sandbox-api-test"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp 使用 quoteId 创建（推荐）
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"selection\": {\n    \"quoteId\": \"REPLACE_WITH_QUOTE_ID\"\n  },\n  \"idempotencyKey\": \"docs-create-quote-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"sandbox-api-test\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 使用 quoteId 创建（推荐）
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "selection": ["quoteId": "REPLACE_WITH_QUOTE_ID"],
  "idempotencyKey": "docs-create-quote-20260813-001",
  "policy": ["resumeOnAccess": false],
  "metadata": [
    "client": "fern-docs",
    "purpose": "sandbox-api-test"
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 固定 offeringId 创建

**Request**

```json
{
  "selection": {
    "offeringId": "11111111-1111-4111-8111-111111111111"
  },
  "idempotencyKey": "docs-create-offering-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "pinned-offering-test"
  }
}
```

**Response**

```json
{
  "id": "44444444-4444-4444-8444-444444444444",
  "offeringId": "11111111-1111-4111-8111-111111111111",
  "observedState": "PROVISIONING",
  "totalCost": "0",
  "createdAt": "2026-08-13T08:21:00.000Z",
  "updatedAt": "2026-08-13T08:21:00.000Z",
  "idempotencyKey": "docs-create-offering-20260813-001",
  "desiredState": "RUNNING"
}
```

**SDK Code**

```python 固定 offeringId 创建
import requests

url = "https://sandbox.xapi.to/v1/sandboxes"

payload = {
    "selection": { "offeringId": "11111111-1111-4111-8111-111111111111" },
    "idempotencyKey": "docs-create-offering-20260813-001",
    "policy": { "resumeOnAccess": False },
    "metadata": {
        "client": "fern-docs",
        "purpose": "pinned-offering-test"
    }
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 固定 offeringId 创建
const url = 'https://sandbox.xapi.to/v1/sandboxes';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"selection":{"offeringId":"11111111-1111-4111-8111-111111111111"},"idempotencyKey":"docs-create-offering-20260813-001","policy":{"resumeOnAccess":false},"metadata":{"client":"fern-docs","purpose":"pinned-offering-test"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 固定 offeringId 创建
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes"

	payload := strings.NewReader("{\n  \"selection\": {\n    \"offeringId\": \"11111111-1111-4111-8111-111111111111\"\n  },\n  \"idempotencyKey\": \"docs-create-offering-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"pinned-offering-test\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 固定 offeringId 创建
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"selection\": {\n    \"offeringId\": \"11111111-1111-4111-8111-111111111111\"\n  },\n  \"idempotencyKey\": \"docs-create-offering-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"pinned-offering-test\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java 固定 offeringId 创建
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"selection\": {\n    \"offeringId\": \"11111111-1111-4111-8111-111111111111\"\n  },\n  \"idempotencyKey\": \"docs-create-offering-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"pinned-offering-test\"\n  }\n}")
  .asString();
```

```php 固定 offeringId 创建
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes', [
  'body' => '{
  "selection": {
    "offeringId": "11111111-1111-4111-8111-111111111111"
  },
  "idempotencyKey": "docs-create-offering-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "pinned-offering-test"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp 固定 offeringId 创建
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"selection\": {\n    \"offeringId\": \"11111111-1111-4111-8111-111111111111\"\n  },\n  \"idempotencyKey\": \"docs-create-offering-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"pinned-offering-test\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 固定 offeringId 创建
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "selection": ["offeringId": "11111111-1111-4111-8111-111111111111"],
  "idempotencyKey": "docs-create-offering-20260813-001",
  "policy": ["resumeOnAccess": false],
  "metadata": [
    "client": "fern-docs",
    "purpose": "pinned-offering-test"
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 按 requirements 动态选择

**Request**

```json
{
  "selection": {
    "requirements": {
      "cpu": {
        "min": 1
      },
      "memoryGiB": {
        "min": 1
      },
      "capabilities": [
        "exec",
        "files"
      ]
    },
    "maxEstimatedHourlyUsd": "0.20"
  },
  "idempotencyKey": "docs-create-requirements-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "dynamic-selection-test"
  }
}
```

**Response**

```json
{
  "id": "55555555-5555-4555-8555-555555555555",
  "offeringId": "11111111-1111-4111-8111-111111111111",
  "observedState": "PROVISIONING",
  "totalCost": "0",
  "createdAt": "2026-08-13T08:22:00.000Z",
  "updatedAt": "2026-08-13T08:22:00.000Z",
  "idempotencyKey": "docs-create-requirements-20260813-001",
  "desiredState": "RUNNING"
}
```

**SDK Code**

```python 按 requirements 动态选择
import requests

url = "https://sandbox.xapi.to/v1/sandboxes"

payload = {
    "selection": {
        "requirements": {
            "cpu": { "min": 1 },
            "memoryGiB": { "min": 1 },
            "capabilities": ["exec", "files"]
        },
        "maxEstimatedHourlyUsd": "0.20"
    },
    "idempotencyKey": "docs-create-requirements-20260813-001",
    "policy": { "resumeOnAccess": False },
    "metadata": {
        "client": "fern-docs",
        "purpose": "dynamic-selection-test"
    }
}
headers = {
    "XAPI-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript 按 requirements 动态选择
const url = 'https://sandbox.xapi.to/v1/sandboxes';
const options = {
  method: 'POST',
  headers: {'XAPI-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"selection":{"requirements":{"cpu":{"min":1},"memoryGiB":{"min":1},"capabilities":["exec","files"]},"maxEstimatedHourlyUsd":"0.20"},"idempotencyKey":"docs-create-requirements-20260813-001","policy":{"resumeOnAccess":false},"metadata":{"client":"fern-docs","purpose":"dynamic-selection-test"}}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 按 requirements 动态选择
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sandbox.xapi.to/v1/sandboxes"

	payload := strings.NewReader("{\n  \"selection\": {\n    \"requirements\": {\n      \"cpu\": {\n        \"min\": 1\n      },\n      \"memoryGiB\": {\n        \"min\": 1\n      },\n      \"capabilities\": [\n        \"exec\",\n        \"files\"\n      ]\n    },\n    \"maxEstimatedHourlyUsd\": \"0.20\"\n  },\n  \"idempotencyKey\": \"docs-create-requirements-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"dynamic-selection-test\"\n  }\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("XAPI-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 按 requirements 动态选择
require 'uri'
require 'net/http'

url = URI("https://sandbox.xapi.to/v1/sandboxes")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["XAPI-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"selection\": {\n    \"requirements\": {\n      \"cpu\": {\n        \"min\": 1\n      },\n      \"memoryGiB\": {\n        \"min\": 1\n      },\n      \"capabilities\": [\n        \"exec\",\n        \"files\"\n      ]\n    },\n    \"maxEstimatedHourlyUsd\": \"0.20\"\n  },\n  \"idempotencyKey\": \"docs-create-requirements-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"dynamic-selection-test\"\n  }\n}"

response = http.request(request)
puts response.read_body
```

```java 按 requirements 动态选择
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://sandbox.xapi.to/v1/sandboxes")
  .header("XAPI-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"selection\": {\n    \"requirements\": {\n      \"cpu\": {\n        \"min\": 1\n      },\n      \"memoryGiB\": {\n        \"min\": 1\n      },\n      \"capabilities\": [\n        \"exec\",\n        \"files\"\n      ]\n    },\n    \"maxEstimatedHourlyUsd\": \"0.20\"\n  },\n  \"idempotencyKey\": \"docs-create-requirements-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"dynamic-selection-test\"\n  }\n}")
  .asString();
```

```php 按 requirements 动态选择
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://sandbox.xapi.to/v1/sandboxes', [
  'body' => '{
  "selection": {
    "requirements": {
      "cpu": {
        "min": 1
      },
      "memoryGiB": {
        "min": 1
      },
      "capabilities": [
        "exec",
        "files"
      ]
    },
    "maxEstimatedHourlyUsd": "0.20"
  },
  "idempotencyKey": "docs-create-requirements-20260813-001",
  "policy": {
    "resumeOnAccess": false
  },
  "metadata": {
    "client": "fern-docs",
    "purpose": "dynamic-selection-test"
  }
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'XAPI-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp 按 requirements 动态选择
using RestSharp;

var client = new RestClient("https://sandbox.xapi.to/v1/sandboxes");
var request = new RestRequest(Method.POST);
request.AddHeader("XAPI-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"selection\": {\n    \"requirements\": {\n      \"cpu\": {\n        \"min\": 1\n      },\n      \"memoryGiB\": {\n        \"min\": 1\n      },\n      \"capabilities\": [\n        \"exec\",\n        \"files\"\n      ]\n    },\n    \"maxEstimatedHourlyUsd\": \"0.20\"\n  },\n  \"idempotencyKey\": \"docs-create-requirements-20260813-001\",\n  \"policy\": {\n    \"resumeOnAccess\": false\n  },\n  \"metadata\": {\n    \"client\": \"fern-docs\",\n    \"purpose\": \"dynamic-selection-test\"\n  }\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 按 requirements 动态选择
import Foundation

let headers = [
  "XAPI-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "selection": [
    "requirements": [
      "cpu": ["min": 1],
      "memoryGiB": ["min": 1],
      "capabilities": ["exec", "files"]
    ],
    "maxEstimatedHourlyUsd": "0.20"
  ],
  "idempotencyKey": "docs-create-requirements-20260813-001",
  "policy": ["resumeOnAccess": false],
  "metadata": [
    "client": "fern-docs",
    "purpose": "dynamic-selection-test"
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.xapi.to/v1/sandboxes")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```