Vast.ai
Rent a GPU on the Vast.ai marketplace (an instance or a Serverless endpoint), serve an LLM, reach it from OpenAI-compatible clients and your gateway, keep the spend and data exposure small, and destroy everything when done.
Scope: the vastai CLI, GPU offer search, instances, ports and SSH, volumes, Serverless endpoints and workergroups, the OpenAI proxy, API key permissions, billing behavior and teardown.
Out of scope: choosing between providers (cloud-llms, choosing-llm-hosting), gateway routing and keys (llm-gateway, litellm), vLLM engine tuning (vllm), GPU sizing (choosing-hardware), training recipes (fine-tuning-llms), image or video models (self-hosted-genmedia).
Work through the steps in order. Load a reference only when a step names it.
Discover first
Read-only. Print variable names, never values, and never cat key files.
command -v vastai && vastai --version
env | cut -d= -f1 | grep -E '^(VAST|HF|OPENAI|LITELLM|VLLM)_' || echo "no matching env vars"
ls -l ~/.config/vastai/vast_api_key 2>&1 # permissions only; want -rw-------
vastai show instances # running or stopped rentals, with cost
vastai show endpoints
vastai show volumes
vastai show ssh-keys
Learn what already exists and what it costs per hour before proposing anything. If vastai is missing or there is no key, go to workflow 1.
Decision flow
- Quick experiment, dev box, or one always-on model? Rent an instance (
references/instances.md). - Spiky traffic, can tolerate minutes of cold start, want an OpenAI-compatible URL? Use Serverless with the vLLM template (
references/serverless.md). - Restartable batch job? An interruptible instance, with checkpoints (
references/instances.md). - Sensitive data or strict uptime? Use Secure Cloud or verified datacenter offers, or another provider (
cloud-llms); read the security notes inreferences/limits-and-costs.md. - Clients and gateway:
references/litellm-and-clients.md. - Something broke:
references/troubleshooting.md. - Done or pausing:
references/teardown.md. Destroy; do not just stop.
Rules
- Ask before anything billable. Instances, endpoints, volumes and bids cost money. State offer id, hourly price, disk size,
max_workersand a stop time, then wait for approval. - Secrets stay secret. The Vast API key comes from a
0600file orVAST_API_KEY, never printed, committed or pasted. Prefer account env vars over-eflags forHF_TOKEN. Use a scoped key for each job or client. - Treat hosts as untrusted. Hosts can technically read files on their machines. No credentials, private datasets or unencrypted sensitive data on instances; prefer verified or Secure Cloud offers.
- Pin versions. Use
vllm/vllm-openai:<version>and pinned model revisions, neverlatest. - Budget controls before traffic. Cap
max_workers, set an inactivity timeout, keep a balance buffer, and setmax_tokensin clients. - Always destroy. A stopped instance still bills for storage and can lose its GPU. Only destroying instances and endpoints stops all billing. Finish every session with workflow 8.
- Protect ports. Mapped ports are plain HTTP; use
--api-keyand an SSH tunnel, Tailscale or a tunnel service. - Do not hardcode prices. Read them from
vastai search offers.
Workflows
1. Account and auth
- Account has credits (human step); note that Autobilling is card-only and there are no refunds.
-
pip install "vastai==1.8.3"in a venv;vastai --version. - User creates an API key, ideally scoped (
references/setup-and-auth.md), and saves it to~/.config/vastai/vast_api_keywith0600. - Register an SSH public key (
vastai create ssh-key) before renting;vastai show userworks. - Save
HF_TOKENandVLLM_API_KEYas account env vars through the console for gated models and vLLM auth.
2. Rent an instance and serve vLLM
-
vastai search offers '... verified=true direct_port_count>=1 rentable=true'; comparedph_total,inet_down,disk_space, reliability and bandwidth price. - After approval,
vastai create instance <OFFER_ID> --image vllm/vllm-openai:<ver> --disk N --ssh --direct --env '-p 8000:8000' --onstart-cmd '...'; recordnew_contract. -
vastai show instance <ID>untilrunning; find the external port (VAST_TCP_PORT_8000,portsin--raw). - Test
GET /v1/modelswith the vLLM key, preferably over an SSH tunnel.
3. Create a Serverless endpoint
- After approval, create the endpoint and workergroup with the vLLM (Serverless) template, low
max_workers, and an inactivity timeout (references/serverless.md). - Set
HF_TOKENfor gated models; wait 3 to 5 minutes for the first worker. - Test via
https://openai.vast.ai/<ENDPOINT_NAME>with a scoped key.
4. Connect to LiteLLM and clients
- Add a
model_listentry fromreferences/litellm-and-clients.md(hosted_vllm/<model>for instances,openai/<name>for the proxy), with longtimeoutand a fallback. - Keep the connection private (tunnel, Tailscale) for instances.
5. Scale
- Instances: rent more, or switch to Serverless. Serverless: tune min and max workers, target utilization and cold multiplier.
- Re-check bandwidth prices for large data movement.
6. Monitor cost
-
vastai show instances(hourly rows),vastai show user(balance), the console billing page. -
llm-observabilityfor request-level cost and latency;llm-evalsbefore swapping models or hosts.
7. Update
- Instances are disposable: create a new one with the new pinned image, test, destroy the old one.
- Serverless: update the template or workergroup, check worker logs, then retire old workers.
8. Tear down
- Follow
references/teardown.md: delete workergroups and endpoints, destroy instances, delete volumes, revoke keys. - Verify
vastai show instances,show endpointsandshow volumesare empty or as intended.
9. Troubleshoot
- Instance status and logs first, then
references/troubleshooting.md.
Reference index
| File | Load when |
|---|---|
references/setup-and-auth.md |
Account, CLI install, API key and scoped permissions, SSH keys, env vars |
references/instances.md |
Searching offers, creating instances, ports, volumes, stop vs destroy |
references/serverless.md |
Endpoints, workergroups, worker states and billing, OpenAI proxy, SDK |
references/litellm-and-clients.md |
LiteLLM entries, OpenAI SDK and curl, private access |
references/limits-and-costs.md |
Billing rules, instance types, limits, security of marketplace hosts |
references/teardown.md |
Destroying every billable resource and verifying |
references/troubleshooting.md |
Symptom to cause to fix |
Companion skills
cloud-llms:npx skills add ScaleDockHQ/llm-skills --skill cloud-llms(compare providers, hybrid setups)llm-gateway:npx skills add ScaleDockHQ/llm-skills --skill llm-gateway(one endpoint, keys, budgets)choosing-llm-hosting:npx skills add ScaleDockHQ/llm-skills --skill choosing-llm-hostingself-hosted-llms:npx skills add ScaleDockHQ/llm-skills --skill self-hosted-llmsllm-clients:npx skills add ScaleDockHQ/llm-skills --skill llm-clientsllm-observability:npx skills add ScaleDockHQ/llm-skills --skill llm-observabilityllm-evals:npx skills add ScaleDockHQ/llm-skills --skill llm-evalsfine-tuning-llms:npx skills add ScaleDockHQ/llm-skills --skill fine-tuning-llmsmodel-quantization:npx skills add ScaleDockHQ/llm-skills --skill model-quantizationvllm:npx skills add ScaleDockHQ/llm-skills --skill vllm