{
  "openapi": "3.1.0",
  "info": {
    "title": "CloudGPU API",
    "version": "1.0.0",
    "description": "One API key and one prepaid USD balance for an OpenAI-compatible model API and for renting GPUs billed per minute. Create a key at https://cloudgpu.app/api. Full docs: https://cloudgpu.app/api/docs. For AI coding assistants there is an MCP server: https://cloudgpu.app/docs/mcp",
    "contact": {
      "email": "support@cloudgpu.app",
      "url": "https://cloudgpu.app/contact"
    }
  },
  "servers": [
    {
      "url": "https://cloudgpu.app"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/v1/models": {
      "get": {
        "operationId": "listModels",
        "summary": "List models on the OpenAI-compatible API",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "operationId": "createChatCompletion",
        "summary": "OpenAI-compatible chat completion (supports stream=true)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "model",
                  "messages"
                ],
                "properties": {
                  "model": {
                    "type": "string"
                  },
                  "messages": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  },
                  "stream": {
                    "type": "boolean"
                  },
                  "max_tokens": {
                    "type": "integer"
                  },
                  "tools": {
                    "type": "array",
                    "items": {
                      "type": "object"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "operationId": "createMessage",
        "summary": "Claude Messages API format (for Claude Code and Claude SDKs)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/v1/gpu/account": {
      "get": {
        "operationId": "getGpuAccount",
        "summary": "Balance and how many instances this account may run at once",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "balance_usd": {
                      "type": "number"
                    },
                    "max_running_instances": {
                      "type": "integer"
                    },
                    "running_instances": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/gpu/offers": {
      "get": {
        "operationId": "listGpuOffers",
        "summary": "GPUs for rent with live price per GPU-hour and availability",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Offer"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/gpu/templates": {
      "get": {
        "operationId": "listGpuTemplates",
        "summary": "Instance templates (JupyterLab, Ollama, ComfyUI, LLaMA-Factory, ...)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Template"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/gpu/instances": {
      "get": {
        "operationId": "listGpuInstances",
        "summary": "Running, starting and recently stopped instances",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "const": "list"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Instance"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createGpuInstance",
        "summary": "Rent a GPU (asynchronous; poll until status is running)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "gpu_model": {
                    "type": "string",
                    "description": "As listed by /v1/gpu/offers"
                  },
                  "template": {
                    "type": "string",
                    "description": "Template id from /v1/gpu/templates"
                  },
                  "gpu_count": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 8
                  },
                  "max_minutes": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10080,
                    "description": "Destroy this many minutes after start (enforced server-side)"
                  },
                  "max_spend_usd": {
                    "type": "number",
                    "exclusiveMinimum": 0,
                    "description": "Destroy before this instance would cost more than this (enforced server-side)"
                  },
                  "idle_minutes": {
                    "type": "integer",
                    "description": "Destroy after the GPU has been idle this long; 10-1440, 0 = off (enforced server-side)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted; status is creating",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Instance"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/Error"
          },
          "402": {
            "$ref": "#/components/responses/Error"
          },
          "429": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/v1/gpu/instances/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "operationId": "getGpuInstance",
        "summary": "One instance, with SSH details once running",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Instance"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "operationId": "destroyGpuInstance",
        "summary": "Destroy the instance and stop billing (its disk is erased)",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Instance"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "CloudGPU API key"
      }
    },
    "responses": {
      "Error": {
        "description": "Error",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "error": {
                  "type": "object",
                  "properties": {
                    "type": {
                      "type": "string"
                    },
                    "code": {
                      "type": "string"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "schemas": {
      "Offer": {
        "type": "object",
        "properties": {
          "gpu_model": {
            "type": "string"
          },
          "vram_gb": {
            "type": "integer"
          },
          "hourly_usd": {
            "type": "number",
            "description": "Per GPU, billed per minute"
          },
          "available": {
            "enum": [
              "none",
              "low",
              "ok"
            ]
          },
          "min_gpu_count": {
            "type": "integer"
          }
        }
      },
      "Template": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "recommended_gpu": {
            "type": "string"
          },
          "min_gpu_count": {
            "type": "integer"
          },
          "has_api_endpoint": {
            "type": "boolean"
          }
        }
      },
      "Instance": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "gpu_model": {
            "type": "string"
          },
          "gpu_count": {
            "type": "integer"
          },
          "template": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "enum": [
              "creating",
              "running",
              "stopped",
              "failed"
            ]
          },
          "hourly_usd": {
            "type": "number"
          },
          "created_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "started_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "stopped_at": {
            "type": [
              "integer",
              "null"
            ]
          },
          "running_minutes": {
            "type": [
              "integer",
              "null"
            ]
          },
          "cost_usd": {
            "type": [
              "number",
              "null"
            ]
          },
          "ssh": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "host": {
                "type": "string"
              },
              "port": {
                "type": "integer"
              },
              "user": {
                "type": "string"
              },
              "password": {
                "type": "string"
              }
            }
          },
          "api_url": {
            "type": [
              "string",
              "null"
            ],
            "description": "Public HTTPS endpoint for templates with an API"
          },
          "failure_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "limits": {
            "type": [
              "object",
              "null"
            ],
            "properties": {
              "max_minutes": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "max_spend_usd": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "idle_minutes": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "expires_at": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "stopped_by": {
                "type": [
                  "string",
                  "null"
                ],
                "enum": [
                  "max_minutes",
                  "max_spend",
                  "idle",
                  null
                ]
              }
            }
          }
        }
      }
    }
  }
}
