{
  "openapi": "3.1.0",
  "info": {
    "title": "Postbot",
    "version": "1.0.0",
    "description": "Send real physical letters in the Czech Republic from an AI agent, CLI, or the web. Backed by Česká pošta (DopisOnline).\n\nVersioning: the version is in the path. This document describes v1, served at /api/v1; the unversioned /api/* paths serve the same v1 surface. A breaking change ships under a new path version. Before a version retires, its responses announce it with a `Deprecation` header (RFC 9745) and a `Sunset` header (RFC 8594) that carry the dates.",
    "contact": {
      "email": "ladi@amentistudio.com"
    }
  },
  "x-service-info": {
    "name": "Postbot",
    "description": "Physical letter delivery across the Czech Republic for AI agents.",
    "categories": [
      "postal",
      "printing",
      "logistics",
      "communication"
    ],
    "docs": {
      "homepage": "https://postbot.cz",
      "apiReference": "https://postbot.cz/openapi.json",
      "llms": "https://postbot.cz/llms.txt"
    }
  },
  "servers": [
    {
      "url": "https://postbot.cz/api/v1"
    }
  ],
  "paths": {
    "/send": {
      "post": {
        "summary": "Send a physical letter",
        "description": "Prints, envelopes, and mails a letter via Česká pošta. Charged against the account's prepaid CZK credit; the price is computed from the rendered PDF (postage band + print). An unfunded account gets 402 with a top-up URL.",
        "operationId": "sendLetter",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "x-payment-info": {
          "intent": "session",
          "method": "stripe",
          "amount": null,
          "currency": "CZK",
          "description": "Charged from prepaid CZK credit; priced per letter from the rendered PDF."
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Same input as the MCP `send_letter_cz` tool."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Letter handed over to Česká pošta.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SendResult"
                }
              }
            }
          },
          "400": {
            "description": "The letter is invalid, or is one Česká pošta cannot print: {error: 'invalid_letter', message, issues?: [{field, code, message, cp?}]}. `issues` names the offending field (e.g. `to.street`, `document`) and a stable `code`, so a caller can fix that one field and retry. Always checked before any charge. Some deployments additionally validate against Česká pošta itself, in which case `cp` carries their own error code — treat `cp` as present-or-absent rather than guaranteed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing/invalid API key and the body was not a valid letter.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "402": {
            "description": "Payment required — the letter is valid, it just isn't funded. Body carries the funding rails for this exact letter: rails.oneoff.payUrl (ready Stripe pay-link, no account — the letter mails once paid) and rails.credit.topupUrl (prepaid balance). rails.credit is always present; rails.oneoff may be absent when a pay-link must not or cannot be minted (the letter is already paid, or card payments are briefly unavailable) — fall back to the credit rail. Returned both for unauthenticated calls with a valid letter (error=payment_required) and for funded accounts with a low balance (error=insufficient_credit, plus balance/needed/topupUrl).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "{error: 'duplicate_send', message, orderId}. This exact letter has already been paid for (and is being, or has been, mailed) via its one-off pay-link, so no credit was spent and nothing was sent twice. Do NOT retry — check the order status instead. To mail the same content again deliberately, change `jobRef`/`note` or send with a fresh Idempotency-Key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "{error: 'sending_paused', message, infoUrl, contact}. Postbot's own daily spend safeguard paused all sending. Nothing was charged or mailed, so a later retry is safe. No Retry-After header: read infoUrl, or retry later.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Any other failure, for example 413 payload_too_large or a 5xx. The `error` code says which; `message` says what to do. Only the responses that declare Retry-After send it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/topup": {
      "post": {
        "summary": "Top up prepaid CZK credit",
        "description": "Funds the account's prepaid balance via Stripe. Returns a Stripe Checkout URL.",
        "operationId": "topUp",
        "x-payment-info": {
          "intent": "session",
          "method": "stripe",
          "amount": "500",
          "currency": "CZK",
          "description": "Establishes/extends prepaid balance. Minimum 500 Kč."
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amountCzk": {
                    "type": "integer",
                    "minimum": 500
                  }
                },
                "required": [
                  "amountCzk"
                ]
              }
            }
          }
        },
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "Stripe Checkout URL to fund credit.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TopupResult"
                }
              }
            }
          },
          "400": {
            "description": "{error: 'bad_amount', message, minCzk, maxCzk} — amountCzk is outside the allowed range.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Any other failure, for example 413 payload_too_large or a 5xx. The `error` code says which; `message` says what to do. Only the responses that declare Retry-After send it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/preview": {
      "post": {
        "summary": "Preview + firm-price a letter (no order, no payment)",
        "description": "Renders the letter to the exact PDF that would be printed and returns it with the firm price. No side effects — use before /api/send or /api/oneoff to show a human what will mail.",
        "operationId": "previewLetter",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Same input as the MCP `send_letter_cz` tool."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rendered preview and firm price.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Preview"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          },
          "400": {
            "description": "The letter is invalid, or is one Česká pošta cannot print: {error: 'invalid_letter', message, issues?: [{field, code, message, cp?}]}. `issues` names the offending field (e.g. `to.street`, `document`) and a stable `code`, so a caller can fix that one field and retry. Always checked before any charge. Some deployments additionally validate against Česká pošta itself, in which case `cp` carries their own error code — treat `cp` as present-or-absent rather than guaranteed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          },
          "429": {
            "description": "Rate limited: more than 30 requests to this route per minute from this IP, counted per edge instance, best effort. Wait Retry-After seconds, then retry.",
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              },
              "Retry-After": {
                "$ref": "#/components/headers/Retry-After"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Any other failure, for example 413 payload_too_large or a 5xx. The `error` code says which; `message` says what to do. Only the responses that declare Retry-After send it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          }
        }
      }
    },
    "/oneoff": {
      "post": {
        "summary": "Pay for a single letter (no account)",
        "description": "One-off card payment for one letter. Prices the rendered PDF, returns a pay URL.",
        "operationId": "oneOff",
        "x-payment-info": {
          "intent": "charge",
          "method": "stripe",
          "amount": null,
          "currency": "CZK",
          "description": "Single-letter card payment, priced from the PDF. Minimum 50 Kč."
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Letter input to price and mail."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Pay URL for the quoted letter.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OneoffQuote"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          },
          "400": {
            "description": "The letter is invalid, or is one Česká pošta cannot print: {error: 'invalid_letter', message, issues?: [{field, code, message, cp?}]}. `issues` names the offending field (e.g. `to.street`, `document`) and a stable `code`, so a caller can fix that one field and retry. Always checked before any charge. Some deployments additionally validate against Česká pošta itself, in which case `cp` carries their own error code — treat `cp` as present-or-absent rather than guaranteed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          },
          "409": {
            "description": "{error: 'duplicate_letter', message}. An identical letter was already paid or mailed. Vary `jobRef` (or `note`) to send it again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          },
          "429": {
            "description": "Rate limited: more than 10 one-off quotes (with anonymous /send and MCP quotes) per minute from this IP, counted per edge instance, best effort. Wait Retry-After seconds, then retry.",
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              },
              "Retry-After": {
                "$ref": "#/components/headers/Retry-After"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "{error: 'validation_unavailable', message}. Česká pošta could not confirm that the letter can be printed, so no payment was created and nothing was charged. Retry after Retry-After seconds.",
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              },
              "Retry-After": {
                "$ref": "#/components/headers/Retry-After"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Any other failure, for example 413 payload_too_large or a 5xx. The `error` code says which; `message` says what to do. Only the responses that declare Retry-After send it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          }
        }
      }
    },
    "/balance": {
      "get": {
        "summary": "Read the prepaid CZK balance",
        "description": "The balance /send gates on. An account that has never topped up reads 0. Used by `posta balance`.",
        "operationId": "getBalance",
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The available prepaid balance.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Balance"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Any other failure, for example 413 payload_too_large or a 5xx. The `error` code says which; `message` says what to do. Only the responses that declare Retry-After send it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders": {
      "get": {
        "summary": "List your letters, newest first",
        "description": "The Orders of this account, newest first, one page at a time. Pass a page's next_cursor as `cursor` to read the next page; has_more is false on the last one. No item carries the letter content. The hosted MCP tool list_letters returns the same page.",
        "operationId": "listOrders",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            },
            "description": "Orders per page."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Opaque. The next_cursor of the previous page, unchanged. Omit it for the first page."
          }
        ],
        "responses": {
          "200": {
            "description": "One page of this account's Orders.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OrderPage"
                }
              }
            }
          },
          "400": {
            "description": "{error: 'invalid_request', message}. limit is not an integer from 1 to 100, or cursor is not a next_cursor this API returned.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Any other failure, for example 413 payload_too_large or a 5xx. The `error` code says which; `message` says what to do. Only the responses that declare Retry-After send it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders/{orderId}": {
      "get": {
        "summary": "Read the status of one of your letters",
        "description": "Status, Česká pošta order code, and tracking number of a letter sent from this account. Used by `posta status`.",
        "operationId": "getOrder",
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "orderId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The orderId that /send returned."
          }
        ],
        "responses": {
          "200": {
            "description": "The Order's status on this account.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AccountOrder"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such order on this account (another account's order also answers 404).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Any other failure, for example 413 payload_too_large or a 5xx. The `error` code says which; `message` says what to do. Only the responses that declare Retry-After send it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/order-status": {
      "get": {
        "summary": "Read the public status of one Order",
        "description": "No authentication: whoever holds the orderId can read these non-sensitive fields, never the letter content. The /sent page polls it while a paid one-off Order is handed over to Česká pošta.",
        "operationId": "getOrderStatus",
        "parameters": [
          {
            "name": "order",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The orderId of the Order."
          }
        ],
        "responses": {
          "200": {
            "description": "The Order's public status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PublicOrderStatus"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          },
          "400": {
            "description": "{error: 'missing_order'}. The `order` query parameter is absent.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          },
          "404": {
            "description": "{error: 'not_found'}. No Order has this id.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          },
          "429": {
            "description": "Rate limited: more than 60 requests to this route per minute from this IP, counted per edge instance, best effort. Wait Retry-After seconds, then retry.",
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              },
              "Retry-After": {
                "$ref": "#/components/headers/Retry-After"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Any other failure, for example 413 payload_too_large or a 5xx. The `error` code says which; `message` says what to do. Only the responses that declare Retry-After send it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "RateLimit-Limit": {
                "$ref": "#/components/headers/RateLimit-Limit"
              },
              "RateLimit-Remaining": {
                "$ref": "#/components/headers/RateLimit-Remaining"
              },
              "RateLimit-Reset": {
                "$ref": "#/components/headers/RateLimit-Reset"
              }
            }
          }
        }
      }
    },
    "/keys": {
      "post": {
        "summary": "Mint an API key with an OAuth access token",
        "description": "Issues a new API key for the account that granted the OAuth access token. The account's previous API key stops working. No request body. Request the token with resource=https://postbot.cz/api/keys. Used by `posta auth`.",
        "operationId": "mintApiKey",
        "security": [
          {
            "oauth2": [
              "letters:send"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "The new API key. Postbot stores only its hash: keep it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKey"
                }
              }
            }
          },
          "401": {
            "description": "No usable OAuth access token, with a WWW-Authenticate challenge. Without a token the body is empty. An invalid, expired, or wrongly bound token gets {error: 'invalid_token', error_description}. {error: 'unauthorized'} when the token's account no longer exists.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "{error: 'insufficient_scope'}. The token lacks letters:send.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "{error: 'account_unavailable'}. The account was removed during the request. No key was issued.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "default": {
            "description": "Any other failure, for example 413 payload_too_large or a 5xx. The `error` code says which; `message` says what to do. Only the responses that declare Retry-After send it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "schema": {
          "type": "string"
        },
        "description": "Optional. Scoped per account: the key and your account id together name the Order, so another account's identical key never collides with yours. A retry with the same key after the Order was handed over returns that Order (200, same orderId, orderCode and trackingNumber) and charges nothing again. A retry while that Order is not handed over (in flight, failed, or canceled) answers 502 send_failed and mails nothing; use a new key for a new send. Without a key, every call is a new Order."
      }
    },
    "headers": {
      "RateLimit-Limit": {
        "description": "Requests allowed per window for this route and client IP.",
        "schema": {
          "type": "integer"
        }
      },
      "RateLimit-Remaining": {
        "description": "Requests left in the current window.",
        "schema": {
          "type": "integer"
        }
      },
      "RateLimit-Reset": {
        "description": "Seconds until the current window resets.",
        "schema": {
          "type": "integer"
        }
      },
      "Retry-After": {
        "description": "Seconds to wait before a retry.",
        "schema": {
          "type": "integer"
        }
      }
    },
    "schemas": {
      "Service": {
        "type": "string",
        "enum": [
          "obycejne",
          "doporucene"
        ],
        "description": "obycejne = ordinary letter; doporucene = registered, with tracking."
      },
      "OrderStatus": {
        "type": "string",
        "enum": [
          "created",
          "dispatching",
          "dispatched",
          "send_failed",
          "canceled"
        ],
        "description": "created = recorded, not yet handed over (a one-off quote waits for payment); dispatching = Handover to Česká pošta in progress; dispatched = handed over; send_failed = Handover failed; canceled = an unpaid quote was retired, never mailed."
      },
      "SendResult": {
        "type": "object",
        "required": [
          "orderId",
          "service",
          "chargeCzk",
          "billingPending"
        ],
        "properties": {
          "orderId": {
            "type": "string",
            "description": "Postbot Order id, for GET /orders/{orderId}."
          },
          "orderCode": {
            "type": "string",
            "description": "Česká pošta order code."
          },
          "trackingNumber": {
            "type": "string",
            "description": "Česká pošta tracking number (podací číslo), when it assigned one."
          },
          "service": {
            "$ref": "#/components/schemas/Service"
          },
          "chargeCzk": {
            "type": "integer",
            "description": "Price of this letter in CZK."
          },
          "balance": {
            "type": "number",
            "description": "Prepaid balance in CZK after the charge. Absent on an Idempotency-Key replay."
          },
          "billingPending": {
            "type": "boolean",
            "description": "True when the letter was handed over but recording the charge failed; a background job retries it."
          }
        }
      },
      "Preview": {
        "type": "object",
        "required": [
          "pdfBase64",
          "sheets",
          "service",
          "chargeCzk",
          "payCzk"
        ],
        "properties": {
          "pdfBase64": {
            "type": "string",
            "contentEncoding": "base64",
            "contentMediaType": "application/pdf",
            "description": "The exact PDF that would be printed."
          },
          "sheets": {
            "type": "integer",
            "description": "Printed sheets."
          },
          "service": {
            "$ref": "#/components/schemas/Service"
          },
          "chargeCzk": {
            "type": "integer",
            "description": "Price on prepaid credit, CZK."
          },
          "payCzk": {
            "type": "integer",
            "description": "Price as a one-off card payment, CZK (one-off minimum applied)."
          }
        }
      },
      "OneoffQuote": {
        "type": "object",
        "required": [
          "payUrl",
          "chargeCzk",
          "payCzk",
          "sheets"
        ],
        "properties": {
          "payUrl": {
            "type": "string",
            "format": "uri",
            "description": "Stripe Checkout link for this letter. It mails once paid."
          },
          "chargeCzk": {
            "type": "integer",
            "description": "Price on prepaid credit, CZK."
          },
          "payCzk": {
            "type": "integer",
            "description": "Amount the pay link charges, CZK."
          },
          "sheets": {
            "type": "integer",
            "description": "Printed sheets."
          }
        }
      },
      "TopupResult": {
        "type": "object",
        "required": [
          "payUrl"
        ],
        "properties": {
          "payUrl": {
            "type": "string",
            "format": "uri",
            "description": "Stripe Checkout link. The balance grows once paid."
          }
        }
      },
      "Balance": {
        "type": "object",
        "required": [
          "balanceCzk"
        ],
        "properties": {
          "balanceCzk": {
            "type": "number",
            "description": "Available prepaid balance, CZK. 0 for an account never topped up."
          }
        }
      },
      "AccountOrder": {
        "type": "object",
        "required": [
          "orderId",
          "status"
        ],
        "properties": {
          "orderId": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "orderCode": {
            "type": "string",
            "description": "Česká pošta order code. Absent until handed over."
          },
          "tracking": {
            "type": "string",
            "description": "Česká pošta tracking number. Absent when it assigned none."
          }
        }
      },
      "OrderSummary": {
        "type": "object",
        "required": [
          "orderId",
          "status",
          "service",
          "sheets",
          "chargeCzk",
          "createdAt",
          "orderCode",
          "tracking"
        ],
        "properties": {
          "orderId": {
            "type": "string",
            "description": "For GET /orders/{orderId}."
          },
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "service": {
            "$ref": "#/components/schemas/Service"
          },
          "sheets": {
            "type": "integer",
            "description": "Printed sheets."
          },
          "chargeCzk": {
            "type": "integer",
            "description": "Price on prepaid credit, CZK."
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "When the Order was recorded."
          },
          "orderCode": {
            "type": [
              "string",
              "null"
            ],
            "description": "Česká pošta order code. null until handed over."
          },
          "tracking": {
            "type": [
              "string",
              "null"
            ],
            "description": "Česká pošta tracking number. null when it assigned none."
          }
        }
      },
      "OrderPage": {
        "type": "object",
        "required": [
          "data",
          "next_cursor",
          "has_more"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OrderSummary"
            },
            "description": "Newest first."
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ],
            "description": "Pass as `cursor` to read the next page. null on the last page."
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether another page follows this one."
          }
        }
      },
      "PublicOrderStatus": {
        "type": "object",
        "required": [
          "status",
          "service",
          "chargeCzk",
          "orderCode",
          "tracking"
        ],
        "properties": {
          "status": {
            "$ref": "#/components/schemas/OrderStatus"
          },
          "service": {
            "$ref": "#/components/schemas/Service"
          },
          "chargeCzk": {
            "type": "integer",
            "description": "Price on prepaid credit, CZK."
          },
          "orderCode": {
            "type": [
              "string",
              "null"
            ],
            "description": "Česká pošta order code. null until handed over."
          },
          "tracking": {
            "type": [
              "string",
              "null"
            ],
            "description": "Česká pošta tracking number. null when it assigned none."
          }
        }
      },
      "ApiKey": {
        "type": "object",
        "required": [
          "key",
          "accountId"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "The API key (pb_…). Send it as `Authorization: Bearer pb_…`."
          },
          "accountId": {
            "type": "string",
            "description": "The account the key acts for."
          }
        }
      },
      "Error": {
        "type": "object",
        "description": "Every 4xx/5xx body. Some errors add fields: `issues` (400 invalid_letter), `rails` (402), `orderId` (409 duplicate_send), `minCzk`/`maxCzk` (400 bad_amount), `infoUrl`/`contact` (503 sending_paused).",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Stable machine-readable code, e.g. invalid_letter, unauthorized, payment_required, not_found."
          },
          "message": {
            "type": "string",
            "description": "Human-readable cause and how to fix it."
          },
          "docs": {
            "type": "string",
            "format": "uri",
            "description": "Where to read more. Sent when no route answered (not_found, server_error, request_failed)."
          }
        },
        "additionalProperties": true
      }
    },
    "securitySchemes": {
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "pb_...",
        "description": "Postbot API key: `Authorization: Bearer pb_...`."
      },
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth 2.1 authorization code flow. PKCE accepts S256 only, and a public client must use it. Register a client at https://postbot.cz/oauth/register. In this API only POST /keys takes an OAuth access token; the other operations take an API key. The same scopes gate the MCP tools at https://postbot.cz/mcp.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://postbot.cz/oauth/authorize",
            "tokenUrl": "https://postbot.cz/oauth/token",
            "scopes": {
              "letters:send": "Send Letters, which spends the account's prepaid CZK credit, and mint an API key.",
              "letters:read": "Read the status of the account's Letters."
            }
          }
        }
      }
    }
  }
}