diff --git a/api-reference/authentication.mdx b/api-reference/authentication.mdx new file mode 100644 index 0000000..722fa71 --- /dev/null +++ b/api-reference/authentication.mdx @@ -0,0 +1,97 @@ +--- +title: "Authentication" +sidebarTitle: "Authentication" +--- + +Every request to the Vast.ai API must include an API key. This page covers how to create keys, how to include them in requests, and key lifecycle details. + +## Create an API Key + +Generate a key from the [Keys page](https://cloud.vast.ai/manage-keys/) in the web console: + +1. Click **+New**. +2. Give the key a name (optional but recommended — e.g. "CI pipeline" or "notebook"). +3. Copy the key immediately — you'll only see it once. + + +You can also create keys programmatically via the API ([Create API Key](/api-reference/accounts/create-api-key)), CLI ([`vastai create api-key`](/cli/reference/create-api-key)), or SDK ([`vast.create_api_key()`](/sdk/python/reference/create-api-key)). + + +## Use an API Key + +Include your key as a Bearer token in the `Authorization` header: + + +```bash cURL +curl -s -H "Authorization: Bearer $VAST_API_KEY" \ + "https://console.vast.ai/api/v0/users/current/" +``` + +```python Python +import os +import requests + +headers = {"Authorization": f"Bearer {os.environ['VAST_API_KEY']}"} +resp = requests.get("https://console.vast.ai/api/v0/users/current/", headers=headers) +print(resp.json()) +``` + + +A common pattern is to store your key in an environment variable: + +```bash +export VAST_API_KEY="your-api-key-here" +``` + +This keeps the key out of your code and makes it easy to rotate. + + +If you get a `401 Unauthorized` or `403 Forbidden` response, double-check your API key. The most common causes are a typo, an expired key, or a scoped key that lacks the required permission for the endpoint you're calling. + + +## Verify Your Key + +A quick way to confirm your key works is to fetch your account info: + +```bash +curl -s -H "Authorization: Bearer $VAST_API_KEY" \ + "https://console.vast.ai/api/v0/users/current/" +``` + +A successful response includes your user ID, email, balance, and SSH key: + +```json +{ + "id": 123456, + "email": "you@example.com", + "credit": 25.00, + "ssh_key": "ssh-rsa AAAAB3..." +} +``` + +## Scoped Keys and Permissions + +By default, the web console creates a **full-access** key. For CI/CD pipelines, shared tooling, or team environments, you should create **scoped keys** that restrict access to only the permissions you need. + +For example, a key that can only read and manage instances (but cannot access billing): + +```json +{ + "api": { + "misc": {}, + "user_read": {}, + "instance_read": {}, + "instance_write": {} + } +} +``` + +See the [Permissions](/api-reference/permissions) page for the full list of permission categories, endpoint mappings, constraint syntax, and advanced examples. + +## Key Expiration + +API keys do not expire by default. You can revoke a key at any time from the [Keys page](https://cloud.vast.ai/manage-keys/) or by calling the [Delete API Key](/api-reference/accounts/delete-api-key) endpoint. + + +Treat your API key like a password. Do not commit keys to version control or share them in plaintext. If a key is compromised, revoke it immediately and create a new one. + diff --git a/api-reference/introduction.mdx b/api-reference/introduction.mdx index 26c7e84..3525d7b 100644 --- a/api-reference/introduction.mdx +++ b/api-reference/introduction.mdx @@ -1,9 +1,190 @@ --- -title: "API Introduction" +title: "API Hello World" +sidebarTitle: "API Hello World" --- -**The raw REST API is intended for advanced users only.** These endpoints offer maximum flexibility but require you to manage all aspects of integration yourself. Most users will have a significantly better experience using the [CLI](/cli/get-started) or the [Python SDK](/sdk/python/quickstart), which handle these details for you. **If you are not sure whether you need direct API access, you almost certainly don't** — start with the CLI or SDK instead. + The raw REST API is intended for advanced users only. These endpoints offer maximum flexibility but require you to manage all aspects of integration yourself. Most users will have a significantly better experience using the [CLI](/cli/hello-world) or the [Python SDK](/sdk/python/quickstart), which handle these details for you. If you are not sure whether you need direct API access, you almost certainly don't — start with the CLI or SDK instead. -Welcome to Vast.ai's API documentation. Our API allows you to programmatically manage GPU instances, handle machine operations, and automate your AI/ML workflow. Whether you're running individual GPU instances or managing a fleet of machines, our API provides comprehensive control over all Vast.ai platform features. \ No newline at end of file +The Vast.ai REST API gives you programmatic control over GPU instances — useful for automation, CI/CD pipelines, or building your own tooling on top of Vast. + +This guide walks through the complete instance lifecycle: authenticate, search for a GPU, rent it, wait for it to boot, connect to it, and clean up. By the end you'll understand the core API calls needed to manage instances without touching the web console. + +## Prerequisites + +- A Vast.ai account with credit (~$0.01–0.05, depending on test instance run time) +- `curl` installed + +## 1. Get Your API Key + +Generate an API key from the [Keys page](https://cloud.vast.ai/manage-keys/) by clicking **+New**. Copy the key — you'll need it for your API calls, and you'll only see it once. + +Export it as an environment variable: + +```bash +export VAST_API_KEY="your-api-key-here" +``` + +## 2. Verify Authentication + +Confirm your key works by listing your current instances. If you have none, this returns an empty list. + +```bash +curl -s -H "Authorization: Bearer $VAST_API_KEY" \ + "https://console.vast.ai/api/v0/instances/" +``` + +```json +{ + "instances_found": 0, + "instances": [] +} +``` + + +If you get a `401` or `403`, double-check your API key. If you already have instances, you'll see them listed here. + + +## 3. Search for GPUs + +Find available machines using the bundles endpoint. This query returns the top 5 on-demand RTX 4090s sorted by deep learning performance benchmarked per dollar: + +```bash +curl -s -H "Authorization: Bearer $VAST_API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "verified": {"eq": true}, + "rentable": {"eq": true}, + "gpu_name": {"eq": "RTX 4090"}, + "num_gpus": {"eq": 1}, + "direct_port_count": {"gte": 1}, + "order": [["dlperf_per_dphtotal", "desc"]], + "type": "on-demand", + "limit": 5 + }' \ + "https://console.vast.ai/api/v0/bundles/" +``` + +Each parameter in the query above controls a different filter: + +| Parameter | Value | Meaning | +|-----------|-------|---------| +| `verified` | `{"eq": true}` | Only machines verified by Vast.ai (identity-checked hosts) | +| `rentable` | `{"eq": true}` | Only machines currently available to rent | +| `gpu_name` | `{"eq": "RTX 4090"}` | Filter to a specific GPU model | +| `num_gpus` | `{"eq": 1}` | Exactly 1 GPU per instance | +| `direct_port_count` | `{"gte": 1}` | At least 1 directly accessible port (needed for SSH) | +| `order` | `[["dlperf_per_dphtotal", "desc"]]` | Sort by deep learning performance per dollar, best value first | +| `type` | `"on-demand"` | On-demand pricing (vs. interruptible spot/bid) | +| `limit` | `5` | Return at most 5 results | + +The response contains an `offers` array. Note the `id` of the offer you want — you'll use it in the next step. If no offers are returned, try relaxing your filters (e.g. a different GPU model or removing `direct_port_count`). + + +See the [Search Offers](/api-reference/search/search-offers) reference for the full list of filter parameters and operators. + + +## 4. Create an Instance + +Rent the machine by sending a PUT request with your Docker image and disk size. Replace `OFFER_ID` with the `id` from step 3. `disk` is in GB and specifies the size of the disk on your new instance. + +```bash +curl -s -H "Authorization: Bearer $VAST_API_KEY" \ + -H "Content-Type: application/json" \ + -X PUT \ + -d '{ + "image": "pytorch/pytorch:2.4.0-cuda12.4-cudnn9-runtime", + "disk": 20, + "onstart": "echo hello && nvidia-smi" + }' \ + "https://console.vast.ai/api/v0/asks/OFFER_ID/" +``` + +```json +{ + "success": true, + "new_contract": 12345678, + "instance_api_key": "d15a..." +} +``` + +Save the `new_contract` value — this is your instance ID. The `instance_api_key` is a restricted key injected into the container as `CONTAINER_API_KEY` — it can only start, stop, or destroy that specific instance. + +## 5. Wait Until Ready + +The instance needs time to pull the Docker image and boot. Poll the status endpoint until `actual_status` is `"running"`. Replace `INSTANCE_ID` with the `new_contract` value from step 4. + +```bash +curl -s -H "Authorization: Bearer $VAST_API_KEY" \ + "https://console.vast.ai/api/v0/instances/INSTANCE_ID/" +``` + +Example response: + +```json +{ + "instances": { + "actual_status": "loading", + "ssh_host": "...", + "ssh_port": 12345 + } +} +``` + +The `actual_status` field progresses through these states: + +| `actual_status` | Meaning | +|-----------------|---------| +| `null` | Instance is being provisioned | +| `"loading"` | Docker image is downloading | +| `"running"` | Ready to use | + +Poll every 10 seconds. Boot time is typically 1–5 minutes depending on the Docker image size. You can also use the `onstart` script to send a callback when the instance is ready, instead of polling. + + +Always handle non-happy-path statuses in your poll loop. If `actual_status` becomes `"exited"` (container crashed), `"unknown"` (no heartbeat from host), or `"offline"` (host disconnected), it will never reach `"running"`. Without a timeout or error check, your script will loop forever while the instance continues accruing disk charges. Destroy the instance and retry with a different offer if you see these states. + + +Once `actual_status` is `"running"`, you're ready to connect. + +## 6. Connect via SSH + +Use the `ssh_host` and `ssh_port` from the status response to connect directly to your new instance: + +```bash +ssh root@SSH_HOST -p SSH_PORT +``` + +## 7. Clean Up + +When you're done, destroy the instance to stop all billing. + +Alternatively, to pause an instance temporarily instead of destroying it, you can **stop** it. Stopping halts compute billing but disk storage charges continue. + +**Destroy** (removes everything): + +```bash +curl -s -H "Authorization: Bearer $VAST_API_KEY" \ + -X DELETE \ + "https://console.vast.ai/api/v0/instances/INSTANCE_ID/" +``` + +**Stop** (pauses compute, disk charges continue): + +```bash +curl -s -H "Authorization: Bearer $VAST_API_KEY" \ + -H "Content-Type: application/json" \ + -X PUT \ + -d '{"state": "stopped"}' \ + "https://console.vast.ai/api/v0/instances/INSTANCE_ID/" +``` + +Both return `{"success": true}`. + +## Next Steps + +You've now completed the full instance lifecycle through the API: authentication, search, creation, polling, and teardown. From here: + +- **SSH setup** — See the [SSH guide](/documentation/instances/connect/ssh) for key configuration and advanced connection options. +- **Use templates** — Avoid repeating image and config parameters on every create call. The [Templates API guide](/api-reference/creating-and-using-templates-with-api) covers creating, sharing, and launching from templates. diff --git a/api-reference/openapi.json b/api-reference/openapi.json index 5ccc126..3917e5d 100644 --- a/api-reference/openapi.json +++ b/api-reference/openapi.json @@ -21,119 +21,6 @@ } ], "paths": { - "/api/v0/network_disk/": { - "post": { - "summary": "add network-disk", - "description": "Adds a network disk to be used to create network volume offers, or adds machines to an existing network disk.\n\nCLI Usage: `vastai add network_disk ... [options]`", - "security": [ - { - "BearerAuth": [] - } - ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "mount_point" - ], - "properties": { - "machine_id": { - "type": "integer", - "description": "ID of the machine to add network disk to" - }, - "machine_ids": { - "type": "array", - "items": { - "type": "integer" - }, - "description": "IDs of machines to add network disk to" - }, - "mount_point": { - "type": "string", - "description": "Path to mount point of networked storage on machine or machines" - }, - "disk_id": { - "type": "integer", - "description": "ID of network disk, if adding machines to existing disk" - } - } - } - } - } - }, - "responses": { - "200": { - "description": "Successful response", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "success": { - "type": "boolean" - }, - "disk_id": { - "type": "integer", - "description": "ID of disk created or added to machines" - } - }, - "example": { - "success": true, - "disk_id": 2 - } - } - } - } - }, - "400": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "error": { - "type": "string", - "example": "invalid_args" - }, - "msg": { - "type": "string", - "example": "Invalid machine id" - } - } - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "error": { - "type": "string", - "example": "not_authorized" - }, - "msg": { - "type": "string", - "example": "Only machine owner can add network disk" - } - } - } - } - } - } - }, - "tags": [ - "Network Volumes" - ] - } - }, "/api/v0/instances/{id}/ssh/": { "post": { "summary": "attach ssh-key", @@ -2591,247 +2478,20 @@ "429": { "description": "Too Many Requests", "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "detail": { - "type": "string", - "example": "API requests too frequent endpoint threshold=4.5" - } - } - } - } - } - } - } - } - }, - "/api/v0/network_volume/": { - "put": { - "summary": "create network-volume", - "description": "Creates a network volume from an offer.\n\nCLI Usage: `vastai create network-volume [--name ]`", - "security": [ - { - "BearerAuth": [] - } - ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "id", - "size" - ], - "properties": { - "id": { - "type": "integer", - "description": "ID of network volume ask being accepted" - }, - "size": { - "type": "integer", - "description": "size of network volume in GB being created" - }, - "name": { - "type": "string", - "description": "optional name for network volume being created" - } - } - } - } - } - }, - "responses": { - "200": { - "description": "Successful response", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "success": { - "type": "boolean" - }, - "volume_name": { - "type": "string", - "description": "name of network volume created" - }, - "volume_size": { - "type": "integer", - "description": "size of network volume created" - } - }, - "example": { - "success": true, - "id": 6, - "msg": "Deleted network volume listing" - } - } - } - } - }, - "400": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "error": { - "type": "string", - "example": "invalid_args" - }, - "msg": { - "type": "string", - "example": "You must pass in `id` in the body of the request" - } - } - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "error": { - "type": "string", - "example": "not_authorized" - }, - "msg": { - "type": "string", - "example": "Authorization Error. Check that you have proper privileges to perform this action." - } - } - } - } - } - } - }, - "tags": [ - "Network Volumes" - ] - }, - "post": { - "summary": "list network-volume", - "description": "Lists a network disk for rent as network volumes, or updates an existing listing with a new price/size/end date/discount.\n\nCLI Usage: `vastai list network-volume [options]`", - "security": [ - { - "BearerAuth": [] - } - ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "disk_id" - ], - "properties": { - "price_disk": { - "type": "number", - "format": "float", - "description": "Price per GB of network volume storage" - }, - "disk_id": { - "type": "integer", - "description": "ID of network disk for which offer is being created" - }, - "size": { - "type": "integer", - "description": "Size in GB of the amount of space available to be rented" - }, - "credit_discount_max": { - "type": "number", - "format": "float", - "description": "Maximum discount rate allowed for prepaid credits" - }, - "end_date": { - "type": "number", - "format": "float", - "description": "Unix timestamp for when the listing expires" - } - } - } - } - } - }, - "responses": { - "200": { - "description": "Successful response", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "success": { - "type": "boolean" - }, - "msg": { - "type": "string", - "description": "status message" - } - }, - "example": { - "success": true, - "disk_id": "created network volume ask with id 6 and size 24" - } - } - } - } - }, - "400": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "error": { - "type": "string", - "example": "invalid_args" - }, - "msg": { - "type": "string", - "example": "Invalid disk_id" - } - } - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "error": { - "type": "string", - "example": "not_authorized" - }, - "msg": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "detail": { "type": "string", - "example": "Could not find network disk with id 6 associated with user" + "example": "API requests too frequent endpoint threshold=4.5" } } } } } } - }, - "tags": [ - "Network Volumes" - ] + } } }, "/api/v0/ssh/": { @@ -7949,228 +7609,6 @@ ] } }, - "/api/v0/network_volumes/search/": { - "post": { - "summary": "search network volumes", - "description": "Search for available network volume offers with advanced filtering and sorting.\n\nCLI Usage: `vastai search network-volumes [--order ]`", - "security": [ - { - "BearerAuth": [] - } - ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "q": { - "type": "object", - "properties": { - "verified": { - "type": "object", - "description": "Display offers where all machines in cluster are verified", - "example": { - "eq": true - } - }, - "order": { - "type": "array", - "items": { - "type": "array", - "items": { - "type": "string" - } - }, - "description": "Sort fields and directions", - "example": [ - [ - "storage_cost", - "asc" - ] - ] - }, - "limit": { - "type": "integer", - "description": "Max results to return" - }, - "reliability2": { - "type": "object", - "description": "Cluster reliability score (0-1)", - "example": { - "gt": 0.98 - } - }, - "inet_down": { - "type": "object", - "description": "Download bandwidth (MB/s)", - "example": { - "gt": 100.0 - } - }, - "inet_up": { - "type": "object", - "description": "Upload bandwidth (MB/s)", - "example": { - "gt": 100.0 - } - }, - "geolocation": { - "type": "object", - "description": "Cluster location (two letter country code)", - "example": { - "in": [ - "TW", - "SE" - ] - } - }, - "disk_bw": { - "type": "object", - "description": "Disk read bandwidth in MB/s", - "example": { - "gt": 500 - } - }, - "duration": { - "type": "object", - "description": "Maximum rental duration in days", - "example": { - "gte": 30 - } - }, - "storage_cost": { - "type": "object", - "description": "Storage cost in $/GB/month", - "example": { - "lte": 0.1 - } - } - } - } - } - } - } - } - }, - "responses": { - "200": { - "description": "Successful search response", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "success": { - "type": "boolean", - "example": true - }, - "offers": { - "type": "array", - "items": { - "type": "object", - "properties": { - "ask_contract_id": { - "type": "integer", - "description": "Unique offer ID" - }, - "disk_space": { - "type": "number", - "description": "Storage space in GB" - }, - "inet_up": { - "type": "number", - "description": "Upload bandwidth (MB/s)" - }, - "inet_down": { - "type": "number", - "description": "Download bandwidth (MB/s)" - }, - "reliability2": { - "type": "number", - "description": "Cluster reliability score (0-1)" - }, - "verified": { - "type": "boolean", - "description": "Cluster verification status" - }, - "geolocation": { - "type": "string", - "description": "Geographic location" - }, - "nw_disk_avg_bw": { - "type": "integer", - "description": "Average read bw of network disk from machines in cluster" - }, - "nw_disk_max_bw": { - "type": "integer", - "description": "Max read bw of network disk from machines in cluster" - }, - "nw_disk_min_bw": { - "type": "integer", - "description": "Min read bw of network disk from machines in cluster" - }, - "start_date": { - "type": "number", - "description": "start date of offer, in epoch time" - }, - "end_date": { - "type": "number", - "description": "end date of offer, in epoch time" - }, - "storage_cost": { - "type": "number", - "description": "storage cost in $/GB/month" - }, - "storage_cost_total": { - "type": "number", - "description": "total storage cost per hour for rented space" - } - } - } - } - } - } - } - } - }, - "400": { - "description": "Bad request - invalid query parameters", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "401": { - "description": "Unauthorized - invalid or missing API key", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - }, - "429": { - "description": "Too many requests", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/Error" - } - } - } - } - }, - "tags": [ - "Network Volumes" - ] - } - }, "/api/v0/bundles/": { "post": { "summary": "search offers", @@ -9511,18 +8949,47 @@ "actual_status": { "type": "string", "nullable": true, + "enum": [ + "loading", + "running", + "stopped", + "frozen", + "exited", + "rebooting", + "unknown", + "offline" + ], + "description": "Current status of the instance container. `null` while provisioning.\n\n- `loading` \u2014 Docker image downloading or container starting up.\n- `running` \u2014 Container executing. GPU charges apply.\n- `stopped` \u2014 Container halted. Disk charges continue; no GPU charges.\n- `frozen` \u2014 Container paused with memory preserved. GPU charges apply.\n- `exited` \u2014 Container process exited unexpectedly.\n- `rebooting` \u2014 Container restarting (transient).\n- `unknown` \u2014 No recent heartbeat from the host.\n- `offline` \u2014 Host machine disconnected from Vast servers (computed, not stored).\n", "example": "running" }, "cur_state": { "type": "string", + "enum": [ + "running", + "stopped", + "unloaded" + ], + "description": "Current state of the machine contract (hardware allocation).\n\n- `running` \u2014 Allocation active.\n- `stopped` \u2014 Allocation paused.\n- `unloaded` \u2014 Allocation released (instance destroyed).\n", "example": "running" }, "next_state": { "type": "string", + "enum": [ + "running", + "stopped", + "unloaded" + ], + "description": "Target state for the machine contract. The daemon transitions `cur_state` toward this value.\n\n- `running` \u2014 Should be active.\n- `stopped` \u2014 Should be paused.\n- `unloaded` \u2014 Should be released.\n", "example": "running" }, "intended_status": { "type": "string", + "enum": [ + "running", + "stopped", + "frozen" + ], + "description": "User's desired target state for the container.\n\n- `running` \u2014 Should be executing.\n- `stopped` \u2014 Should be halted.\n- `frozen` \u2014 Should be paused with memory preserved.\n", "example": "running" }, "label": { @@ -10023,7 +9490,7 @@ "/api/v1/instances/": { "get": { "summary": "show instances (v1)", - "description": "Retrieve a paginated list of instances for the authenticated user.\nSupports keyset pagination (max 25 per page), filtering, column selection, and sorting.\n\nCLI Usage: `vastai show instances-v1 [OPTIONS] [--api-key API_KEY] [--raw]`", + "description": "Retrieve a paginated list of instances for the authenticated user.\nSupports keyset pagination (max 25 per page), filtering, column selection, and sorting.\n\nCLI Usage: `vastai show instances [OPTIONS] [--api-key API_KEY] [--raw]`", "security": [ { "BearerAuth": [] @@ -10134,18 +9601,47 @@ "actual_status": { "type": "string", "nullable": true, + "enum": [ + "loading", + "running", + "stopped", + "frozen", + "exited", + "rebooting", + "unknown", + "offline" + ], + "description": "Current status of the instance container. `null` while provisioning.\n\n- `loading` \u2014 Docker image downloading or container starting up.\n- `running` \u2014 Container executing. GPU charges apply.\n- `stopped` \u2014 Container halted. Disk charges continue; no GPU charges.\n- `frozen` \u2014 Container paused with memory preserved. GPU charges apply.\n- `exited` \u2014 Container process exited unexpectedly.\n- `rebooting` \u2014 Container restarting (transient).\n- `unknown` \u2014 No recent heartbeat from the host.\n- `offline` \u2014 Host machine disconnected from Vast servers (computed, not stored).\n", "example": "running" }, "cur_state": { "type": "string", + "enum": [ + "running", + "stopped", + "unloaded" + ], + "description": "Current state of the machine contract (hardware allocation).\n\n- `running` \u2014 Allocation active.\n- `stopped` \u2014 Allocation paused.\n- `unloaded` \u2014 Allocation released (instance destroyed).\n", "example": "running" }, "next_state": { "type": "string", + "enum": [ + "running", + "stopped", + "unloaded" + ], + "description": "Target state for the machine contract. The daemon transitions `cur_state` toward this value.\n\n- `running` \u2014 Should be active.\n- `stopped` \u2014 Should be paused.\n- `unloaded` \u2014 Should be released.\n", "example": "running" }, "intended_status": { "type": "string", + "enum": [ + "running", + "stopped", + "frozen" + ], + "description": "User's desired target state for the container.\n\n- `running` \u2014 Should be executing.\n- `stopped` \u2014 Should be halted.\n- `frozen` \u2014 Should be paused with memory preserved.\n", "example": "running" }, "label": { @@ -11719,109 +11215,6 @@ ] } }, - "/api/v0/network_volumes/unlist/": { - "post": { - "summary": "unlist network-volume", - "description": "Unlists a network volume for rent.\n\nCLI Usage: `vastai unlist volume `", - "security": [ - { - "BearerAuth": [] - } - ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "id" - ], - "properties": { - "id": { - "type": "integer", - "description": "ID of network volume ask being unlisted" - } - } - } - } - } - }, - "responses": { - "200": { - "description": "Successful response", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "success": { - "type": "boolean" - }, - "id": { - "type": "integer", - "description": "id of unlisted network volume ask" - }, - "msg": { - "type": "string", - "description": "status message" - } - }, - "example": { - "success": true, - "id": 6, - "msg": "Deleted network volume listing" - } - } - } - } - }, - "400": { - "description": "Bad Request", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "error": { - "type": "string", - "example": "invalid_args" - }, - "msg": { - "type": "string", - "example": "You must pass in `id` in the body of the request" - } - } - } - } - } - }, - "403": { - "description": "Forbidden", - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "error": { - "type": "string", - "example": "not_authorized" - }, - "msg": { - "type": "string", - "example": "Authorization Error. Check that you have proper privileges to perform this action." - } - } - } - } - } - } - }, - "tags": [ - "Network Volumes" - ] - } - }, "/api/v0/volumes/unlist/": { "post": { "summary": "unlist volume", @@ -12142,22 +11535,47 @@ "actual_status": { "type": "string", "nullable": true, - "description": "Current status of the instance container.", + "enum": [ + "loading", + "running", + "stopped", + "frozen", + "exited", + "rebooting", + "unknown", + "offline" + ], + "description": "Current status of the instance container. `null` while the instance is still being provisioned.\n\n- `loading` \u2014 Docker image is downloading or the container is starting up.\n- `running` \u2014 Container is actively executing. GPU charges apply.\n- `stopped` \u2014 Container is halted. Disk charges continue; no GPU charges.\n- `frozen` \u2014 Container is paused with memory preserved. GPU charges apply.\n- `exited` \u2014 Container process exited unexpectedly.\n- `rebooting` \u2014 Container is restarting (transient).\n- `unknown` \u2014 Status cannot be determined; no recent heartbeat from the host.\n- `offline` \u2014 Machine hosting this instance has disconnected from Vast servers. Computed at query time; the underlying `actual_status` value in the database is preserved.\n", "example": "running" }, "intended_status": { "type": "string", - "description": "Intended status of the instance container.", + "enum": [ + "running", + "stopped", + "frozen" + ], + "description": "The user's desired target state for the container. The system continuously works to reconcile `actual_status` with this value.\n\n- `running` \u2014 Container should be executing.\n- `stopped` \u2014 Container should be halted.\n- `frozen` \u2014 Container should be paused with memory preserved.\n", "example": "running" }, "cur_state": { "type": "string", - "description": "Current state of the machine contract.", + "enum": [ + "running", + "stopped", + "unloaded" + ], + "description": "Current state of the machine contract (the hardware allocation for this instance).\n\n- `running` \u2014 Allocation is active; hardware is in use.\n- `stopped` \u2014 Allocation is paused.\n- `unloaded` \u2014 Allocation has been released (instance is destroyed).\n", "example": "running" }, "next_state": { "type": "string", - "description": "Next scheduled state for the machine contract.", + "enum": [ + "running", + "stopped", + "unloaded" + ], + "description": "Target state for the machine contract. The daemon transitions `cur_state` toward this value.\n\n- `running` \u2014 Allocation should be active.\n- `stopped` \u2014 Allocation should be paused.\n- `unloaded` \u2014 Allocation should be released (set when destroying an instance).\n", "example": "running" }, "label": { @@ -12765,4 +12183,4 @@ } } } -} \ No newline at end of file +} diff --git a/api-reference/permissions.mdx b/api-reference/permissions.mdx new file mode 100644 index 0000000..1c08e4b --- /dev/null +++ b/api-reference/permissions.mdx @@ -0,0 +1,238 @@ +--- +title: "Permissions" +sidebarTitle: "Permissions" +--- + +Every API key has a set of permissions that control which endpoints it can access. This page is the comprehensive reference for permission categories, how they map to API routes, and how to build custom scoped keys. + +For an overview of API key creation and usage, see [Authentication](/api-reference/authentication). + +## Permission Categories + +Permissions are organized into categories. When you create a scoped API key, you include only the categories the key needs. The available categories are: + +| Category | Controls | +|----------|----------| +| `instance_read` | Viewing instances, logs, SSH keys, volumes, deposits | +| `instance_write` | Creating, managing, and destroying instances and volumes | +| `user_read` | Viewing account info, API keys, SSH keys, environment variables, templates | +| `user_write` | Creating/modifying API keys, SSH keys, environment variables, templates, teams | +| `billing_read` | Viewing invoices and earnings | +| `billing_write` | Transferring credit | +| `machine_read` | Viewing machines and reports (hosts) | +| `machine_write` | Managing machines, maintenance, listing/unlisting (hosts) | +| `misc` | Search offers, benchmarks, network volumes, serverless endpoints | +| `team_read` | Viewing team members and roles | +| `team_write` | Inviting/removing team members, managing roles | + +## Creating Scoped Keys + +Define permissions as a JSON object and pass it when creating a key. The top-level key is always `"api"`, containing the categories you want to grant. + +**Example — Instance management with billing access:** + +```json +{ + "api": { + "misc": {}, + "user_read": {}, + "instance_read": {}, + "instance_write": {}, + "billing_read": {}, + "billing_write": {} + } +} +``` + +**Example — Instance management without billing:** + +```json +{ + "api": { + "misc": {}, + "user_read": {}, + "instance_read": {}, + "instance_write": {} + } +} +``` + +You can create scoped keys using: +- **API**: [Create API Key](/api-reference/accounts/create-api-key) +- **CLI**: [`vastai create api-key`](/cli/reference/create-api-key) +- **SDK**: [`vast.create_api_key()`](/sdk/python/reference/create-api-key) + +## Custom Roles + +Custom roles let you assign the same set of permissions to multiple team members. + +- **Creating roles**: Use the CLI or the Manage page in the web console (requires `team_write` access). +- **Defining permissions**: Select from any combination of the categories listed above. +- **Assigning roles**: Assign created roles to team members through the team management interface or CLI. + +## Constraints + +Constraints narrow a permission category to specific parameter values. This lets you create keys that can only operate on certain resources. + +**Example — Read logs for a single instance only:** + +```json +{ + "api": { + "instance_read": { + "api.instance.request_logs": { + "constraints": { + "id": { + "eq": 1227 + } + } + } + } + } +} +``` + +**Example — Read logs for a range of instance IDs:** + +```json +{ + "api": { + "instance_read": { + "api.instance.request_logs": { + "constraints": { + "id": { + "lte": 2, + "gte": 1 + } + } + } + } + } +} +``` + +Supported constraint operators: `eq`, `lte`, `gte`. + + +API keys using constraints must be created via the CLI ([`vastai create api-key`](/cli/reference/create-api-key)) or the API ([Create API Key](/api-reference/accounts/create-api-key)). + + +You can also use **wildcards** in `params` to represent placeholder values — useful when generating many keys that perform similar operations. + +## Endpoint Reference by Category + +Below is the complete mapping of which endpoints each permission category controls. + +### instance\_read + +- [Show Instance](/api-reference/instances/show-instance) +- [Show Instances](/api-reference/instances/show-instances) +- [Show Logs](/api-reference/instances/show-logs) +- [Show SSH Keys](/api-reference/instances/show-ssh-keys) +- [Show Volumes](/api-reference/volumes/list-volumes) +- [Show Deposit](/api-reference/billing/show-deposit) + +### instance\_write + +- [Attach SSH Key](/api-reference/instances/attach-ssh-key) +- [Copy](/api-reference/instances/copy) +- [Cancel Copy](/api-reference/instances/cancel-copy) +- [Cloud Copy](/api-reference/instances/cloud-copy) +- [Cancel Sync](/api-reference/instances/cancel-sync) +- [Change Bid](/api-reference/instances/change-bid) +- [Create Instance](/api-reference/instances/create-instance) +- [Manage Instance](/api-reference/instances/manage-instance) +- [Delete Instance](/api-reference/instances/destroy-instance) +- [Detach SSH Key](/api-reference/instances/detach-ssh-key) +- [Execute](/api-reference/instances/execute) +- [Prepay Instance](/api-reference/instances/prepay-instance) +- [Reboot Instance](/api-reference/instances/reboot-instance) +- [Recycle Instance](/api-reference/instances/recycle-instance) +- [Create Volume](/api-reference/volumes/rent-volume) +- [Delete Volume](/api-reference/volumes/delete-volume) + +### user\_read + +- [Show API Keys](/api-reference/accounts/show-api-keys) +- [Show Connections](/api-reference/accounts/show-connections) +- [Show Environment Variables](/api-reference/accounts/show-env-vars) +- [Show IP Addresses](/api-reference/accounts/show-ipaddrs) +- [Show SSH Keys](/api-reference/accounts/show-ssh-keys) +- [Show Subaccounts](/api-reference/accounts/show-subaccounts) +- [Show User](/api-reference/accounts/show-user) +- [Search Templates](/api-reference/search/search-template) + +### user\_write + +- [Create API Key](/api-reference/accounts/create-api-key) +- [Delete API Key](/api-reference/accounts/delete-api-key) +- [Create Environment Variable](/api-reference/accounts/create-env-var) +- [Update Environment Variable](/api-reference/accounts/update-env-var) +- [Delete Environment Variable](/api-reference/accounts/delete-env-var) +- [Create SSH Key](/api-reference/accounts/create-ssh-key) +- [Update SSH Key](/api-reference/accounts/update-ssh-key) +- [Delete SSH Key](/api-reference/accounts/delete-ssh-key) +- [Create Subaccount](/api-reference/accounts/create-subaccount) +- [Set User](/api-reference/accounts/set-user) +- [Create Team](/api-reference/team/create-team) +- [Delete Team](/api-reference/team/destroy-team) +- [Create Template](/api-reference/templates/create-template) +- [Edit Template](/api-reference/templates/edit-template) +- [Delete Template](/api-reference/templates/delete-template) + +### billing\_read + +- [Search Invoices](/api-reference/billing/search-invoices) +- [Show Invoices](/api-reference/billing/show-invoices) +- [Show Earnings](/api-reference/billing/show-earnings) + +### billing\_write + +- [Transfer Credit](/api-reference/accounts/transfer-credit) + +### machine\_read + +- [Show Machines](/api-reference/machines/show-machines) +- [Show Reports](/api-reference/machines/show-reports) + +### machine\_write + +- [Cancel Maintenance](/api-reference/machines/cancel-maint) +- [Cleanup Machine](/api-reference/machines/cleanup-machine) +- [List Machine](/api-reference/machines/list-machine) +- [Remove Default Job](/api-reference/machines/remove-defjob) +- [Schedule Maintenance](/api-reference/machines/schedule-maint) +- [Set Default Job](/api-reference/machines/set-defjob) +- [Set Minimum Bid](/api-reference/machines/set-min-bid) +- [Unlist Machine](/api-reference/machines/unlist-machine) +- [Add Network Disk](/api-reference/network-volumes/add-network-disk) +- [Unlist Network Volume](/api-reference/network-volumes/unlist-network-volume) +- [Unlist Volume](/api-reference/volumes/unlist-volume) + +### misc + +- [Search Network Volumes](/api-reference/network-volumes/search-network-volumes) +- [Show Workergroups](/api-reference/serverless/show-workergroup) +- [Create Workergroup](/api-reference/serverless/create-workergroup) +- [Update Workergroup](/api-reference/serverless/update-workergroup) +- [Delete Workergroup](/api-reference/serverless/delete-workergroup) +- [Show Endpoints](/api-reference/serverless/show-endpoints) +- [Create Endpoint](/api-reference/serverless/create-endpoint) +- [Delete Endpoint](/api-reference/serverless/delete-endpoint) +- [Search Benchmarks](/api-reference/search/search-benchmarks) +- [Search Offers](/api-reference/search/search-offers) +- [Search Volumes](/api-reference/volumes/search-volumes) + +### team\_read + +- [Show Team Members](/api-reference/team/show-team-members) +- [Show Team Role](/api-reference/team/show-team-role) +- [Show Team Roles](/api-reference/team/show-team-roles) + +### team\_write + +- [Invite Team Member](/api-reference/team/invite-team-member) +- [Remove Team Member](/api-reference/team/remove-team-member) +- [Create Team Role](/api-reference/team/create-team-role) +- [Update Team Role](/api-reference/team/update-team-role) +- [Remove Team Role](/api-reference/team/remove-team-role) diff --git a/cli/authentication.mdx b/cli/authentication.mdx new file mode 100644 index 0000000..42c80be --- /dev/null +++ b/cli/authentication.mdx @@ -0,0 +1,103 @@ +--- +title: "CLI Authentication" +sidebarTitle: "Authentication" +--- + +Every request to the Vast.ai API requires an API key. The CLI stores your key locally and includes it automatically in every command. This page covers how to set up, verify, and manage API keys through the CLI. + +## Set Your API Key + +After creating a key from the [Keys page](https://cloud.vast.ai/manage-keys/), store it locally: + +```bash +vastai set api-key YOUR_API_KEY +``` + +This writes the key to `~/.config/vastai/vast_api_key` (or `$XDG_CONFIG_HOME/vastai/vast_api_key` if that env var is set). All subsequent commands use it automatically. + +## Environment Variable (CI/CD) + +Instead of storing the key in a file, you can set it as an environment variable: + +```bash +export VAST_API_KEY="your_api_key_here" +``` + +This is recommended for CI pipelines, Docker containers, and scripts — it avoids writing keys to +disk and makes it easy to inject secrets via your platform's secret manager. The environment +variable takes precedence over the file if both are set. + + +If you previously used an older version of the CLI, your key may be at the legacy location +`~/.vast_api_key`. The CLI migrates it automatically to `~/.config/vastai/vast_api_key` on next +run, so no manual action is needed. + + +## Verify Your Key + +Confirm your key works by fetching your account info: + +```bash +vastai show user +``` + +A successful response includes your user ID, email, and balance: + +```json +{ + "id": 123456, + "email": "you@example.com", + "credit": 25.00, + "ssh_key": "ssh-rsa AAAAB3..." +} +``` + + +If you get an authentication error, double-check your API key. The most common causes are a typo, an expired key, or a scoped key that lacks the required permission for the command you're running. + + +## Create an API Key + +You can create new keys from the CLI: + +```bash +vastai create api-key --name "ci-deploy-key" +``` + +The output includes the new key value. Copy it immediately -- you will not be able to retrieve it again. + +To create a key with restricted permissions, pass a JSON permissions file: + +```bash +vastai create api-key --name "ci-deploy-key" --permission_file perms.json +``` + +See the [Permissions](/cli/permissions) page for the full permissions file format and examples. + +## View and Delete Keys + +List all API keys on your account: + +```bash +vastai show api-keys +``` + +View a specific key's details by ID: + +```bash +vastai show api-key 42 +``` + +Delete a key: + +```bash +vastai delete api-key 42 +``` + +## Key Expiration + +API keys do not expire by default. You can revoke a key at any time from the [Keys page](https://cloud.vast.ai/manage-keys/) or with `vastai delete api-key`. + + +Treat your API key like a password. Do not commit keys to version control or share them in plaintext. If a key is compromised, revoke it immediately and create a new one. + diff --git a/cli/commands.mdx b/cli/commands.mdx deleted file mode 100644 index 473d831..0000000 --- a/cli/commands.mdx +++ /dev/null @@ -1,2097 +0,0 @@ ---- -title: Commands -createdAt: Mon Jan 13 2025 21:20:40 GMT+0000 (Coordinated Universal Time) -updatedAt: Sat Jul 12 2025 01:09:10 GMT+0000 (Coordinated Universal Time) ---- - -