mcpField
V
vastai

vastai

github.com/vast-aiクラウド・DevOps225861 回インストール6 日前に更新
リポジトリ

vastai について

vastai は Vast.ai の GPU レンタルを管理するコマンドラインツールです。計算リソースを構成・運用するユーザーやスクリプト向けに、インスタンスの検索と管理に加え、ストレージ、デプロイ、アカウント、請求を扱います。

主な機能

  1. 01GPU オファーの検索と絞り込み
  2. 02インスタンスの作成と管理
  3. 03ボリュームとテンプレートの管理
  4. 04ファイル転送とコマンド実行
  5. 05エンドポイントと請求の管理

活用シーン

  1. 01ハードウェア、地域、価格で GPU を検索
  2. 02計算インスタンスの構成と監視
  3. 03ローカルとクラウドストレージ間でデータセットを転送
  4. 04アカウント利用状況と料金を確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/vast-ai/vast-cli --skill vastai

インストール後、Claude Code で/vastaiを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

__init__.py
_base.py
api/
__init__.py
auth.py
billing.py
client.py
clusters.py
deployments.py
endpoints.py
instances.py
keys.py
machines.py
metrics.py
offers.py
price_increase.py
query.py
storage.py
teams.py
async_/
__init__.py
client.py
results.py
cli/
__init__.py
cli/commands/
__init__.py
auth.py
benchmarks.py
billing.py
clusters.py
deployments.py
endpoints.py
instances.py

詳細

vastai

Vast.ai で GPU インスタンス、テンプレート、ボリューム、サーバーレスエンドポイント、SSH キー、請求を管理します。

コマンドは vastai(小文字)です。機械可読な JSON 出力には、必ず --raw を使用してください。

インストール

# Linux/macOS (recommended, no Python required)
curl -fsSL https://vast.ai/install.sh | bash

# or via PyPI (Windows, or if you'd rather use pip)
pip install vastai

クイックスタート

vastai set api-key <YOUR_API_KEY>                   # Authenticate (one-time); Create API Key in account at https://console.vast.ai/manage-keys/
vastai show user                                    # Verify auth + check balance
vastai create ssh-key ~/.ssh/id_ed25519.pub         # Register SSH key (do BEFORE create)
vastai search offers 'gpu_name=RTX_4090 num_gpus=1 verified=true direct_port_count>=1 rentable=true' -o 'dlperf_usd-'
# Note the offer ID from the output
vastai create instance <OFFER_ID> --image pytorch/pytorch:@vastai-automatic-tag --disk 20 --ssh --direct
# Automatically grab appropriate image tag; Response:  {"success": true, "new_contract": <INSTANCE_ID>}
vastai show instance <INSTANCE_ID>                  # Poll until actual_status == "running" (see Instance status values below)
vastai ssh-url <INSTANCE_ID>                        # Get SSH connection string
vastai copy local:./data/ <INSTANCE_ID>:/workspace/ # Upload files
vastai destroy instance <INSTANCE_ID> -y             # Clean up (stops all billing; -y skips confirmation)

API キー:https://console.vast.ai/manage-keys/

グローバルフラグ

すべてのコマンドで使用できます。

