{
  "openapi": "3.1.0",
  "info": {
    "title": "CapVM API",
    "version": "v1",
    "summary": "Prepaid ARM and L4 GPU machines for AI agents, inside per-key spend caps.",
    "description": "Real machine provisioning is still being rolled out, so the API may return simulated machines and command output for now.\n\nAPI keys are issued by the CapVM team after signup and Terms acceptance; they aren't self-serve. Money is integer micro-USD (1 USD = 1,000,000 micro-USD). Billed per second with a 60-second minimum, capped at ttl_seconds; the clock starts at create and the full TTL is held up front. Prices in USD, excluding VAT. Errors are {\"error\":{\"code\":\"...\",\"message\":\"...\"}}.\n\nCard top-ups (POST /v1/checkout/sessions) are Coming soon; for now, CapVM adds credits to your account. OAuth for MCP clients is Coming soon. The MCP server is at https://api.capvm.com/mcp (not described here). Full docs: https://capvm.com/docs/",
    "contact": {
      "name": "CapVM (MAKERSCLUB Molina)",
      "email": "hello@capvm.com",
      "url": "https://capvm.com/"
    }
  },
  "servers": [
    {
      "url": "https://api.capvm.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "tags": [
    {
      "name": "Machines"
    },
    {
      "name": "Account"
    }
  ],
  "paths": {
    "/v1/machines": {
      "post": {
        "tags": [
          "Machines"
        ],
        "operationId": "createMachine",
        "summary": "Create a machine. Requires Idempotency-Key. Holds ceil(price_per_hour_micro x ttl_seconds / 3600).",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateMachineRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created (or the same machine replayed for the same key and body).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Machine"
                }
              }
            }
          },
          "400": {
            "description": "sku_required | unknown_sku | ttl_seconds_required | ttl_out_of_range | idempotency_key_required | idempotency_key_invalid | invalid_json",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized | invalid_api_key | key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "insufficient_credits | spend_cap_exceeded. Nothing launches.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "sku_not_allowed | account_limit_reached | terms_not_accepted | account_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "idempotency_conflict | concurrency_limit_exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "provider_error. The hold is released.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "capacity_unavailable | launches_disabled. The hold is released.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Machines"
        ],
        "operationId": "listMachines",
        "summary": "List machines for the calling API key.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MachineList"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized | invalid_api_key | key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (120 requests per 60 s per key; see Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/machines/{id}": {
      "parameters": [
        {
          "$ref": "#/components/parameters/MachineId"
        }
      ],
      "get": {
        "tags": [
          "Machines"
        ],
        "operationId": "getMachine",
        "summary": "Get one machine for the calling API key.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Machine"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized | invalid_api_key | key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (120 requests per 60 s per key; see Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Machines"
        ],
        "operationId": "deleteMachine",
        "summary": "Stop a machine, charge the billed seconds (at least 60, at most ttl_seconds) and release the rest of the hold. Already settled: returns the machine unchanged.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Machine"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized | invalid_api_key | key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (120 requests per 60 s per key; see Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/machines/{id}/exec": {
      "parameters": [
        {
          "$ref": "#/components/parameters/MachineId"
        }
      ],
      "post": {
        "tags": [
          "Machines"
        ],
        "operationId": "execCommand",
        "summary": "Run a command on the machine with bash. Not billed per call. Command text and output aren't kept.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExecRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExecResult"
                }
              }
            }
          },
          "400": {
            "description": "command_required | command_too_long | timeout_out_of_range | working_directory_invalid",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized | invalid_api_key | key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "machine_not_ready (the command didn't run; safe to retry) | machine_not_running",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "408": {
            "description": "command_timeout. The command may have run; don't blindly retry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "provider_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "internal_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (120 requests per 60 s per key; see Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getUsage",
        "summary": "This key's spend, outstanding holds, cap, and recent usage events.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Usage"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized | invalid_api_key | key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (120 requests per 60 s per key; see Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/balance": {
      "get": {
        "tags": [
          "Account"
        ],
        "operationId": "getBalance",
        "summary": "Available and held balance for the organization.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Balance"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized | invalid_api_key | key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (120 requests per 60 s per key; see Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/checkout/sessions": {
      "post": {
        "tags": [
          "Account"
        ],
        "operationId": "createCheckoutSession",
        "summary": "Coming soon. Start a card top-up: returns a Stripe Checkout link a human pays. For now, CapVM adds credits to your account.",
        "x-status": "coming-soon",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CheckoutRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created (the same session for a retry with the same key and body).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CheckoutSession"
                }
              }
            }
          },
          "400": {
            "description": "validation_error | idempotency_key_required | idempotency_key_invalid | min_topup_not_met | max_topup_exceeded | terms_acceptance_required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "unauthorized | invalid_api_key | key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "terms_not_accepted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "idempotency_conflict",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "stripe_error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "stripe_not_configured: card payments are unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ak_test_... or ak_live_...",
        "description": "Per-agent API key (ak_test_... or ak_live_...) issued by the CapVM team after signup and Terms acceptance, with a spend cap, a concurrent-machine limit and an SKU allow-list. The secret is shown once."
      }
    },
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "description": "1 to 255 characters after trimming, no control characters, sent once. Scoped to the API key. Same key and same body returns the same result; a different body returns 409 idempotency_conflict.",
        "schema": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
        }
      },
      "MachineId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        },
        "example": "m_0123456789abcdef0123456789abcdef"
      }
    },
    "schemas": {
      "CreateMachineRequest": {
        "type": "object",
        "required": [
          "sku",
          "ttl_seconds"
        ],
        "properties": {
          "sku": {
            "type": "string",
            "enum": [
              "arm-small",
              "gpu-l4"
            ],
            "description": "arm-small: 2 vCPU, 4 GiB, ARM64 Linux, $0.20/h. gpu-l4: 1x NVIDIA L4 24 GB, $2.00/h."
          },
          "ttl_seconds": {
            "type": "integer",
            "minimum": 60,
            "maximum": 7200,
            "description": "Required time limit. Max 7200 (2 hours)."
          }
        },
        "example": {
          "sku": "arm-small",
          "ttl_seconds": 900
        }
      },
      "ExecRequest": {
        "type": "object",
        "required": [
          "command"
        ],
        "properties": {
          "command": {
            "type": "string",
            "minLength": 1,
            "maxLength": 8192
          },
          "timeout_seconds": {
            "type": "integer",
            "minimum": 1,
            "maximum": 300,
            "default": 30
          },
          "working_directory": {
            "type": "string",
            "maxLength": 256,
            "description": "Absolute path; segments use only ASCII letters, digits, '.', '_' and '-'."
          }
        },
        "example": {
          "command": "uname -a",
          "timeout_seconds": 30
        }
      },
      "ExecResult": {
        "type": "object",
        "required": [
          "stdout",
          "stderr",
          "exit_code",
          "truncated"
        ],
        "properties": {
          "stdout": {
            "type": "string"
          },
          "stderr": {
            "type": "string"
          },
          "exit_code": {
            "type": "integer"
          },
          "truncated": {
            "type": "boolean",
            "description": "true if stdout or stderr was cut at 256 KiB"
          }
        }
      },
      "MachineState": {
        "type": "string",
        "enum": [
          "requested",
          "provisioning",
          "ready",
          "stopping",
          "terminated"
        ]
      },
      "Machine": {
        "type": "object",
        "required": [
          "id",
          "sku",
          "state",
          "region",
          "ttl_seconds",
          "price_per_hour_micro",
          "hold_micro",
          "created_at",
          "expires_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "m_ followed by 32 hex characters"
          },
          "sku": {
            "type": "string"
          },
          "state": {
            "$ref": "#/components/schemas/MachineState"
          },
          "instance_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "public_ip": {
            "type": [
              "string",
              "null"
            ]
          },
          "region": {
            "type": "string",
            "examples": [
              "eu-central-2"
            ]
          },
          "ttl_seconds": {
            "type": "integer"
          },
          "price_per_hour_micro": {
            "type": "integer",
            "format": "int64"
          },
          "hold_micro": {
            "type": "integer",
            "format": "int64"
          },
          "charge_micro": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "ready_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "stop_requested_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "terminated_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "MachineList": {
        "type": "object",
        "required": [
          "machines"
        ],
        "properties": {
          "machines": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Machine"
            }
          }
        }
      },
      "UsageEvent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "machine_id": {
            "type": "string"
          },
          "sku": {
            "type": "string"
          },
          "seconds": {
            "type": "integer"
          },
          "amount_micro": {
            "type": "integer",
            "format": "int64"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Usage": {
        "type": "object",
        "properties": {
          "spend_micro": {
            "type": "integer",
            "format": "int64"
          },
          "held_micro": {
            "type": "integer",
            "format": "int64"
          },
          "spend_cap_micro": {
            "type": "integer",
            "format": "int64"
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/UsageEvent"
            }
          }
        }
      },
      "Balance": {
        "type": "object",
        "properties": {
          "available_micro": {
            "type": "integer",
            "format": "int64",
            "description": "Excludes holds. Can be negative after a refund or dispute."
          },
          "held_micro": {
            "type": "integer",
            "format": "int64"
          },
          "currency": {
            "type": "string",
            "const": "USD"
          },
          "unit": {
            "type": "string",
            "const": "micro_usd"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "CheckoutRequest": {
        "type": "object",
        "required": [
          "amount_usd"
        ],
        "properties": {
          "amount_usd": {
            "oneOf": [
              {
                "type": "integer",
                "description": "Whole dollars"
              },
              {
                "type": "string",
                "pattern": "^[0-9]+(\\.[0-9]{1,2})?$"
              }
            ],
            "description": "USD, $10 to $1000. The format may change, possibly to integer cents."
          },
          "success_url": {
            "type": "string",
            "format": "uri",
            "minLength": 8,
            "maxLength": 2048
          },
          "cancel_url": {
            "type": "string",
            "format": "uri",
            "minLength": 8,
            "maxLength": 2048
          }
        },
        "example": {
          "amount_usd": "10.00"
        }
      },
      "CheckoutSession": {
        "type": "object",
        "required": [
          "id",
          "url"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Stripe Checkout page. A human pays there."
          }
        }
      }
    }
  },
  "externalDocs": {
    "url": "https://capvm.com/docs/",
    "description": "CapVM docs"
  }
}
