vastai-workflow

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Vast.ai Workflow

Vast.ai 工作流

Overview

概述

Use this skill for provider-level Vast.ai automation only. Keep it project-agnostic and parameter-driven.
本技能仅用于服务商级别的Vast.ai自动化操作。保持与项目无关,采用参数驱动。

Scope Boundaries

范围边界

  • Handle only Vast API workflow logic: offers, create, poll, SSH attach, lifecycle, billing.
  • Do not embed project-specific repo paths, branch names, labels, or training commands.
  • If the user asks for workload-specific execution (for example Reparo training), switch to the corresponding workload skill after infrastructure provisioning.
  • 仅处理Vast API工作流逻辑:报价、创建、轮询、SSH附加、生命周期、计费。
  • 请勿嵌入项目特定的仓库路径、分支名称、标签或训练命令。
  • 如果用户请求特定工作负载的执行(例如Reparo训练),请在基础设施配置完成后切换到对应的工作负载技能。

Dialog-First Required Fields

对话优先的必要字段

Before any create/order call, confirm required runtime fields in dialog. If the user does not provide them, propose defaults and ask for confirmation.
Required fields and default suggestions:
  • api_key_source
    : default
    VAST_API_KEY
    environment variable.
    • If missing, suggest loading from a local file path the user confirms (for example
      keys/.vast_env
      ).
  • instance_type
    (offer filter): default
    gpu_name="RTX 4090"
    .
    • Ask whether to lock by exact GPU, VRAM minimum, region, max price, and reliability.
  • image
    : default
    pytorch/pytorch:latest
    .
  • disk_gb
    : default
    64
    .
  • count
    : default
    1
    .
  • label
    : do not ask by default.
    • Derive from Vast account identity when possible (nickname or email local-part).
    • Fallback label:
      vast-user
      .
Suggested minimal question set:
  1. Which action now (
    offers
    ,
    create
    ,
    status
    ,
    ssh
    ,
    destroy
    ,
    billing
    )?
  2. Confirm runtime fields (
    image
    ,
    disk_gb
    , instance filter).
  3. Confirm API key source (
    VAST_API_KEY
    env vs file path).
If the user approves defaults, proceed without extra questions.
在进行任何创建/下单调用前,需通过对话确认必要的运行时字段。如果用户未提供,需给出默认建议并请求确认。
必要字段及默认建议:
  • api_key_source
    :默认值为
    VAST_API_KEY
    环境变量。
    • 如果缺失,建议从用户确认的本地文件路径加载(例如
      keys/.vast_env
      )。
  • instance_type
    (报价筛选):默认值为
    gpu_name="RTX 4090"
    • 询问是否要按精确GPU型号、最小显存、地域、最高价格和可靠性进行锁定筛选。
  • image
    :默认值为
    pytorch/pytorch:latest
  • disk_gb
    :默认值为
    64
  • count
    :默认值为
    1
  • label
    :默认不询问。
    • 尽可能从Vast账户身份信息中推导(昵称或邮箱本地部分)。
    • 备用标签:
      vast-user
建议的最简问题集:
  1. 现在执行哪个操作(
    offers
    create
    status
    ssh
    destroy
    billing
    )?
  2. 确认运行时字段(
    image
    disk_gb
    、实例筛选条件)。
  3. 确认API密钥来源(
    VAST_API_KEY
    环境变量 vs 文件路径)。
如果用户认可默认值,无需额外询问即可继续。

Workflow

工作流

1) Preflight

1) 预检

  • Check active instances first.
  • If any instances are unintentionally active, ask whether to stop/destroy before creating a new one.
  • Ensure API key is loaded and never echo it.
  • 首先检查活跃实例。
  • 如果存在非预期的活跃实例,询问是否要在创建新实例前停止/销毁它们。
  • 确保API密钥已加载,且绝不回显密钥。

2) Find offers

2) 查找报价

  • Query offers (
    /bundles
    is commonly reliable in practice).
  • Apply user filters plus mandatory
    rentable=true
    and
    rented=false
    .
  • Sort by user objective (price, performance, reliability).
  • Use user policy for selection:
    • Default: choose cheapest valid offer.
    • Optional conservative mode: choose second cheapest.
  • 查询报价(实际使用中
    /bundles
    接口通常更可靠)。
  • 应用用户筛选条件,加上强制的
    rentable=true
    rented=false
  • 根据用户目标(价格、性能、可靠性)排序。
  • 遵循用户策略选择报价:
    • 默认:选择最便宜的有效报价。
    • 可选保守模式:选择第二便宜的报价。

