{
  "openapi": "3.0.3",
  "info": {
    "title": "Polymath API",
    "description": "Use the Polymath API to find vehicles, check their state, and send commands.",
    "termsOfService": "https://www.polymathrobotics.com/legal/terms-of-service",
    "contact": {
      "name": "Polymath Support",
      "url": "https://www.polymathrobotics.com",
      "email": "api@polymathrobotics.com"
    },
    "license": {
      "name": "All rights reserved",
      "url": "https://www.polymathrobotics.com/legal/privacy-policy"
    },
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.polymathrobotics.dev",
      "description": "Polymath API"
    }
  ],
  "security": [
    {
      "HTTPBearer": []
    }
  ],
  "tags": [
    {
      "name": "Vehicles",
      "description": "Find vehicles your API client can access."
    },
    {
      "name": "Power",
      "description": "Check a vehicle's power state and request power changes."
    }
  ],
  "paths": {
    "/v1/vehicles": {
      "get": {
        "tags": ["Vehicles"],
        "summary": "List vehicles",
        "description": "Lists the vehicles your API client can access and shows whether each vehicle is connected to the Polymath VPN.",
        "operationId": "list_vehicles",
        "responses": {
          "200": {
            "description": "The vehicles your API client can access.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VehiclesResponse"
                },
                "example": {
                  "status": "success",
                  "data": [
                    {
                      "id": "your_vehicle_id",
                      "ipAddress": "100.64.0.1",
                      "vpnConnected": true
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          }
        }
      }
    },
    "/v1/vehicles/{vehicleId}/power/status": {
      "get": {
        "tags": ["Power"],
        "summary": "Get vehicle power status",
        "description": "Returns the vehicle's most recently reported power state and any pending power command.",
        "operationId": "get_vehicle_power_status",
        "parameters": [
          {
            "$ref": "#/components/parameters/VehicleId"
          }
        ],
        "responses": {
          "200": {
            "description": "The vehicle's most recently reported power state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PowerStatusResponse"
                },
                "example": {
                  "status": "success",
                  "data": {
                    "state": "on",
                    "pendingCommand": null,
                    "updatedAt": "2026-06-29T12:00:00.000Z"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/VehicleNotFound"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/v1/vehicles/{vehicleId}/power/on": {
      "post": {
        "tags": ["Power"],
        "summary": "Request vehicle power on",
        "description": "Requests that the vehicle turn on. Send this request without a body. A `202 Accepted` response means Polymath accepted the command, but the vehicle may still be off. Poll the power status endpoint until the vehicle is `on` and no command is pending.",
        "operationId": "request_vehicle_power_on",
        "parameters": [
          {
            "$ref": "#/components/parameters/VehicleId"
          }
        ],
        "responses": {
          "202": {
            "$ref": "#/components/responses/CommandAccepted"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/VehicleNotFound"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    },
    "/v1/vehicles/{vehicleId}/power/off": {
      "post": {
        "tags": ["Power"],
        "summary": "Request vehicle power off",
        "description": "Requests that the vehicle turn off. Send this request without a body. A `202 Accepted` response means Polymath accepted the command, but the vehicle may still be on. Poll the power status endpoint until the vehicle is `off` and no command is pending.",
        "operationId": "request_vehicle_power_off",
        "parameters": [
          {
            "$ref": "#/components/parameters/VehicleId"
          }
        ],
        "responses": {
          "202": {
            "$ref": "#/components/responses/CommandAccepted"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/VehicleNotFound"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "502": {
            "$ref": "#/components/responses/BadGateway"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailable"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeout"
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "VehicleId": {
        "name": "vehicleId",
        "in": "path",
        "required": true,
        "description": "The vehicle ID provided by Polymath.",
        "schema": {
          "type": "string"
        },
        "example": "your_vehicle_id"
      }
    },
    "schemas": {
      "VehiclesResponse": {
        "type": "object",
        "required": ["status", "data"],
        "properties": {
          "status": {
            "type": "string",
            "enum": ["success"]
          },
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VehicleSummary"
            }
          }
        }
      },
      "VehicleSummary": {
        "type": "object",
        "required": ["id", "vpnConnected"],
        "properties": {
          "id": {
            "type": "string",
            "description": "The vehicle ID provided by Polymath."
          },
          "ipAddress": {
            "type": "string",
            "format": "ipv4",
            "description": "The vehicle's Polymath VPN address. This field is omitted when no address is available."
          },
          "vpnConnected": {
            "type": "boolean",
            "description": "Whether the vehicle is connected to the Polymath VPN."
          }
        }
      },
      "PowerStatusResponse": {
        "type": "object",
        "required": ["status", "data"],
        "properties": {
          "status": {
            "type": "string",
            "enum": ["success"]
          },
          "data": {
            "$ref": "#/components/schemas/PowerStatus"
          }
        }
      },
      "PowerStatus": {
        "type": "object",
        "required": ["state", "pendingCommand", "updatedAt"],
        "properties": {
          "state": {
            "type": "string",
            "description": "The vehicle's most recently reported power state.",
            "enum": ["on", "off", "unknown"]
          },
          "pendingCommand": {
            "$ref": "#/components/schemas/PowerPendingCommand"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time",
            "description": "When the vehicle's power state was last reported, or `null` if no state has been reported.",
            "nullable": true
          }
        }
      },
      "PowerPendingCommand": {
        "type": "object",
        "description": "A power command that Polymath accepted but the vehicle has not completed, or `null` if no command is pending.",
        "nullable": true,
        "required": ["state"],
        "properties": {
          "state": {
            "type": "string",
            "description": "The power state requested by the pending command.",
            "enum": ["on", "off"]
          }
        }
      },
      "SuccessResponse": {
        "type": "object",
        "required": ["status"],
        "properties": {
          "status": {
            "type": "string",
            "enum": ["success"]
          }
        }
      }
    },
    "responses": {
      "CommandAccepted": {
        "description": "Polymath accepted the command.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/SuccessResponse"
            },
            "example": {
              "status": "success"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "The request is missing a bearer token, or the token is invalid."
      },
      "Forbidden": {
        "description": "The bearer token does not grant access to this operation or vehicle."
      },
      "VehicleNotFound": {
        "description": "The vehicle was not found, is not available to this API client, or does not support power control."
      },
      "InternalServerError": {
        "description": "Polymath could not complete the request because of an unexpected error."
      },
      "BadGateway": {
        "description": "Polymath could not complete the request because another service failed."
      },
      "ServiceUnavailable": {
        "description": "The requested operation is temporarily unavailable."
      },
      "GatewayTimeout": {
        "description": "Polymath did not receive a response in time."
      }
    },
    "securitySchemes": {
      "HTTPBearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Send your access token in the `Authorization` header as `Bearer <token>`."
      }
    }
  }
}
