{
  "openapi": "3.1.0",
  "info": {
    "title": "Fleet partner API",
    "version": "3.0.0",
    "description": "The HTTP API your fleet serves in HTTP mode. REMI calls it to read bot state and to send commands."
  },
  "servers": [
    {
      "url": "https://fleet.example.com",
      "description": "Your `base_url`, set with `PATCH /fleet`."
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "tags": [
    {
      "name": "State",
      "description": "REMI calls this to read your bots."
    },
    {
      "name": "Commands",
      "description": "REMI calls this to give a bot an order."
    }
  ],
  "paths": {
    "/bots": {
      "get": {
        "operationId": "listPartnerBots",
        "tags": [
          "State"
        ],
        "summary": "List bots with state",
        "description": "REMI polls this while your transport is `http` and you are not pushing state. Return every bot on every call, complete, without pagination: a bot left out, or with an invalid state, counts as a failed sample for that bot.\n\n- Answer within 5 seconds and under 1 MiB. REMI never runs two polls at once: the interval (`poll_interval_active_ms` while any bot holds a job, `poll_interval_idle_ms` otherwise) starts when the previous answer ends.\n- A bot becomes disconnected after 3 failed or missing polls in a row, or when its state is 60 seconds old. It reconnects after 2 polls in a row with `connected: true` and a fresh `timestamp`.",
        "responses": {
          "200": {
            "description": "Every bot of the fleet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ListPartnerBotsResponse"
                },
                "example": {
                  "bots": [
                    {
                      "bot_id": "ACME-4T001",
                      "seq": 88214,
                      "timestamp": "2026-06-17T15:48:08.000Z",
                      "available": true,
                      "connected": true,
                      "position": {
                        "lat": 4.6498,
                        "lng": -74.0712,
                        "azimuth": 90.3
                      },
                      "battery": {
                        "percentage": 74
                      },
                      "motion": {
                        "speed_mps": 0
                      },
                      "door": "closed",
                      "current_command": {
                        "id": "ES-5867/pickup",
                        "state": "succeeded",
                        "accepted_at": "2026-06-17T15:46:31.220Z",
                        "updated_at": "2026-06-17T15:48:05.400Z"
                      }
                    },
                    {
                      "bot_id": "ACME-4T002",
                      "seq": 51002,
                      "timestamp": "2026-06-17T15:48:08.000Z",
                      "available": false,
                      "connected": true,
                      "position": {
                        "lat": 4.6498,
                        "lng": -74.0712,
                        "azimuth": 90.3
                      },
                      "battery": {
                        "percentage": 31
                      },
                      "motion": {
                        "speed_mps": 1.4
                      },
                      "door": "closed",
                      "current_command": {
                        "id": "ES-5868/dropoff",
                        "state": "executing",
                        "accepted_at": "2026-06-17T15:47:55.000Z"
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Reject a missing or wrong bearer token. REMI counts any non-2xx answer as a failed poll.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "x-error-codes": [
              {
                "when": "Reject a missing or wrong bearer token. REMI counts any non-2xx answer as a failed poll."
              }
            ]
          },
          "500": {
            "description": "Any other non-2xx status, a timeout, or a body that is not `{ \"bots\": [...] }` counts as a failed poll for every bot.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "x-error-codes": [
              {
                "when": "Any other non-2xx status, a timeout, or a body that is not `{ \"bots\": [...] }` counts as a failed poll for every bot."
              }
            ]
          }
        }
      }
    },
    "/bots/{bot_id}/commands": {
      "post": {
        "operationId": "createBotCommand",
        "tags": [
          "Commands"
        ],
        "summary": "Accept a command",
        "description": "REMI gives one bot one command and expects 202 as soon as it is queued, not when the bot finishes. Progress comes back in `current_command` of the bot state.\n\n- Be idempotent on `(bot_id, id)`. An unconfirmed command is resent with the same `id` every 10 seconds, 3 sends in total.\n- Only 202 with a valid `CommandStatus` body counts as received. Any other 2xx, or an invalid body, is treated as not received and resent.\n- A 202 body with `state: rejected` ends the command. With `state: failed` (its mission already ended), REMI sends a `navigate_to` again under a new id, `<id>~1`, `<id>~2` and so on, at most 5 times.\n- A `navigate_to` during another navigation must replace it if you declared `supports_command_interrupt: true`. Otherwise REMI sends `cancel_navigation` first and waits for it.\n- `set_door` is never sent to a bot with `has_door: false`, and `closed` never to one with `manual_close_door: true`.\n- A corrected destination is information: REMI neither resends nor cancels, and expects the bot to drive to `corrected_position`. Report `position` and `motion` so REMI can see the bot stop within 25 m of it.\n\nAnswer a 4xx with a problem body whose `code` is one of the codes below. REMI also reads `reason` and `correction_distance_m`.",
        "parameters": [
          {
            "name": "bot_id",
            "in": "path",
            "required": true,
            "description": "The `bot_id` REMI registered, not the `fleet_serial`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BotCommand"
              },
              "example": {
                "id": "ES-5867/pickup",
                "type": "navigate_to",
                "params": {
                  "lat": 4.6512,
                  "lng": -74.0689
                },
                "issued_at": "2026-06-17T15:46:31.000Z"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The command is queued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CommandStatus"
                },
                "example": {
                  "id": "ES-5867/pickup",
                  "state": "accepted",
                  "accepted_at": "2026-06-17T15:46:31.220Z",
                  "corrected_position": {
                    "lat": 4.6513,
                    "lng": -74.0688
                  },
                  "correction_distance_m": 14.2
                }
              }
            }
          },
          "404": {
            "description": "`BOT_NOT_FOUND`: Unknown bot. Final: REMI does not resend.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "x-error-codes": [
              {
                "code": "BOT_NOT_FOUND",
                "when": "Unknown bot. Final: REMI does not resend."
              }
            ]
          },
          "409": {
            "description": "`COMMAND_EXPIRED`: `expires_at` is in the past. Final: REMI does not resend.\n\n`BOT_BUSY`: The bot cannot take the command in its current state, not transiently. Final: REMI does not resend.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "x-error-codes": [
              {
                "code": "COMMAND_EXPIRED",
                "when": "`expires_at` is in the past. Final: REMI does not resend."
              },
              {
                "code": "BOT_BUSY",
                "when": "The bot cannot take the command in its current state, not transiently. Final: REMI does not resend."
              }
            ]
          },
          "422": {
            "description": "`UNSUPPORTED_COMMAND`: The bot does not support the command type or a parameter. Final: REMI does not resend.\n\n`DESTINATION_UNREACHABLE`: The destination is too far from your drivable network. Include `correction_distance_m`. Final: REMI does not resend.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "x-error-codes": [
              {
                "code": "UNSUPPORTED_COMMAND",
                "when": "The bot does not support the command type or a parameter. Final: REMI does not resend."
              },
              {
                "code": "DESTINATION_UNREACHABLE",
                "when": "The destination is too far from your drivable network. Include `correction_distance_m`. Final: REMI does not resend."
              }
            ]
          },
          "500": {
            "description": "Any 5xx, a timeout or a network failure means not received: REMI resends the same `id` after 10 seconds, 3 sends in total.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            },
            "x-error-codes": [
              {
                "when": "Any 5xx, a timeout or a network failure means not received: REMI resends the same `id` after 10 seconds, 3 sends in total."
              }
            ]
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "REMI sends the token you set with `PATCH /fleet` as `Authorization: Bearer <token>`."
      }
    },
    "schemas": {
      "Problem": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "Always `about:blank`."
          },
          "title": {
            "type": "string",
            "description": "The HTTP status text."
          },
          "status": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991
          },
          "detail": {
            "type": "string",
            "description": "Human-readable. Do not parse it: branch on `code`."
          },
          "instance": {
            "type": "string",
            "description": "The request path."
          },
          "code": {
            "description": "Stable machine-readable error code, when the error has one.",
            "type": "string"
          },
          "params": {
            "description": "Values that explain the error, keyed by name.",
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {}
          }
        },
        "required": [
          "type",
          "title",
          "status",
          "detail",
          "instance"
        ]
      },
      "BotState": {
        "type": "object",
        "properties": {
          "bot_id": {
            "type": "string"
          },
          "seq": {
            "description": "Increasing per bot. A state is kept only if its `timestamp` is later than the last accepted one, or equal with a higher `seq`. Without it, states are not ordered.",
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "timestamp": {
            "type": "string",
            "format": "date-time",
            "description": "When the state was measured on your side, not when it was sent."
          },
          "available": {
            "type": "boolean",
            "description": "Whether the bot can take new work right now, by your own verdict. Do not fold in connectivity, staleness or out of service."
          },
          "out_of_service": {
            "description": "True when you took the bot out of service. Operators are alerted while it holds a job, and new `navigate_to` commands are held back. Absent means false.",
            "type": "boolean"
          },
          "connected": {
            "type": "boolean",
            "description": "Whether you have a live link to the bot. In MQTT mode the broker connection decides instead."
          },
          "position": {
            "type": "object",
            "properties": {
              "lat": {
                "type": "number",
                "minimum": -90,
                "maximum": 90,
                "description": "Latitude in decimal degrees, WGS 84."
              },
              "lng": {
                "type": "number",
                "minimum": -180,
                "maximum": 180,
                "description": "Longitude in decimal degrees, WGS 84."
              },
              "azimuth": {
                "description": "Compass bearing in degrees: 0 = North, clockwise, nominally [0, 360).",
                "type": "number"
              }
            },
            "required": [
              "lat",
              "lng"
            ]
          },
          "battery": {
            "type": "object",
            "properties": {
              "percentage": {
                "type": "integer",
                "minimum": 0,
                "maximum": 100,
                "description": "State of charge, 0 to 100. Below 20 the bot gets no new jobs."
              }
            },
            "required": [
              "percentage"
            ]
          },
          "motion": {
            "type": "object",
            "properties": {
              "speed_mps": {
                "type": "number",
                "minimum": 0,
                "description": "Ground speed in meters per second."
              }
            },
            "required": [
              "speed_mps"
            ]
          },
          "door": {
            "type": "string",
            "enum": [
              "opened",
              "closed",
              "opening",
              "closing",
              "stalled",
              "unknown",
              "unsupported"
            ],
            "description": "Cargo door state. Send `unknown` when you cannot read it and `unsupported` when the bot has no controllable door, never `closed`."
          },
          "current_command": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/CommandStatus"
              },
              {
                "type": "null"
              }
            ],
            "description": "The latest command this bot accepted. REMI counts a command as delivered when its `id` appears here. Null if none yet."
          }
        },
        "required": [
          "bot_id",
          "timestamp",
          "available",
          "connected",
          "position",
          "battery",
          "door",
          "current_command"
        ]
      },
      "BotCommand": {
        "oneOf": [
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1,
                "description": "Idempotency key, unique per bot. Opaque: echo it back in `current_command.id`."
              },
              "issued_at": {
                "type": "string",
                "format": "date-time",
                "description": "When REMI issued the command."
              },
              "expires_at": {
                "description": "Optional deadline after which the command is not worth executing. REMI does not set it today.",
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "type": "string",
                "const": "navigate_to"
              },
              "params": {
                "type": "object",
                "properties": {
                  "lat": {
                    "type": "number"
                  },
                  "lng": {
                    "type": "number"
                  }
                },
                "required": [
                  "lat",
                  "lng"
                ]
              }
            },
            "required": [
              "id",
              "issued_at",
              "type",
              "params"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1,
                "description": "Idempotency key, unique per bot. Opaque: echo it back in `current_command.id`."
              },
              "issued_at": {
                "type": "string",
                "format": "date-time",
                "description": "When REMI issued the command."
              },
              "expires_at": {
                "description": "Optional deadline after which the command is not worth executing. REMI does not set it today.",
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "type": "string",
                "const": "cancel_navigation"
              },
              "params": {
                "default": {},
                "type": "object",
                "properties": {}
              }
            },
            "required": [
              "id",
              "issued_at",
              "type"
            ]
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1,
                "description": "Idempotency key, unique per bot. Opaque: echo it back in `current_command.id`."
              },
              "issued_at": {
                "type": "string",
                "format": "date-time",
                "description": "When REMI issued the command."
              },
              "expires_at": {
                "description": "Optional deadline after which the command is not worth executing. REMI does not set it today.",
                "type": "string",
                "format": "date-time"
              },
              "type": {
                "type": "string",
                "const": "set_door"
              },
              "params": {
                "type": "object",
                "properties": {
                  "state": {
                    "type": "string",
                    "enum": [
                      "open",
                      "closed"
                    ]
                  }
                },
                "required": [
                  "state"
                ]
              }
            },
            "required": [
              "id",
              "issued_at",
              "type",
              "params"
            ]
          }
        ]
      },
      "CommandStatus": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "description": "The command id REMI sent."
          },
          "state": {
            "type": "string",
            "enum": [
              "accepted",
              "executing",
              "succeeded",
              "failed",
              "rejected"
            ],
            "description": "`accepted`: queued. `executing`: in progress. `succeeded`, `failed` and `rejected` are terminal. `failed`: accepted but cannot finish. `rejected`: you will not take it, with `error.code` and `rejected_at`."
          },
          "accepted_at": {
            "description": "Required unless `state` is `rejected`.",
            "type": "string",
            "format": "date-time"
          },
          "rejected_at": {
            "description": "Required when `state` is `rejected`, absent otherwise.",
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "description": "When `state` last changed.",
            "type": "string",
            "format": "date-time"
          },
          "error": {
            "description": "Set when `state` is `failed` or `rejected`. On a rejection, `code` is one of the four rejection codes.",
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          },
          "corrected_position": {
            "description": "Where the bot will really stop when you moved a `navigate_to` destination. Only while `accepted` or `executing`.",
            "type": "object",
            "properties": {
              "lat": {
                "type": "number",
                "minimum": -90,
                "maximum": 90,
                "description": "Latitude in decimal degrees, WGS 84."
              },
              "lng": {
                "type": "number",
                "minimum": -180,
                "maximum": 180,
                "description": "Longitude in decimal degrees, WGS 84."
              }
            },
            "required": [
              "lat",
              "lng"
            ]
          },
          "correction_distance_m": {
            "description": "Meters between the requested destination and `corrected_position`, or, on a `DESTINATION_UNREACHABLE` rejection, your network.",
            "type": "number",
            "minimum": 0
          }
        },
        "required": [
          "id",
          "state"
        ]
      },
      "BotEvent": {
        "type": "object",
        "properties": {
          "bot_id": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "arrived",
              "blocked",
              "unblocked"
            ],
            "description": "`arrived`: a navigation finished. `blocked` and `unblocked` open and close an operator task."
          },
          "command_id": {
            "description": "Required for `arrived`: the id of the navigation command that just completed.",
            "type": "string",
            "minLength": 1
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time",
            "description": "When it happened on your side, not when you sent it."
          },
          "detail": {
            "description": "For `blocked`: `{ \"reason\": string, \"message\": string }`.",
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {}
          }
        },
        "required": [
          "bot_id",
          "type",
          "occurred_at"
        ]
      },
      "FleetCapabilities": {
        "type": "object",
        "properties": {
          "supports_command_interrupt": {
            "type": "boolean",
            "description": "Whether a `navigate_to` sent during another navigation is accepted and replaces it. Fleet-wide. Without a document this is false."
          },
          "default": {
            "type": "object",
            "properties": {
              "has_door": {
                "type": "boolean",
                "description": "Whether the bot has a remotely controllable cargo door. False: `set_door` is never sent."
              },
              "supported_commands": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "navigate_to",
                    "cancel_navigation",
                    "set_door"
                  ]
                },
                "description": "The command types this bot accepts."
              }
            },
            "required": [
              "has_door",
              "supported_commands"
            ],
            "description": "Applies to every bot unless overridden."
          },
          "overrides": {
            "default": {},
            "description": "Keyed by bot id and merged over `default`, field by field.",
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "object",
              "properties": {
                "has_door": {
                  "type": "boolean",
                  "description": "Whether the bot has a remotely controllable cargo door. False: `set_door` is never sent."
                },
                "supported_commands": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "navigate_to",
                      "cancel_navigation",
                      "set_door"
                    ]
                  },
                  "description": "The command types this bot accepts."
                }
              }
            }
          }
        },
        "required": [
          "supports_command_interrupt",
          "default"
        ]
      },
      "ListPartnerBotsResponse": {
        "type": "object",
        "properties": {
          "bots": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BotState"
            },
            "description": "Complete bot states, as `BotState`."
          }
        },
        "required": [
          "bots"
        ]
      }
    }
  }
}