3) Create instance

3) 创建实例

  • Create from a single selected offer (
    PUT /asks/{id}
    ).
  • Use confirmed
    image
    , resolved
    label
    , and
    disk_gb
    .
  • Parse and store the returned instance ID.
  • If create fails (
    no_such_ask
    or already taken), re-query and retry once with next candidate.
Label resolution order:
  1. Load profile/account endpoint data and use nickname when present.
  2. If nickname missing, use the email local-part when available.
  3. If neither field is available, use
    vast-user
    .
  • 从单个选中的报价创建实例(
    PUT /asks/{id}
    )。
  • 使用已确认的
    image
    、解析后的
    label
    disk_gb
  • 解析并存储返回的实例ID。
  • 如果创建失败(
    no_such_ask
    或报价已被占用),重新查询并使用下一个候选报价重试一次。
标签解析顺序:
  1. 加载个人资料/账户端点数据,若存在则使用昵称。
  2. 如果没有昵称,使用可用的邮箱本地部分。
  3. 如果上述两者都不可用,使用
    vast-user

4) Readiness and access

4) 就绪状态与访问

  • Poll instance status until running.
  • Add SSH key to account and attach to instance.
  • Retry SSH readiness for up to 2 minutes before declaring failure.
  • 轮询实例状态直到其运行。
  • 将SSH密钥添加到账户并附加到实例。
  • 重试SSH就绪检查最多2分钟,之后判定为失败。

5) Lifecycle and billing

5) 生命周期与计费

  • Support start/stop/restart when available.
  • Use destroy promptly when requested to prevent costs.
  • Verify final state and check usage/invoices when needed.
  • 支持可用的启动/停止/重启操作。
  • 收到请求后立即执行销毁操作以避免产生费用。
  • 必要时验证最终状态并检查使用情况/发票。

Request Templates

请求模板

Use explicit, reproducible requests and validate JSON before chaining calls.
bash
curl -sS -L -G "https://console.vast.ai/api/v0/<endpoint>/" \
  --data-urlencode "api_key=$VAST_API_KEY" \
  --data-urlencode "<param>=<value>"
bash
curl -sS -L -X PUT "https://console.vast.ai/api/v0/asks/$OFFER_ID/?api_key=$VAST_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"image\":\"$IMAGE\",\"disk\":$DISK_GB,\"label\":\"$LABEL\"}"
使用明确、可复现的请求,在链式调用前验证JSON格式。
bash
curl -sS -L -G "https://console.vast.ai/api/v0/<endpoint>/" \
  --data-urlencode "api_key=$VAST_API_KEY" \
  --data-urlencode "<param>=<value>"
bash
curl -sS -L -X PUT "https://console.vast.ai/api/v0/asks/$OFFER_ID/?api_key=$VAST_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"image\":\"$IMAGE\",\"disk\":$DISK_GB,\"label\":\"$LABEL\"}"

Error Handling

错误处理

  • 401/403
    : API key missing, invalid, or not authorized for requested org/action.
  • 429
    : rate limit; retry with backoff.
  • 4xx
    : invalid endpoint or params; re-check request shape and required fields.
  • 5xx
    : provider-side issue; retry with backoff and re-validate state.
  • Empty/parse failures: retry once, then save response to a temp file and parse from file.
  • 401/403
    :API密钥缺失、无效,或无权请求的组织/操作。
  • 429
    :请求频率超限;退避后重试。
  • 4xx
    :端点或参数无效;重新检查请求格式和必要字段。
  • 5xx
    :服务商端问题;退避后重试并重新验证状态。
  • 空响应/解析失败:重试一次,然后将响应保存到临时文件并从文件解析。

Resources

资源

  • references/api.md
    : concise endpoint map and safe calling checklist.
  • Treat
    references/api.md
    as the working source for endpoint details and refresh it against official docs regularly.
  • references/api.md
    :简洁的端点映射和安全调用检查清单。
  • references/api.md
    作为端点详情的工作来源,并定期对照官方文档更新。