{
  "openapi": "3.1.0",
  "info": {
    "title": "ComputeGpu API",
    "version": "1.2.3",
    "description": "Cloud GPU rental API. 47 models, per-second billing, Ollama/Docker/SSH."
  },
  "servers": [{ "url": "https://computegpu.com" }],
  "security": [{ "bearerAuth": [] }],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "GPU API key. Get one via POST /api/signup."
      }
    }
  },
  "paths": {
    "/api/signup": {
      "post": {
        "operationId": "agentSignup",
        "summary": "Create account and get API key instantly",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "tenantId"],
                "properties": {
                  "email": { "type": "string", "description": "Real email of the account owner" },
                  "tenantId": { "type": "string", "description": "Lowercase slug (3-64 chars, e.g. my-agent)" },
                  "agent": { "type": "string", "description": "Agent name (e.g. claude-code)" }
                }
              }
            }
          }
        },
        "responses": {
          "201": { "description": "API key created. Returns apiKey, tenantId, balance, endpoints." },
          "409": { "description": "Tenant or email already exists." }
        }
      }
    },
    "/api/v1/gpu/types": {
      "get": {
        "operationId": "listGpuTypes",
        "summary": "List all 47 GPU models with live pricing",
        "security": [],
        "responses": {
          "200": { "description": "Array of GPU types with pricePerHour, vramGb, spotPrice." }
        }
      }
    },
    "/api/v1/gpu/cheapest": {
      "get": {
        "operationId": "cheapestGpu",
        "summary": "Find cheapest GPU for a VRAM requirement",
        "security": [],
        "parameters": [
          { "name": "vram", "in": "query", "required": true, "schema": { "type": "integer" }, "description": "Minimum VRAM in GB" }
        ],
        "responses": {
          "200": { "description": "Cheapest GPU matching VRAM requirement." }
        }
      }
    },
    "/api/v1/gpu/deploy": {
      "post": {
        "operationId": "deployGpu",
        "summary": "Deploy an on-demand GPU instance",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["gpuType"],
                "properties": {
                  "gpuType": { "type": "string", "description": "GPU model name (e.g. RTX 4090)" },
                  "gpuCount": { "type": "integer", "default": 1 },
                  "models": { "type": "array", "items": { "type": "string" }, "description": "Ollama models to preload" },
                  "instanceType": { "type": "string", "enum": ["ollama", "docker", "ssh"], "default": "ollama" },
                  "volumeGb": { "type": "integer", "description": "Persistent volume size in GB" }
                }
              }
            }
          }
        },
        "responses": {
          "201": { "description": "Instance deploying. Returns pod object with id, status, pricePerHour." },
          "402": { "description": "Insufficient credits. Response includes balance, required amount, and requestTopup endpoint." },
          "422": { "description": "GPU type not available." }
        }
      }
    },
    "/api/v1/gpu/pods": {
      "get": {
        "operationId": "listPods",
        "summary": "List your active GPU instances",
        "responses": {
          "200": { "description": "Array of active pods with status, cost, billing info." }
        }
      }
    },
    "/api/v1/gpu/pods/{id}/stop": {
      "put": {
        "operationId": "stopPod",
        "summary": "Pause instance (billing pauses, volume kept)",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Instance paused." } }
      }
    },
    "/api/v1/gpu/pods/{id}": {
      "delete": {
        "operationId": "destroyPod",
        "summary": "Destroy instance permanently. Returns final cost.",
        "parameters": [{ "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }],
        "responses": { "200": { "description": "Instance destroyed. Final cost returned." } }
      }
    },
    "/api/v1/gpu/billing/request-topup": {
      "post": {
        "operationId": "requestTopup",
        "summary": "Email account owner to add credits",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": { "type": "string", "description": "Owner email (optional, defaults to account email)" },
                  "amount": { "type": "number", "default": 5, "description": "Requested top-up amount in USD" },
                  "reason": { "type": "string", "description": "Why credits are needed" }
                }
              }
            }
          }
        },
        "responses": { "200": { "description": "Email sent to account owner." } }
      }
    }
  }
}