--api-key KEY    Override stored API key
--raw            Output machine-readable JSON (agents should always use this)
--full           Print full results (don't page with less)
--explain        Show underlying API calls (useful for debugging)
--curl           Show equivalent curl command
--no-color       Disable colored output
--url URL        Override server REST API URL
--retry RETRY    Set retry limit for API calls
--version        Show CLI version

クエリ構文

検索コマンドでは、フィルター式を使用できます。演算子:=、!=、>、>=、<、<=、in、notin。

# Examples
'gpu_name=RTX_4090 num_gpus=1'           # Exact match + numeric
'gpu_ram>=48 reliability>0.95'           # Greater-than filters
'geolocation=EU dph_total<=2.0'          # Region + price cap

一般的なフィルターフィールド:num_gpus、gpu_name、gpu_ram、cpu_ram、disk_space、reliability、compute_cap、inet_up、inet_down、dph_total、geolocation、direct_port_count、verified、rentable

一般的な並べ替えフィールド:score(デフォルト — 総合的な価値)、dlperf_usd(ドルあたりの DL パフォーマンス)、dph_total(価格)、num_gpus、reliability

コマンド

インスタンス
vastai show instances                                    # List all your instances (fetches every page, no prompts)
vastai show instances --status running loading           # Filter by status
vastai show instances --gpu-name 'RTX 4090'              # Filter by GPU
vastai show instances --label training                   # Filter by label
vastai show instances --order-by start_date desc         # Sort by column
vastai show instances --cols id,status,gpu,dph           # Custom columns
vastai show instances --raw                              # Flat JSON list of all instances (scripting)
vastai show instance <id>                                # Poll single instance (use for status checks)
vastai create instance <offer-id> --image pytorch/pytorch:2.4.0-cuda12.4-cudnn9-runtime --disk 20 --ssh --direct
# Response includes "new_contract": <id> — that is your instance ID
vastai launch instance --gpu-name RTX_4090 --num-gpus 1 --image pytorch/pytorch
vastai start instance <id>                               # Start stopped instance
vastai stop instance <id>                                # Stop (preserves disk, no GPU charges)
vastai reboot instance <id>                              # Stop + start
vastai destroy instance <id> -y                          # Delete permanently (irreversible; -y required for non-interactive use)
vastai destroy instances <id1> <id2> -y                  # Batch delete (-y skips confirmation prompt)
vastai label instance <id> --label "training-run-1"      # Tag instance
vastai update instance <id>                              # Recreate from updated template
vastai prepay instance <id>                              # Deposit credits into reserved instance
vastai recycle instance <id>                             # Destroy + recreate

Vast.ai 推奨イメージ(@vastai-automatic-tag を使うと、マシンに適したタグが自動的に選択されます。事前設定済みモデルは https://vast.ai/model-library で確認できます)

vastai/base-image:@vastai-automatic-tag          # Minimal Ubuntu base
vastai/pytorch:@vastai-automatic-tag             # PyTorch + CUDA
vastai/linux-desktop:@vastai-automatic-tag       # Linux desktop (VNC/RDP)

# vLLM — set model via env vars with huggingface model example
vastai create instance <id> --image vastai/vllm:@vastai-automatic-tag --disk 40 --ssh --direct \
  --env '-e MODEL_NAME=Qwen/Qwen2.5-3B-Instruct -e HF_TOKEN=hf_xxx'

# ComfyUI — set model checkpoint via env vars with huggingface model example
vastai create instance <id> --image vastai/comfy:@vastai-automatic-tag --disk 40 --ssh --direct \
  --env '-e CHECKPOINT_MODEL=black-forest-labs/FLUX.1-schnell -e HF_TOKEN=hf_xxx'

インスタンス作成フラグ:

  • --image IMAGE — Docker イメージ
  • --disk DISK — ローカルディスク(GB)
  • --ssh / --jupyter — 接続タイプ
  • --direct — より高速な直接接続
  • --label LABEL — インスタンスのラベル
  • --env ENV — 環境変数とポートマッピング。例:'-e TZ=UTC -p 8080:8080'
  • --onstart FILE — 起動スクリプトファイルのパス
  • --onstart-cmd CMD — インライン文字列として指定する起動スクリプト(長いスクリプトには --onstart を使うか、gzip と base64 でエンコードしてください)
  • --bid_price PRICE — 中断可能(スポット)料金($/時)
  • --template_hash HASH — テンプレートから作成
  • --create-volume ID — 新しいボリュームを接続
  • --link-volume ID — 既存のボリュームを接続
  • --cancel-unavail — 利用可能なマシンがない場合は失敗(停止状態で作成する代わり)

インスタンスのステータス値:

actual_status意味
nullプロビジョニング中
createdインスタンス作成済み、プロビジョニング前
loadingイメージをダウンロード中/コンテナを起動中
runningアクティブ — GPU 料金が発生します
stopped停止中 — ディスク料金のみ発生します
frozenメモリを保持して一時停止中 — GPU 料金が発生します
exitedコンテナプロセスが予期せず終了しました
rebooting再起動中(一時的)
unknownホストから最近のハートビートがありません
offlineホストが Vast サーバーから切断されました

ポーリングループに関する警告: actual_status が exited、unknown、または offline になると、running にはなりません。必ずタイムアウトとエラー分岐を追加してください。そうしないと、ディスク料金が発生し続ける間、スクリプトが無限ループします。インスタンスを破棄し、別のオファーで再試行してください。

料金: ストレージ料金は作成時に発生し始めます。GPU 料金はステータスが running になった時点で発生し始めます。

中断可能(スポット)レンタル

中断可能(スポット)インスタンスはオンデマンドインスタンスより低価格ですが、別のユーザーがより高い入札をすると、いつでも中断される可能性があります。注:search offers --type bid では min_bid が表示されますが、--bid_price <floor> を渡さない場合、create instance は オンデマンドの dph_total をデフォルトで使用します。--type bid で検索した後は、必ず --bid_price を渡してください。そうしないと、中断可能インスタンスではなく、オンデマンドインスタンス/料金でレンタルされます。

入札額で負けると、インスタンスは破棄されずに stopped に移行し、ストレージ料金は引き続き発生します。update instance --bid_price で入札額を引き上げると再開できます。

検索
vastai search offers                                     # Default: verified, on-demand, sorted by score
vastai search offers 'gpu_name=RTX_4090 num_gpus=1 verified=true direct_port_count>=1' -o 'dlperf_usd-'
vastai search offers 'num_gpus>=4 reliability>0.99' -o 'num_gpus-'
vastai search offers --type bid                          # Interruptible (spot) pricing
vastai search offers --type reserved                     # Reserved pricing
vastai search offers -n 'gpu_name=H100_SXM'             # No default filters
vastai search volumes                                    # Search volume offers
vastai search templates "pytorch"                        # Search templates
vastai search benchmarks                                 # Search benchmarks
vastai search invoices                                   # Search invoice history

search offers のフラグ: --type on-demand|reserved|bid、--order/-o FIELD[-]、--limit、--storage GB、--no-default/-n

SSH とファイル転送
vastai ssh-url <id>                                      # Get ssh:// connection URL
vastai scp-url <id>                                      # Get scp:// URL
vastai attach ssh <id> "ssh-ed25519 AAAA..."             # Attach SSH key to instance
vastai detach ssh <id> <ssh_key_id>                      # Remove SSH key (ssh_key_id from show ssh-keys)
vastai show ssh-keys                                     # List account SSH keys
vastai create ssh-key ~/.ssh/id_ed25519.pub              # Add SSH key from file (do BEFORE create instance)
vastai create ssh-key                                    # Generate new key if you don't have one
vastai create ssh-key "ssh-ed25519 AAAA..."              # Add SSH key inline
vastai delete ssh-key <id>                               # Remove SSH key from account
vastai update ssh-key <id> "ssh-ed25519 AAAA..."         # Update SSH key value

注: ssh-url は接続文字列を返すだけで、対話型セッションは開きません。$(vastai ssh-url <id>) を使って URL を取り出すか、--raw の JSON 出力を解析してください。

ファイルコピー
vastai copy <src> <dst>                                  # Copy between instance and local
vastai copy local:./data/ <id>:/workspace/data/          # Local → instance (preferred format)
vastai copy <id>:/workspace/results/ local:./results/    # Instance → local
vastai copy <id-a>:/workspace/ <id-b>:/workspace/        # Instance → instance
vastai copy s3.101:/data/ C.<id>:/workspace/             # Cloud service → instance (s3.<connection-id>)
vastai copy V.1234:/file C.<id>:/workspace/              # Volume → instance
vastai copy V.1234:/file s3.101:/workspace/              # Volume → cloud service
# Legacy format also works: vastai copy 12345:./data ./local-data
vastai cloud copy --src ./data --dst s3://bucket/path \
  --instance 12345 --connection <conn-id> \
  --transfer "Instance To Cloud"                         # To cloud storage (add connection in UI on settings page)
vastai cancel copy <dst-id>                              # Cancel in-progress copy

クラウドコピーのフラグ: --src、--dst、--instance、--connection、--transfer

場所の形式: [instance_id:]path(レガシー)、C.instance_id:path、V.volume_id:path、cloud_service[.id]:path、local:path。ボリュームのコピーは現在、他のボリューム、インスタンス、クラウドサービスへのコピーのみサポートしており、ローカルへのコピーはサポートしていません。/root または / には絶対にコピーしないでください。インスタンスの SSH 権限が壊れ、以後のコピーが失敗します。

ログと実行
vastai logs <id>                                         # Container logs (last 1000 lines)
vastai logs <id> --tail 100                              # Last 100 lines
vastai logs <id> --filter "error"                        # Grep filter
vastai execute <id> "nvidia-smi"                         # Run command on instance
vastai execute <id> "ls /workspace" --schedule DAILY     # Scheduled execution
ボリューム
vastai search volumes                                    # Search available volume offers
vastai show volumes                                      # List your volumes
vastai create volume <offer_id> [-s SIZE] [-n NAME]      # Create volume (offer_id from search volumes)
vastai clone volume <source_id> <dest_id> [-s SIZE]      # Clone volume (dest_id from search volumes)
vastai delete volume <id>                                # Delete volume
vastai create network-volume ...                         # Create network volume
vastai list network-volume                               # List network volumes
vastai take snapshot <instance_id> --repo REPO --docker_login_user USER --docker_login_pass PASS  # Snapshot instance to volume
サーバーレスとデプロイ
vastai show endpoints                                    # List endpoint groups
vastai create endpoint --name "my-ep" ...                # Create endpoint
vastai update endpoint <id> ...                          # Update endpoint
vastai delete endpoint <id>                              # Delete endpoint
vastai get endpt-logs <id>                               # Endpoint logs

vastai show workergroups                                 # List worker groups
vastai create workergroup --name "wg" ...                # Create worker group
vastai update workergroup <id> ...                       # Update worker group
vastai update workers <id>                               # Rolling update of workers
vastai delete workergroup <id>                           # Delete worker group
vastai get wrkgrp-logs <id>                              # Worker group logs

vastai show deployments                                  # List deployments
vastai show deployment <id>                              # Deployment details
vastai show deployment-versions <id>                     # Version history
vastai delete deployment <id>                            # Delete deployment

vastai show scheduled-jobs                               # List scheduled jobs
vastai delete scheduled-job <id>                         # Delete scheduled job
テンプレート
vastai search templates "pytorch"                        # Search templates
vastai create template --name "x" --image "img"          # Create template
vastai update template <hash_id> ...                     # Update template (edits create a new version)
vastai delete template <id>                              # Delete template
アカウントと API キー
vastai set api-key <key>                                 # Save API key locally
vastai show api-key <id>                                 # Show a specific key
vastai show api-keys                                     # List all your API keys
vastai create api-key --name "ci" --permissions '{...}'  # Create restricted key
vastai delete api-key <id>                               # Delete key
vastai reset api-key                                     # Reset main key (get new from console)
vastai show user                                         # Account info, credit balance
vastai show audit-logs                                   # Account action history
vastai show connections                                  # Cloud storage connections
vastai show ipaddrs                                      # IP address history
請求
vastai show invoices-v1                                  # Charges/invoices (paginated)
vastai show invoices-v1 --charges                        # Charges only
vastai show invoices-v1 --invoices                       # Invoices only
vastai show invoices-v1 --start-date 2026-01-01 --end-date 2026-02-01
vastai show invoices-v1 --limit 50 --latest-first
vastai show deposit <id>                                 # Reserved instance deposit info
チーム
vastai create team --team-name "myteam"                  # Create team; your key stays on your personal account
vastai show members                                      # List team members
vastai invite member --email [email protected]            # Invite member
vastai remove member <id>                                # Remove member
vastai create team-role --name "viewer" ...              # Create role
vastai show team-role <id>                               # Role details
vastai show team-roles                                   # List roles
vastai update team-role <id> ...                         # Update role
vastai remove team-role <id>                             # Remove role
vastai destroy team                                      # Delete team
環境変数
vastai show env-vars                                     # List user env vars
vastai create env-var KEY val                             # Create env var
vastai update env-var KEY newval                          # Update env var
vastai delete env-var KEY                                 # Delete env var
マシン管理(ホスト)
vastai show machines                                     # List your machines
vastai list machine <id>                                 # List/unlist machine on marketplace
vastai show machine <id>                                 # Machine details
vastai cleanup machine <id>                              # Clean up machine state
vastai schedule maint <id> ...                           # Schedule maintenance window
vastai cancel maint <id>                                 # Cancel scheduled maintenance
vastai show maints                                       # List maintenance windows
vastai unlist machine <id>                               # Remove from marketplace

よくあるエラー

エラー原因対処方法
401 UnauthorizedAPI キーが無効または期限切れですvastai set api-key <new-key>
Insufficient creditsアカウント残高が不足していますhttps://cloud.vast.ai/billing/ でクレジットを追加します
No offers foundフィルターの条件が厳しすぎます条件を緩め、--no-default/-n を試します
Permission deniedSSH キーが登録されていませんcreate instance の前に vastai create ssh-key を実行します
Connection refusedインスタンスがまだ起動していませんactual_status == "running" になるまで show instance <id> を繰り返し確認します
destroy instance で停止する確認プロンプトが入力を待っています-y フラグを追加します:vastai destroy instance <id> -y

URL

コンソール
https://console.vast.ai/instances/   # Your instances
https://console.vast.ai/create/      # Search GPU offers
https://console.vast.ai/manage-keys/ # Create and manage API keys
https://cloud.vast.ai/billing/       # Billing
API
https://console.vast.ai/api/v0/instances/      # Instances endpoint
https://console.vast.ai/api/v0/asks/           # Offers search
インスタンスのポート

インスタンスで公開されているポートにアクセスします:

ssh://root@<ssh_host>:<ssh_port>               # SSH (from vastai ssh-url)

直接接続(作成時に --direct を使用した場合):インスタンス JSON の <direct_port_end> フィールド。

ドキュメント

完全なドキュメントのインデックスはこちらから取得できます:https://docs.vast.ai/llms.txt

コメント