{
  "openapi": "3.1.0",
  "info": {
    "title": "OnePost development API",
    "version": "0.2.0",
    "description": "Independent OnePost API with owner-scoped Bearer keys, social connections, profiles, media, delivery history and idempotent multi-platform publications. All external integrations use ordinary Bearer API keys; provider tokens remain in OnePost. Monthly entitlements and manual plan assignment are implemented without payments. Runtime and live delivery have not been verified. Analytics for connected Instagram, Facebook, Threads, Telegram and Discord accounts is available with provider limitations and permissions; AI and team workflows remain separate stages. JSON mutations default to 16 KiB; post drafts allow 128 KiB and publications 512 KiB. Provider limits and request-rate limits still apply."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "security": [
    {
      "PostKey": []
    }
  ],
  "paths": {
    "/api/platforms": {
      "get": {
        "summary": "Catalog and server readiness",
        "description": "Public catalog; no account tokens or user connections are included. MCP list_platforms uses the same response with MCP authorization.",
        "security": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "platforms": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Platform"
                      }
                    }
                  },
                  "required": [
                    "platforms"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/profiles": {
      "get": {
        "summary": "List own profiles",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "profiles": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Profile"
                      }
                    }
                  },
                  "required": [
                    "profiles"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "summary": "Create profile",
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "profile": {
                      "$ref": "#/components/schemas/Profile"
                    }
                  },
                  "required": [
                    "profile"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProfileInput"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            },
            "description": "Repeat with the same normalized name and description to return the same profile. Different name or description, or previously deleted profile returns 409. Without this header, each call creates a separate profile."
          }
        ]
      }
    },
    "/api/profiles/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read own profile",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "profile": {
                      "$ref": "#/components/schemas/Profile"
                    }
                  },
                  "required": [
                    "profile"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "summary": "Replace profile",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "profile": {
                      "$ref": "#/components/schemas/Profile"
                    }
                  },
                  "required": [
                    "profile"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProfileInput"
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete profile",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Profile deletion is blocked while drafts or connections reference it."
      }
    },
    "/api/posts": {
      "get": {
        "summary": "List own posts",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "posts": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Post"
                      }
                    }
                  },
                  "required": [
                    "posts"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "summary": "Create post",
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "post": {
                      "$ref": "#/components/schemas/Post"
                    }
                  },
                  "required": [
                    "post"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PostInput"
              }
            }
          }
        }
      }
    },
    "/api/posts/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read own post",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "post": {
                      "$ref": "#/components/schemas/Post"
                    }
                  },
                  "required": [
                    "post"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "patch": {
        "summary": "Replace post",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "post": {
                      "$ref": "#/components/schemas/Post"
                    }
                  },
                  "required": [
                    "post"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PostInput"
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Delete post",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "Deletes local draft, not external posts."
      }
    },
    "/api/connections": {
      "get": {
        "summary": "List own connections without secrets",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connections": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Connection"
                      }
                    }
                  },
                  "required": [
                    "connections"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": ""
      }
    },
    "/api/posts/{id}/publish": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "summary": "Publish a saved draft to one connected target",
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "delivery": {
                      "$ref": "#/components/schemas/Delivery"
                    },
                    "reused": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "delivery"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          },
          "200": {
            "description": "Existing attempt; no new send",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "delivery": {
                      "$ref": "#/components/schemas/Delivery"
                    },
                    "reused": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "delivery"
                  ]
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Draft version in double quotes, e.g. \"POST_VERSION\"; legacy drafts use updatedAt."
          },
          {
            "name": "X-Connection-Version",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "X-Retry-Delivery-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Explicit retry of a retryable failed attempt with identical owner/post/snapshot; new Idempotency-Key required."
          }
        ],
        "description": "Only Telegram/Discord text-photo-video, YouTube video, Dev.to text article. plannedAt must be empty. First attempt returns 201 even for saved failure/uncertainty; inspect delivery.status. An idempotent replay returns 200."
      }
    },
    "/api/deliveries": {
      "get": {
        "summary": "Own delivery history, 100 per page",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deliveries": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Delivery"
                      }
                    },
                    "cursor": {
                      "anyOf": [
                        {
                          "type": "string",
                          "format": "uuid"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "complete": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "deliveries",
                    "cursor",
                    "complete"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "sending",
                "published",
                "failed",
                "uncertain"
              ]
            }
          },
          {
            "name": "platform",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Exact platform ID from the delivery snapshot."
          },
          {
            "name": "profile",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Profile ID from the delivery snapshot; may refer to a removed profile."
          },
          {
            "name": "id",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 200
            },
            "description": "Case-sensitive substring of delivery ID or returned external video/message/article/post ID; includes every Telegram album messageIds element."
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Inclusive createdAt lower bound."
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Exclusive createdAt upper bound."
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Last row ID from previous page; must belong to owner. Keep all filters unchanged between pages."
          }
        ],
        "description": "All filters apply before pagination. Sorted createdAt DESC/id DESC. Statuses may change between pages; refresh to update."
      }
    },
    "/api/deliveries/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read own attempt",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "delivery": {
                      "$ref": "#/components/schemas/Delivery"
                    }
                  },
                  "required": [
                    "delivery"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/deliveries/{id}/check": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "summary": "Check known YouTube session/video or Dev.to article; never creates a new post",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "delivery": {
                      "$ref": "#/components/schemas/Delivery"
                    }
                  },
                  "required": [
                    "delivery"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": " Mastodon: checks only a saved statusId on the original instance/account; requires read:statuses for private statuses. No new status is created; missing access or mismatches remain uncertain."
      }
    },
    "/api/deliveries/{id}/resume": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "post": {
        "summary": "Continue the same YouTube upload after checking accepted offset",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "delivery": {
                      "$ref": "#/components/schemas/Delivery"
                    }
                  },
                  "required": [
                    "delivery"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/media": {
      "get": {
        "summary": "List own uploaded files, 100 per page",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "media": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Media"
                      }
                    },
                    "cursor": {
                      "anyOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "complete": {
                      "type": "boolean"
                    }
                  },
                  "required": [
                    "media",
                    "cursor",
                    "complete"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 512
            }
          }
        ]
      },
      "post": {
        "summary": "Upload a private binary file",
        "responses": {
          "201": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "media": {
                      "$ref": "#/components/schemas/Media"
                    }
                  },
                  "required": [
                    "media"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "X-File-Name",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filename encoded with encodeURIComponent; defaults to media. Up to 200 UTF-16 code units, no control characters or slashes."
          },
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": false,
            "description": "Same key and bytes reuse media.id; different bytes are rejected. A deleted original requires a new key.",
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          },
          {
            "name": "profileId",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Associate the uploaded file with this permitted profile."
          },
          {
            "name": "X-Post-Shorts",
            "in": "header",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "image/jpeg": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "image/png": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "application/pdf": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            },
            "video/mp4": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "description": "JPEG/PNG <=10,000,000 bytes; MP4/PDF <=50,000,000. Short-video mode allows supported MP4/MOV/WebM <=100,000,000 with X-Post-Shorts: 1. Storage <=500,000,000 bytes per owner; provider limits may be stricter. PDF can be published to LinkedIn. File content is private."
      }
    },
    "/api/media/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read own file metadata",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "media": {
                      "$ref": "#/components/schemas/Media"
                    }
                  },
                  "required": [
                    "media"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "summary": "Delete an unused file",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Ok"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "description": "409 while referenced by a saved draft or an unfinished YouTube upload without video ID."
      }
    },
    "/api/media/{id}/content": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "Read own binary file",
        "parameters": [
          {
            "name": "Range",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "One bytes range only; unavailable ranges return 416."
          }
        ],
        "responses": {
          "200": {
            "description": "Private file",
            "headers": {
              "Content-Type": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Length": {
                "schema": {
                  "type": "string"
                }
              },
              "Accept-Ranges": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Range": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "video/mp4": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "206": {
            "description": "Private file",
            "headers": {
              "Content-Type": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Length": {
                "schema": {
                  "type": "string"
                }
              },
              "Accept-Ranges": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Range": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "image/jpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "image/png": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "video/mp4": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "416": {
            "description": "Invalid/unsatisfiable range"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "head": {
        "summary": "Read file headers",
        "responses": {
          "200": {
            "description": "File headers; no body",
            "headers": {
              "Content-Type": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Length": {
                "schema": {
                  "type": "string"
                }
              },
              "Accept-Ranges": {
                "schema": {
                  "type": "string"
                }
              },
              "Content-Range": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/plans": {
      "get": {
        "summary": "List OnePost monthly plans (USD; payments disabled)",
        "security": [],
        "responses": {
          "200": {
            "description": "OnePost plan catalog. External products manage their own subscriptions independently."
          }
        }
      }
    },
    "/api/subscription": {
      "get": {
        "summary": "Read effective entitlement and current monthly usage",
        "description": "Publication quotas are determined by the OnePost plan and Enterprise contract, shared by the dashboard, REST and MCP. Each confirmed successful delivery to a destination account consumes one credit. A confirmed deletion returns that credit when requested through OnePost within 15 minutes of publication. Pending or uncertain deliveries may hold temporary quota reservations. Profiles and connections have no plan limit. Scheduling is available on every plan, with a 30-day horizon and a plan-specific pending queue limit across all projects. See scheduleQuota in /api/capabilities. technicalLimits describes deployment-level request protection independent of plan; API and MCP do not have separate business quotas. HTTP 429 includes Retry-After; code distinguishes rate_limited, concurrency_limited publication_quota_exceeded and schedule_quota_exceeded (pending queue full). HTTP 503 server_busy signals process capacity.",
        "responses": {
          "200": {
            "description": "Subscription, profile/upload limits, used/remaining quota and UTC reset period."
          },
          "401": {
            "description": "Invalid or revoked key"
          }
        }
      }
    },
    "/api/publications": {
      "get": {
        "summary": "Recover a publication by its original Idempotency-Key",
        "description": "Requires posts:read and access to the original profile. Returns the current publication without creating deliveries or consuming credits. Use operationKey from the original POST; do not generate another key after an unknown response.",
        "security": [{"PostKey": []}],
        "parameters": [{"name": "operationKey", "in": "query", "required": true, "schema": {"type": "string", "pattern": "^[A-Za-z0-9_-]{16,128}$"}}],
        "responses": {"200": {"description": "Current publication and per-recipient results", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PublicationResponse"}}}}, "404": {"description": "Unknown publication or unauthorized profile"}}
      },
      "post": {
        "summary": "Publish one material to several connected networks",
        "description": "Publish immediately, schedule for a UTC instant, reserve a profile queue slot, or dispatch in the background. Returns per-network results; uncertain and processing results are not automatically republished. Reusing the same key and request returns the existing publication.",
        "parameters": [
          {
            "in": "header",
            "name": "Idempotency-Key",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{16,128}$"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "title",
                  "text",
                  "format",
                  "platforms",
                  "timezone"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "text": {
                    "type": "string",
                    "maxLength": 10000
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "text",
                      "photo",
                      "video",
                      "document",
                      "carousel"
                    ]
                  },
                  "platforms": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 22,
                    "uniqueItems": true,
                    "items": {
                      "type": "string"
                    }
                  },
                  "connectionVersions": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "string"
                    },
                    "description": "For every selected platform, current version from GET /api/connections."
                  },
                  "mediaIds": {
                    "type": "array",
                    "maxItems": 20,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  },
                  "platformContent": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "title": {
                          "type": "string"
                        },
                        "text": {
                          "type": "string",
                          "maxLength": 10000
                        }
                      }
                    }
                  },
                  "timezone": {
                    "type": "string",
                    "example": "UTC"
                  },
                  "externalId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 255,
                    "description": "Optional caller reference returned with the publication and searchable in delivery history. Separate from Idempotency-Key."
                  },
                  "plannedAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time",
                    "description": "Existing calendar date in UTC ending in Z, up to 30 days ahead. A new publication must be in the future; replaying an accepted Idempotency-Key returns its current status. Mutually exclusive with addToQueue."
                  },
                  "addToQueue": {
                    "type": "boolean",
                    "description": "Reserve the next free slot in the profile queue."
                  },
                  "maxPostsPerSlot": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "description": "Override the profile slot capacity for this request only. Requires addToQueue."
                  },
                  "background": {
                    "type": "boolean",
                    "description": "Dispatch without waiting for delivery. Direct links for immediate background sends are downloaded after acceptance."
                  },
                  "mediaUrls": {
                    "type": "array",
                    "maxItems": 20,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "format": "uri",
                      "maxLength": 2048
                    },
                    "description": "Direct public HTTPS links to up to ten photos, one video, one PDF, or an Instagram carousel of 2–20 JPEG/MP4 files depending on the configured API version. Do not combine with mediaIds."
                  },
                  "firstComment": {
                    "type": "string",
                    "maxLength": 10000,
                    "description": "First comment on supported networks after publication succeeds."
                  },
                  "youtubeOptions": {
                    "$ref": "#/components/schemas/YouTubeOptions"
                  },
                  "tiktokOptions": {
                    "type": "object",
                    "description": "Required for TikTok. Fetch current creator settings and obtain explicit user confirmation first. Set uploadToDraft=true for video inbox uploads; connection must include video.upload. Captions are completed in the TikTok app."
                  },
                  "tiktokConfirmation": {
                    "type": "string",
                    "description": "Selected TikTok account ID; not a provider credential."
                  },
                  "mastodonOptions": {
                    "type": "object",
                    "description": "Required for Mastodon: visibility, sensitive, spoilerText."
                  },
                  "nostrEvent": {
                    "type": "object",
                    "description": "NIP-07 signed event for Nostr; never send a private key."
                  },
                  "recipients": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 1000,
                    "description": "Explicit recipients, each with the current connection version. Every platform must be represented. Replaces connectionVersions.",
                    "items": {
                      "type": "object",
                      "required": [
                        "id",
                        "platform",
                        "version"
                      ],
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "platform": {
                          "type": "string"
                        },
                        "version": {
                          "type": "string"
                        }
                      }
                    }
                  }
                },
                "anyOf": [
                  {
                    "required": [
                      "recipients"
                    ]
                  },
                  {
                    "required": [
                      "connectionVersions"
                    ]
                  }
                ]
              },
              "example": {
                "profileId": "11111111-1111-4111-8111-111111111111",
                "title": "My publication",
                "text": "Reviewed text",
                "format": "text",
                "platforms": [
                  "telegram"
                ],
                "recipients": [
                  {
                    "id": "22222222-2222-4222-8222-222222222222",
                    "platform": "telegram",
                    "version": "33333333-3333-4333-8333-333333333333"
                  }
                ],
                "mediaIds": [],
                "timezone": "Europe/Warsaw",
                "plannedAt": null
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing publication; no new send.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PublicationResponse"}}}
          },
          "201": {
            "description": "Publication created, with individual statuses and delivery IDs.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PublicationResponse"}}}
          },
          "202": {
            "description": "Immediate background publication with linked media accepted before download.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PublicationResponse"}}}
          },
          "400": {
            "description": "Invalid parameters or unsupported format."
          },
          "403": {
            "description": "Profile or platform not available under current plan."
          },
          "409": {
            "description": "Idempotency conflict or an operation is still active."
          },
          "412": {
            "description": "A connection changed; refresh before confirming again."
          },
          "429": {
            "description": "Quota or request limit reached."
          }
        },
        "x-codeSamples": [
          {
            "lang": "bash",
            "label": "cURL",
            "source": "# Run in Bash; require an origin, never a path or credentials.\nif ! [[ \"$POST_BASE_URL\" =~ ^https://[^/@?#[:space:]]+/?$ ||\n        \"$POST_BASE_URL\" =~ ^http://(localhost|127[.]0[.]0[.]1)(:[0-9]+)?/?$ ]]; then\n  printf '%s\\n' 'POST_BASE_URL must be an HTTPS origin (HTTP only on localhost)' >&2\n  exit 1\nfi\nPOST_BASE_URL=\"${POST_BASE_URL%/}\"\n# POST_PAYLOAD_FILE points to the reviewed publication.json below.\n# Reuse POST_REQUEST_ID for this material; do not generate it on each retry.\ncurl --fail-with-body --max-time 120 \\\n  \"$POST_BASE_URL/api/publications\" \\\n  -H \"Authorization: Bearer $POST_API_KEY\" \\\n  -H \"Idempotency-Key: $POST_REQUEST_ID\" \\\n  -H 'Content-Type: application/json' \\\n  --data-binary \"@$POST_PAYLOAD_FILE\"\n# Save publication.id from the response, then read its individual results:\ncurl --fail-with-body --max-time 30 \\\n  \"$POST_BASE_URL/api/publications/PUBLICATION_ID\" \\\n  -H \"Authorization: Bearer $POST_API_KEY\""
          },
          {
            "lang": "javascript",
            "label": "JavaScript · Node 22+",
            "source": "// Save as publish.mjs; run: node publish.mjs\nimport { readFile } from 'node:fs/promises';\nconst { POST_BASE_URL: base, POST_API_KEY: key,\n  POST_REQUEST_ID: requestId, POST_PAYLOAD_FILE: file } = process.env;\nif (!base || !key || !file || !/^[A-Za-z0-9_-]{16,128}$/.test(requestId || ''))\n  throw new Error('Set POST_BASE_URL, POST_API_KEY, POST_REQUEST_ID and POST_PAYLOAD_FILE');\nconst origin = new URL(base);\nif (!origin.hostname || origin.username || origin.password || origin.search || origin.hash ||\n    !['', '/'].includes(origin.pathname) ||\n    !(origin.protocol === 'https:' || origin.protocol === 'http:' && ['localhost', '127.0.0.1'].includes(origin.hostname)))\n  throw new Error('POST_BASE_URL must be an HTTPS origin (HTTP only on localhost)');\nasync function api(path, body) {\n  const response = await fetch(new URL(path, origin.origin), {\n    method: body === undefined ? 'GET' : 'POST', redirect: 'error',\n    signal: AbortSignal.timeout(120000),\n    headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json',\n      ...(body === undefined ? {} : { 'Idempotency-Key': requestId }) }, body,\n  });\n  const data = await response.json();\n  if (!response.ok) throw new Error(`HTTP ${response.status}: ${data.error}; Retry-After=${response.headers.get('retry-after')}`);\n  return data;\n}\nconst payload = await readFile(file, 'utf8');\nJSON.parse(payload); // Reject malformed JSON before sending.\nconst { publication } = await api('/api/publications', payload);\nconsole.log('Save publication ID:', publication.id);\nconsole.log(JSON.stringify(await api('/api/publications/' + publication.id), null, 2));\n// A successful HTTP response is not proof that every recipient was published."
          },
          {
            "lang": "python",
            "label": "Python 3 · standard library",
            "source": "# Save as publish.py; run: python3 publish.py\nimport json, os, re\nfrom pathlib import Path\nfrom urllib.request import Request, build_opener, HTTPRedirectHandler\nfrom urllib.error import HTTPError\nfrom urllib.parse import urlsplit\n\nclass NoRedirect(HTTPRedirectHandler):\n    def redirect_request(self, req, fp, code, msg, headers, newurl):\n        return None\n\nbase = os.environ['POST_BASE_URL'].rstrip('/')\norigin = urlsplit(base)\nif (not origin.hostname or origin.username is not None or origin.password is not None or\n        origin.path not in ('', '/') or origin.query or origin.fragment or\n        not (origin.scheme == 'https' or origin.scheme == 'http' and origin.hostname in ('localhost', '127.0.0.1'))):\n    raise ValueError('POST_BASE_URL must be an HTTPS origin (HTTP only on localhost)')\nif origin.port is not None and not 1 <= origin.port <= 65535:\n    raise ValueError('Invalid Post port')\nkey = os.environ['POST_API_KEY']\nrequest_id = os.environ['POST_REQUEST_ID']\nif not re.fullmatch(r'[A-Za-z0-9_-]{16,128}', request_id):\n    raise ValueError('POST_REQUEST_ID must be 16-128 letters/digits/_/-')\nopener = build_opener(NoRedirect())\ndef api(path, body=None):\n    headers = {'Authorization': 'Bearer ' + key, 'Content-Type': 'application/json'}\n    if body is not None:\n        headers['Idempotency-Key'] = request_id\n    try:\n        with opener.open(Request(base + path, data=body, headers=headers), timeout=120) as response:\n            return json.load(response)\n    except HTTPError as error:\n        raise RuntimeError(f'HTTP {error.code}; Retry-After={error.headers.get(\"Retry-After\")}; ' + error.read().decode('utf-8')) from None\npayload = Path(os.environ['POST_PAYLOAD_FILE']).read_bytes()\njson.loads(payload)\npublication = api('/api/publications', payload)['publication']\nprint('Save publication ID:', publication['id'])\nprint(json.dumps(api('/api/publications/' + publication['id']), ensure_ascii=False, indent=2))\n# No automatic retry; inspect every recipient status."
          },
          {
            "lang": "swift",
            "label": "Swift 6.2+ · Foundation",
            "source": "// Save as Publish.swift. Build: swiftc -parse-as-library Publish.swift -o publish\n// Run ./publish on your server or local CLI, never distribute the secret in an app.\nimport Foundation\n#if canImport(FoundationNetworking)\nimport FoundationNetworking\n#endif\n\nfinal class NoRedirect: NSObject, URLSessionTaskDelegate, Sendable {\n    func urlSession(_ session: URLSession, task: URLSessionTask,\n        willPerformHTTPRedirection response: HTTPURLResponse, newRequest request: URLRequest,\n        completionHandler: @escaping @Sendable (URLRequest?) -> Void) {\n        completionHandler(nil)\n    }\n}\nstruct Envelope: Decodable, Sendable {\n    struct Publication: Decodable, Sendable { let id: String }\n    let publication: Publication\n}\n@main struct Publish {\n    static func main() async throws {\n        let env = ProcessInfo.processInfo.environment\n        guard let base = env[\"POST_BASE_URL\"], let key = env[\"POST_API_KEY\"],\n              let requestID = env[\"POST_REQUEST_ID\"], let file = env[\"POST_PAYLOAD_FILE\"],\n              requestID.range(of: \"^[A-Za-z0-9_-]{16,128}$\", options: .regularExpression) != nil\n        else { throw NSError(domain: \"Set Post environment variables\", code: 1) }\n        guard let components = URLComponents(string: base), let host = components.host,\n              !host.isEmpty, components.user == nil, components.password == nil,\n              components.query == nil, components.fragment == nil,\n              components.path.isEmpty || components.path == \"/\",\n              components.port == nil || (1...65535).contains(components.port!),\n              components.scheme == \"https\" || components.scheme == \"http\" && [\"localhost\", \"127.0.0.1\"].contains(host),\n              let origin = components.url\n        else { throw URLError(.badURL) }\n        let config = URLSessionConfiguration.ephemeral\n        config.timeoutIntervalForRequest = 120\n        config.timeoutIntervalForResource = 120\n        let session = URLSession(configuration: config, delegate: NoRedirect(), delegateQueue: nil)\n        defer { session.invalidateAndCancel() }\n        func api(_ path: String, body: Data? = nil) async throws -> Data {\n            guard let url = URL(string: path, relativeTo: origin)\n            else { throw URLError(.badURL) }\n            var request = URLRequest(url: url)\n            request.httpMethod = body == nil ? \"GET\" : \"POST\"\n            request.httpBody = body\n            request.setValue(\"Bearer \" + key, forHTTPHeaderField: \"Authorization\")\n            request.setValue(\"application/json\", forHTTPHeaderField: \"Content-Type\")\n            if body != nil { request.setValue(requestID, forHTTPHeaderField: \"Idempotency-Key\") }\n            let (data, response) = try await session.data(for: request)\n            guard let http = response as? HTTPURLResponse else { throw URLError(.badServerResponse) }\n            guard (200..<300).contains(http.statusCode) else {\n                throw NSError(domain: \"Post\", code: http.statusCode,\n                    userInfo: [NSLocalizedDescriptionKey: String(decoding: data, as: UTF8.self)])\n            }\n            return data\n        }\n        let payload = try Data(contentsOf: URL(fileURLWithPath: file))\n        let created = try await api(\"/api/publications\", body: payload)\n        let id = try JSONDecoder().decode(Envelope.self, from: created).publication.id\n        print(\"Save publication ID:\", id)\n        let status = try await api(\"/api/publications/\" + id)\n        print(String(decoding: status, as: UTF8.self))\n    }\n}"
          },
          {
            "lang": "kotlin",
            "label": "Kotlin 2.4+ · JDK 11+",
            "source": "@file:DependsOn(\"org.jetbrains.kotlinx:kotlinx-serialization-json:1.11.0\")\n// Save as Publish.main.kts; run: kotlin Publish.main.kts\n// main-kts resolves the JSON library; no serialization compiler plugin is needed.\nimport java.net.URI\nimport java.net.http.HttpClient\nimport java.net.http.HttpRequest\nimport java.net.http.HttpResponse\nimport java.nio.file.Files\nimport java.nio.file.Path\nimport java.time.Duration\nimport kotlinx.serialization.json.*\n\nval base = requireNotNull(System.getenv(\"POST_BASE_URL\")).trimEnd('/')\nval origin = URI.create(base)\nrequire(!origin.host.isNullOrEmpty() && origin.rawUserInfo == null &&\n    origin.rawQuery == null && origin.rawFragment == null && origin.rawPath in listOf(\"\", \"/\") &&\n    (origin.port == -1 || origin.port in 1..65535) &&\n    (origin.scheme == \"https\" || origin.scheme == \"http\" && origin.host in listOf(\"localhost\", \"127.0.0.1\"))) {\n    \"POST_BASE_URL must be an HTTPS origin (HTTP only on localhost)\"\n}\nval key = requireNotNull(System.getenv(\"POST_API_KEY\"))\nval requestID = requireNotNull(System.getenv(\"POST_REQUEST_ID\"))\nrequire(Regex(\"^[A-Za-z0-9_-]{16,128}$\").matches(requestID))\nval client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(30))\n    .followRedirects(HttpClient.Redirect.NEVER).build()\nfun api(path: String, body: String? = null): JsonObject {\n    val builder = HttpRequest.newBuilder(URI.create(base + path))\n        .timeout(Duration.ofSeconds(120)).header(\"Authorization\", \"Bearer \" + key)\n        .header(\"Content-Type\", \"application/json\")\n    if (body == null) builder.GET() else builder.header(\"Idempotency-Key\", requestID)\n        .POST(HttpRequest.BodyPublishers.ofString(body))\n    val response = client.send(builder.build(), HttpResponse.BodyHandlers.ofString())\n    check(response.statusCode() in 200..299) {\n        \"HTTP ${response.statusCode()}; Retry-After=${response.headers().firstValue(\"Retry-After\").orElse(\"\")}; ${response.body()}\"\n    }\n    return Json.parseToJsonElement(response.body()).jsonObject\n}\nval payload = Files.readString(Path.of(requireNotNull(System.getenv(\"POST_PAYLOAD_FILE\"))))\nJson.parseToJsonElement(payload)\nval created = api(\"/api/publications\", payload)\nval id = created.getValue(\"publication\").jsonObject.getValue(\"id\").jsonPrimitive.content\nprintln(\"Save publication ID: \" + id)\nprintln(api(\"/api/publications/\" + id))\n// No automatic retry. Review per-recipient results, including uncertain."
          }
        ]
      }
    },
    "/api/publications/{publicationId}": {
      "get": {
        "summary": "Read own publication and per-network delivery results",
        "parameters": [
          {
            "in": "path",
            "name": "publicationId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Publication with current content and schedule revision. content contains title, text, firstComment, platformContent and mediaIds, using accepted edits where present. This is a local read, not a provider request. Before editing, show the current content and send the confirmed revision in If-Match; merge existing platformContent to preserve other networks.",
            "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PublicationResponse"}}}
          },
          "404": {
            "description": "Publication not found for this key owner."
          }
        }
      },
      "patch": {
        "summary": "Edit a pending scheduled publication",
        "description": "Requires posts:write, scheduling entitlement and access to the profile. Cannot change recipients or send an already started material. Supply If-Match with the quoted schedule revision to reject concurrent edits.",
        "parameters": [
          {
            "name": "publicationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "minProperties": 1,
                "additionalProperties": false,
                "properties": {
                  "plannedAt": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "format": "date-time",
                    "description": "UTC timestamp ending in Z, up to 30 days ahead. Mutually exclusive with addToQueue."
                  },
                  "timezone": {
                    "type": "string",
                    "example": "UTC"
                  },
                  "title": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 100
                  },
                  "text": {
                    "type": "string",
                    "maxLength": 10000
                  },
                  "firstComment": {
                    "type": "string",
                    "maxLength": 10000,
                    "description": "First comment on supported networks after publication succeeds."
                  },
                  "platformContent": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "properties": {
                        "title": {
                          "type": "string"
                        },
                        "text": {
                          "type": "string",
                          "maxLength": 10000
                        }
                      }
                    }
                  },
                  "mediaIds": {
                    "type": "array",
                    "maxItems": 20,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated publication and revision.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PublicationResponse"}}}
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "summary": "Cancel a scheduled publication before dispatch",
        "parameters": [
          {
            "name": "publicationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "If-Match",
            "in": "header",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled publication; an already started send is not cancelled.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/PublicationResponse"}}}
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/publications/{publicationId}/check/{platform}": {
      "post": {
        "summary": "Check processing without republishing",
        "parameters": [
          {
            "in": "path",
            "name": "publicationId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "platform",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated publication."
          },
          "404": {
            "description": "Not found for current owner."
          },
          "409": {
            "description": "Original delivery is unknown, not ready or still active; no automatic new publication."
          }
        }
      }
    },
    "/api/publications/{publicationId}/resume/{platform}": {
      "post": {
        "summary": "Explicitly confirm a previously prepared publication",
        "parameters": [
          {
            "in": "path",
            "name": "publicationId",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "path",
            "name": "platform",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Updated publication."
          },
          "404": {
            "description": "Not found for current owner."
          },
          "409": {
            "description": "Original delivery is unknown, not ready or still active; no automatic new publication."
          }
        }
      }
    },
    "/api/analytics": {
      "get": {
        "summary": "Read analytics for connected accounts and posts",
        "description": "Owner-scoped provider data, daily history, collection status and explicit unavailable metrics. First request starts background collection; subsequent requests return persistent snapshots. Cached for 15 minutes; fresh=1 starts a refresh at most once per minute. OnePost metrics are lifetime counters, not increments during a selected date range. Telegram Bot API has no post views; Discord has no reach. Meta insights require the corresponding provider permission and account authorization.",
        "parameters": [
          {
            "name": "profile",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Limit to an authorized profile, including local publication queries, visible profile links, cache and daily history. Provider account-wide metrics remain account-wide. This selector never expands key permissions."
          },
          {
            "name": "fresh",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Snapshots and collection state",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "accounts": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    },
                    "history": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "additionalProperties": true
                      }
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication required"
          },
          "404": {
            "description": "Profile not found"
          }
        }
      }
    },
    "/api/connections/operations": {
      "get":{"summary":"Read a direct credential connection operation","description":"Requires connections:read and original profile authorization. Direct POST connection endpoints optionally accept Idempotency-Key. Pending does not authorize an automatic second attempt; read or cancel the original operation. No credentials or request signatures are returned.","security":[{"PostKey":[]}],"parameters":[{"name":"operationKey","in":"query","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9_-]{16,128}$"}}],"responses":{"200":{"description":"operation: platform, profileId, state (pending/connected/failed/cancelled), connectionId and optional failure status"},"404":{"description":"Unknown operation or unauthorized profile"}}},
      "delete":{"summary":"Cancel an uncommitted direct connection operation","description":"Requires connections:write and original profile authorization. A cancelled operation cannot later commit an account. Does not disconnect a committed account. For an unknown direct operation, also provide profileId and platform to record cancellation before a late creation.","security":[{"PostKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["operationKey","confirm"],"properties":{"operationKey":{"type":"string","pattern":"^[A-Za-z0-9_-]{16,128}$"},"confirm":{"const":true},"profileId":{"type":"string"},"platform":{"type":"string"}}}}}},"responses":{"200":{"description":"Operation cancelled"},"404":{"description":"Unknown operation or unauthorized profile"},"409":{"description":"Account already committed"}}}
    },
    "/api/connections/sessions": {
      "delete":{"summary":"Cancel an OAuth operation even before session creation","description":"Requires connections:write and original profile authorization. Provide operationKey and confirm=true; profileId and platform are required for an operation not yet registered. Atomically records cancellation and stops any existing uncommitted session. A later POST with the same key cannot create a session. Does not disconnect a committed account.","security":[{"PostKey":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["operationKey","confirm"],"properties":{"operationKey":{"type":"string","pattern":"^[A-Za-z0-9_-]{16,128}$"},"confirm":{"const":true},"profileId":{"type":"string","format":"uuid"},"platform":{"type":"string"}}}}}},"responses":{"200":{"description":"Cancellation recorded; session.id may be null if creation never happened"},"409":{"description":"Account already committed or operation context differs"}}},
      "get": {
        "summary":"Recover a connection session by its operation key",
        "description":"Requires connections:read and authorization for the original profile. Returns the original session ID and phase without tokens, provider parameters or authorizeUrl. A committed account ID is retained for new operations after transient session expiry; expired means no committed account is recorded. A 404 is not proof that a concurrent creation cannot still complete.",
        "security":[{"PostKey":[]}],
        "parameters":[{"name":"operationKey","in":"query","required":true,"schema":{"type":"string","pattern":"^[A-Za-z0-9_-]{16,128}$"}}],
        "responses":{"200":{"description":"Original session; phase includes expired."},"403":{"description":"Missing connections:read"},"404":{"description":"Operation absent or original profile not authorized"}}
      },
      "post": {
        "parameters": [{"name":"Idempotency-Key","in":"header","required":false,"schema":{"type":"string","pattern":"^[A-Za-z0-9_-]{16,128}$"},"description":"Stable operation key. Identical retries return the original session. A started session has no new authorizeUrl; use its phase/status. Expired sessions return 410 instead of creating another."}],
        "summary": "Create a one-time social authorization URL",
        "description": "Requires connections:write and access to profileId. Open authorizeUrl in the user browser; it does not require a OnePost login. The URL expires in 300 seconds and is single use. Provider state and browser-binding cookies remain enforced. Never put an API key in the browser. Provider parameters come from GET /api/platforms oauthForm.fields.",
        "security": [
          {
            "PostKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "platform",
                  "profileId"
                ],
                "properties": {
                  "platform": {
                    "type": "string"
                  },
                  "profileId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "reconnectConnectionId": {
                    "type": "string",
                    "pattern": "^[a-f0-9-]{36}(?:-[a-z_]+)?$",
                    "description": "Optional active connection in this profile. The OAuth result must have the same external account identity; another account or a disconnected target is rejected before credentials are saved."
                  },
                  "parameters": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {"description":"Idempotent replay. Returns session with current phase, connectionId and selectionId. authorizeUrl and expiresIn are present only while phase=pending and the original ticket is valid.","content":{"application/json":{"schema":{"type":"object","required":["session","reused"],"properties":{"session":{"type":"object"},"reused":{"const":true},"authorizeUrl":{"type":"string","format":"uri"},"expiresIn":{"type":"integer","minimum":0}}}}}},
          "201": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session": {
                      "type": "object",
                      "required": [
                        "id",
                        "platform",
                        "profileId",
                        "phase"
                      ],
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "platform": {
                          "type": "string"
                        },
                        "profileId": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "phase": {
                          "type": "string",
                          "enum": [
                            "pending",
                            "started",
                            "selection_required",
                            "connected",
                            "cancelled",
                            "failed"
                          ]
                        },
                        "connectionId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "selectionId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    },
                    "authorizeUrl": {
                      "type": "string",
                      "format": "uri"
                    },
                    "expiresIn": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; no connection is granted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; no connection is granted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; no connection is granted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Request rejected; no connection is granted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/connections/sessions/{sessionId}/authorize-url": {
      "post": {
        "summary":"Recover the original unused connection URL",
        "description":"Requires connections:write and profile access. Returns the same unexpired one-time ticket only for an idempotently created pending session with live original authorization. Does not create a session, renew a ticket or restart OAuth.",
        "security":[{"PostKey":[]}],
        "parameters":[{"name":"sessionId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],
        "responses":{"200":{"description":"Original authorizeUrl and remaining expiresIn; no-store"},"409":{"description":"Session started or no recoverable operation"},"410":{"description":"Session/ticket expired or ticket consumed"}}
      }
    },
    "/api/connections/sessions/{sessionId}": {
      "delete": {
        "summary": "Cancel an unfinished social connection session",
        "description": "Requires connections:write and access to the session profile. Stops pending, started or selection-required connection before an account is committed. Does not disconnect an already connected account. Repeated confirmed cancellation is safe while the session exists.",
        "security": [{"PostKey": []}],
        "parameters": [{"name":"sessionId","in":"path","required":true,"schema":{"type":"string","format":"uuid"}}],
        "requestBody": {"required":true,"content":{"application/json":{"schema":{"type":"object","required":["confirm"],"properties":{"confirm":{"const":true}}}}}},
        "responses": {"200":{"description":"Session phase is cancelled"},"409":{"description":"Account already committed or session expired"},"410":{"description":"Session expired"}}
      },
      "get": {
        "summary": "Read social authorization result",
        "description": "Requires connections:read and access to the session profile. For selection_required, use GET/POST /api/connections/facebook/selection/{selectionId} or /api/connections/youtube/selection/{selectionId}. Complete selection using pageId or channelId. No provider tokens or API keys are returned.",
        "security": [
          {
            "PostKey": []
          }
        ],
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session": {
                      "type": "object",
                      "required": [
                        "id",
                        "platform",
                        "profileId",
                        "phase"
                      ],
                      "properties": {
                        "id": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "platform": {
                          "type": "string"
                        },
                        "profileId": {
                          "type": "string",
                          "format": "uuid"
                        },
                        "phase": {
                          "type": "string",
                          "enum": [
                            "pending",
                            "started",
                            "selection_required",
                            "connected",
                            "failed"
                          ]
                        },
                        "connectionId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        },
                        "selectionId": {
                          "type": [
                            "string",
                            "null"
                          ]
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Request rejected; no connection is granted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Request rejected; no connection is granted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Request rejected; no connection is granted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "Request rejected; no connection is granted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/capabilities": {
      "get": {
        "summary": "Read current plan, publication quota and authorized actions",
        "description": "Available to any authenticated active API key without requiring subscription:read. Describes only the current key permissions, plan and shared quota; no arbitrary token lookup. Requires subscription:read. Combines the OnePost plan, current shared quota, selected key scopes and profile restrictions. null quota limit/remaining means unlimited. Actions express authorization, not completed provider setup. No secrets are returned. Provider-specific validation and social account connections remain required.",
        "security": [
          {
            "PostKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "plan, quota (unit=delivery, limit/used/reserved/remaining/deletionRefundWindowMinutes/startsAt/resetsAt), scheduleQuota (unit=post, limit/used/remaining/daysAhead), accountQuota (unit=profile_account, limit/used/remaining counts account assignments across all profiles; unassigned connections are unlimited; null limit/remaining means unlimited), technicalLimits, authorization (permissions/profileIds), actions, platforms and note."
          },
          "401": {
            "description": "Invalid or revoked key"
          },
          "403": {
            "description": "Missing subscription:read permission"
          },
          "429": {
            "description": "Shared technical rate limit; Retry-After is returned."
          }
        }
      }
    },
    "/api/connections/{connectionId}/telegram-senders": {
      "parameters": [
        {
          "name": "connectionId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "summary": "List Telegram-authorized sender identities for this destination",
        "description": "Requires a native Telegram account connection and connections:read. Does not publish or change the sender. Provider session secrets are never returned.",
        "responses": {
          "200": {
            "description": "Allowed senders",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "senders"
                  ],
                  "properties": {
                    "senders": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "required": [
                          "id",
                          "name"
                        ],
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "premiumRequired": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/{connectionId}/categories": {
      "parameters": [
        {
          "name": "connectionId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "summary": "Assignable YouTube categories for own connection",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          }
                        },
                        "required": [
                          "id",
                          "title"
                        ]
                      }
                    },
                    "regionCode": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "categories",
                    "regionCode"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "regionCode",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Z]{2}$"
            }
          }
        ],
        "description": ""
      }
    },
    "/api/connections/telegram": {
      "post": {
        "summary": "Connect telegram using supplied credentials",
        "description": "Requires connections:write. Provider credentials remain on the server. Connecting does not publish content. Use GET /api/platforms connectionForm for current setup notes and fields. A non-empty profileId attaches the API-created connection to that profile.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "botToken",
                  "chatId"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "description": "Profile UUID, or empty string for an unassigned account with an unrestricted key."
                  },
                  "botToken": {
                    "type": "string",
                    "description": "Bot token",
                    "maxLength": 256
                  },
                  "chatId": {
                    "type": "string",
                    "description": "Channel",
                    "maxLength": 33
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection metadata without secrets."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/discord": {
      "post": {
        "summary": "Connect a Discord webhook manually as a superadmin",
        "description": "Superadmin only. API keys also require connections:write. Other users connect through a Discord OAuth session. Connecting does not publish content.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "webhookUrl"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "description": "Profile UUID, or empty string for an unassigned account with an unrestricted key."
                  },
                  "webhookUrl": {
                    "type": "string",
                    "description": "URL webhook",
                    "maxLength": 512
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection metadata without secrets."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/devto": {
      "post": {
        "summary": "Connect devto using supplied credentials",
        "description": "Requires connections:write. Provider credentials remain on the server. Connecting does not publish content. Use GET /api/platforms connectionForm for current setup notes and fields. A non-empty profileId attaches the API-created connection to that profile.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "apiKey"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "description": "Profile UUID, or empty string for an unassigned account with an unrestricted key."
                  },
                  "apiKey": {
                    "type": "string",
                    "description": "API key",
                    "maxLength": 256
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection metadata without secrets."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/mastodon": {
      "post": {
        "summary": "Connect mastodon using supplied credentials",
        "description": "Requires connections:write. Provider credentials remain on the server. Connecting does not publish content. Use GET /api/platforms connectionForm for current setup notes and fields. A non-empty profileId attaches the API-created connection to that profile.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "instance",
                  "accessToken"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "description": "Profile UUID, or empty string for an unassigned account with an unrestricted key."
                  },
                  "instance": {
                    "type": "string",
                    "description": "Server",
                    "maxLength": 512
                  },
                  "accessToken": {
                    "type": "string",
                    "description": "Access token",
                    "maxLength": 1024
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection metadata without secrets."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/hashnode": {
      "post": {
        "summary": "Connect hashnode using supplied credentials",
        "description": "Requires connections:write. Provider credentials remain on the server. Connecting does not publish content. Use GET /api/platforms connectionForm for current setup notes and fields. A non-empty profileId attaches the API-created connection to that profile.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "token",
                  "publicationId"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "description": "Profile UUID, or empty string for an unassigned account with an unrestricted key."
                  },
                  "token": {
                    "type": "string",
                    "description": "Personal Access Token",
                    "maxLength": 2048
                  },
                  "publicationId": {
                    "type": "string",
                    "description": "Publication ID",
                    "pattern": "[a-f0-9]{24}"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection metadata without secrets."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/lemmy": {
      "post": {
        "summary": "Connect lemmy using supplied credentials",
        "description": "Requires connections:write. Login uses the official API of the selected public HTTPS Lemmy instance; password and optional TOTP are not stored. Returns selectionId and subscribed/moderated communities. Find another community by name with GET /api/connections/lemmy/selection/{selectionId}?name=community, then POST choiceId to connect. The selection expires after 10 minutes and must use the original owner/key. Connecting does not publish content. Legacy token/communityId payloads remain supported. Managed login sessions are logged out on disconnect; history is retained.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "instance"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "description": "Profile UUID, or empty string for an unassigned account with an unrestricted key."
                  },
                  "instance": {
                    "type": "string",
                    "description": "Server"
                  },
                  "token": {
                    "type": "string",
                    "description": "Session token",
                    "maxLength": 4096,
                    "deprecated": true
                  },
                  "communityId": {
                    "type": "string",
                    "description": "Community ID",
                    "deprecated": true
                  },
                  "username": {
                    "type": "string",
                    "maxLength": 254,
                    "description": "Lemmy username or email on the selected instance."
                  },
                  "password": {
                    "type": "string",
                    "format": "password",
                    "writeOnly": true,
                    "maxLength": 1024
                  },
                  "totp": {
                    "type": "string",
                    "pattern": "^[0-9]{6}$",
                    "writeOnly": true,
                    "description": "Optional current TOTP code when two-factor authentication is enabled."
                  }
                },
                "oneOf": [
                  {
                    "required": [
                      "username",
                      "password"
                    ]
                  },
                  {
                    "required": [
                      "token",
                      "communityId"
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "selection_required with selectionId and choices, or connection metadata for a legacy token payload. Never returns provider credentials."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/lemmy/selection/{selectionId}": {
      "parameters": [
        {
          "name": "selectionId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "List or find Lemmy communities for an authenticated selection",
        "description": "Requires connections:read and access to the pending profile with the original owner/key. Returns choices; no credentials. Optional name finds a local or federated community by name or name@server.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "parameters": [
          {
            "name": "name",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 255
            }
          }
        ]
      },
      "post": {
        "summary": "Connect the selected Lemmy community",
        "description": "Requires connections:write, the original owner/key and access to the pending profile. Consumes selection atomically; rechecks the account, community and unchanged connection.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "choiceId"
                ],
                "properties": {
                  "choiceId": {
                    "type": "string",
                    "description": "ID returned in choices; do not construct it manually."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connected account metadata."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/whop": {
      "post": {
        "summary": "Connect whop using supplied credentials",
        "description": "Requires connections:write. Provider credentials remain on the server. Connecting does not publish content. Use GET /api/platforms connectionForm for current setup notes and fields. A non-empty profileId attaches the API-created connection to that profile.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "apiKey",
                  "experienceId"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "description": "Profile UUID, or empty string for an unassigned account with an unrestricted key."
                  },
                  "apiKey": {
                    "type": "string",
                    "description": "API key",
                    "maxLength": 4096
                  },
                  "experienceId": {
                    "type": "string",
                    "description": "Forum experience ID",
                    "pattern": "exp_[A-Za-z0-9]{1,100}"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection metadata without secrets."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/listmonk": {
      "post": {
        "summary": "Connect listmonk using supplied credentials",
        "description": "Requires connections:write. Provider credentials remain on the server. Connecting does not publish content. Use GET /api/platforms connectionForm for current setup notes and fields. A non-empty profileId attaches the API-created connection to that profile.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "instance",
                  "username",
                  "token",
                  "listId",
                  "senderName",
                  "postalAddress"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "description": "Profile UUID, or empty string for an unassigned account with an unrestricted key."
                  },
                  "instance": {
                    "type": "string",
                    "description": "Server"
                  },
                  "username": {
                    "type": "string",
                    "description": "API user",
                    "maxLength": 100
                  },
                  "token": {
                    "type": "string",
                    "description": "API token",
                    "maxLength": 2048
                  },
                  "listId": {
                    "type": "string",
                    "description": "List ID"
                  },
                  "senderName": {
                    "type": "string",
                    "description": "Sender name or organization",
                    "maxLength": 100
                  },
                  "postalAddress": {
                    "type": "string",
                    "description": "Valid sender mailing address",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection metadata without secrets."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/{connectionId}": {
      "parameters": [
        {
          "name": "connectionId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "patch": {
        "summary": "Attach a social account to a profile or remove its profile association",
        "description": "Requires connections:write and access to the profile and connection. linked=false does not revoke provider credentials.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId",
                  "linked"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "format": "uuid"
                  },
                  "linked": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated connection metadata."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "delete": {
        "summary": "Disconnect an account without deleting published history",
        "description": "Requires connections:write. A profile-scoped key cannot disconnect an account used by inaccessible profiles.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/facebook/selection/{selectionId}": {
      "parameters": [
        {
          "name": "selectionId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "List authorized facebook accounts for selection",
        "description": "Requires connections:read. Returns profileId and pages; no provider tokens are returned.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "summary": "Complete facebook account selection",
        "description": "Requires connections:write and access to the pending profile.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "pageId"
                ],
                "properties": {
                  "pageId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connected account metadata."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/youtube/selection/{selectionId}": {
      "parameters": [
        {
          "name": "selectionId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "get": {
        "summary": "List authorized youtube accounts for selection",
        "description": "Requires connections:read. Returns profileId and channels; no provider tokens are returned.",
        "responses": {
          "200": {
            "description": "Success"
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      },
      "post": {
        "summary": "Complete youtube account selection",
        "description": "Requires connections:write and access to the pending profile.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "channelId"
                ],
                "properties": {
                  "channelId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connected account metadata."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/nostr/challenge": {
      "post": {
        "summary": "Request an NIP-07 connection event",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "profileId"
                ],
                "properties": {
                  "profileId": {
                    "type": "string",
                    "format": "uuid"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "challenge and event; expires in 60 seconds."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/connections/nostr": {
      "post": {
        "summary": "Connect Nostr using the signed challenge",
        "description": "Sign the exact event with an NIP-07 extension. Never send a private key.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "challenge",
                  "event"
                ],
                "properties": {
                  "challenge": {
                    "type": "string"
                  },
                  "event": {
                    "type": "object"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection metadata."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/api/media/import": {
      "post": {
        "summary": "Import media from a direct public HTTPS URL",
        "description": "Requires media:write. Same file validation, SSRF restrictions and storage limits as binary upload.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "maxLength": 2048
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Imported media metadata."
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        }
      }
    },
    "/bluesky-client-metadata.json": {
      "get": {
        "tags": [
          "Connections"
        ],
        "summary": "Public AT Protocol OAuth client metadata",
        "description": "Available when Bluesky OAuth is configured. Contains public verification keys only; never the private client key.",
        "security": [],
        "responses": {
          "200": {
            "description": "OAuth client metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "404": {
            "description": "Bluesky OAuth is not configured"
          }
        }
      }
    },
    "/api/deliveries/{id}/publication": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "format": "uuid"
          }
        }
      ],
      "delete": {
        "summary": "Delete an external publication while retaining delivery history",
        "description": "Requires posts:publish and access to the delivery profile. Supported adapters: Telegram (within 48 hours), Discord, Facebook, Instagram via Facebook Login, Threads, Bluesky, Mastodon, YouTube, Pinterest, Reddit, LinkedIn, Hashnode, Lemmy API v4. Lemmy verifies the original instance/author/community and confirms deleted=true; deleted_on_origin does not guarantee immediate deletion across federation. Hashnode uses removePost with Pro and author/admin rights; deletion.providerStatus is soft_deleted. This removes the post from feeds but does not guarantee erasure or prevent direct GraphQL retrieval by ID.postMessage. Historic incoming webhook messages cannot be deleted through OnePost.manage, and retains the original delivery and local media file. LinkedIn uses the saved share/ugcPost URN, verifies the original member/app and active w_member_social grant, and requires HTTP 204. Reading the post with restricted r_member_social is not required. Organization posts are not supported by this adapter. Reddit requires edit and verifies the original account, author and subreddit, then confirms deletion markers with api/info. Unknown results stay uncertain; comments by other users may remain. Pinterest requires boards:read, boards:write, pins:read, pins:write; older connections may require reauthorization. The original owned pin and board are verified; HTTP 204 or a matching HTTP 200 Pin response confirms deletion. YouTube deletion is permanent and requires youtube.force-ssl (older connections must reauthorize); the original video/channel is verified before deletion and HTTP 204 confirms success. Mastodon requires the original instance/account and write:statuses, plus read:statuses for private posts. A confirmed deleted result is idempotent; unknown results are not represented as successful deletion. Nostr requires an externally signed NIP-09 kind 5 event by the original author with exactly e=original event ID and k=1 tags. It is sent to the original configured relays. An accepted request returns deletion.status=requested, never deleted; erasure across relays and clients is not guaranteed. Provider restrictions and permissions apply.",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "delivery": {
                      "$ref": "#/components/schemas/Delivery"
                    }
                  },
                  "required": [
                    "delivery"
                  ]
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": false,
          "description": "For Nostr, supply the signed event on the first request; an uncertain request can reuse its saved event. Never send private keys. Other adapters need no body.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "event": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "PostKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Post API key",
        "description": "Owner-scoped pst.* key created in the dashboard. Each key has explicit action scopes and either selected profileIds or null for all current and future profiles. A key never expands plan entitlements. Legacy keys without a policy retain their existing access. Never send social access tokens here."
      }
    },
    "schemas": {
      "PublicationResponse": {
        "type": "object",
        "required": ["publication"],
        "properties": {
          "publication": {
            "type": "object",
            "required": ["id", "profileId", "format", "createdAt", "dueAt", "background", "timezone", "revision", "phase", "status", "content", "results"],
            "properties": {
              "id": {"type": "string", "format": "uuid"},
              "externalId": {"type": "string"},
              "profileId": {"type": "string", "format": "uuid"},
              "format": {"type": "string"},
              "createdAt": {"type": "string", "format": "date-time"},
              "dueAt": {"type": ["string", "null"], "format": "date-time"},
              "background": {"type": "boolean"},
              "timezone": {"type": ["string", "null"]},
              "revision": {"type": "integer", "minimum": 0},
              "phase": {"type": "string", "description": "Current dispatch phase; interrupted and preparing require inspection, not a new publication."},
              "status": {"type": "string", "enum": ["pending", "completed"]},
              "content": {"type": "object", "required": ["title", "text", "firstComment", "platformContent", "mediaIds"], "properties": {"title": {"type": "string"}, "text": {"type": "string"}, "firstComment": {"type": "string"}, "platformContent": {"type": "object", "additionalProperties": {"type": "object"}}, "mediaIds": {"type": "array", "items": {"type": "string", "format": "uuid"}}}},
              "results": {"type": "array", "items": {"type": "object", "required": ["platform", "recipientId", "status", "deliveryId", "result", "error"], "properties": {"platform": {"type": "string"}, "recipientId": {"type": "string"}, "connectionVersion": {"type": "string"}, "postId": {"type": "string", "format": "uuid"}, "status": {"type": "string"}, "deliveryId": {"type": ["string", "null"], "format": "uuid"}, "result": {"anyOf": [{"$ref": "#/components/schemas/DeliveryResult"}, {"type": "null"}]}, "error": {"type": ["string", "null"]}}}}
            }
          },
          "reused": {"type": "boolean", "description": "Present on idempotent replay of POST."}
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "code": {
            "type": "string",
            "description": "Optional machine-readable error code."
          }
        },
        "required": [
          "error"
        ]
      },
      "Ok": {
        "type": "object",
        "properties": {
          "ok": {
            "const": true
          }
        },
        "required": [
          "ok"
        ]
      },
      "ProfileInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Trimmed to 1–100 UTF-16 code units; no CR/LF."
          },
          "description": {
            "type": "string",
            "maxLength": 300,
            "description": "Optional short profile description, trimmed. Preserved on update when omitted."
          }
        },
        "required": [
          "name"
        ]
      },
      "Profile": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string",
            "maxLength": 300
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "name",
          "createdAt",
          "updatedAt"
        ]
      },
      "Platform": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "instagram",
              "tiktok",
              "youtube",
              "linkedin",
              "facebook",
              "threads",
              "pinterest",
              "bluesky",
              "discord",
              "telegram",
              "mastodon",
              "nostr",
              "lemmy",
              "devto",
              "hashnode",
              "whop",
              "listmonk",
              "reddit"
            ]
          },
          "name": {
            "type": "string"
          },
          "connection": {
            "type": "string"
          },
          "formats": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "text",
                "photo",
                "video",
                "document",
                "carousel"
              ]
            }
          },
          "implemented": {
            "type": "boolean"
          },
          "connectionAvailable": {
            "type": "boolean"
          },
          "minimumConnectionRole": {
            "type": "string",
            "enum": ["free", "basic", "professional", "advanced", "enterprise", "admin", "superadmin"]
          },
          "canConnect": {
            "type": "boolean",
            "description": "Whether the current account can connect this platform."
          },
          "manualConnectionMinimumRole": {
            "const": "superadmin",
            "description": "Minimum role for entering a Discord webhook URL."
          },
          "canConnectManually": {
            "type": "boolean",
            "description": "Whether the current account can enter a Discord webhook URL."
          },
          "publishingFormats": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "text",
                "photo",
                "video",
                "document",
                "carousel"
              ]
            }
          },
          "connectionForm": {
            "type": [
              "object",
              "null"
            ],
            "description": "Title, notes and fields for direct credential connection. Fields contain name, label, type, required, pattern and length constraints."
          },
          "oauthForm": {
            "type": [
              "object",
              "null"
            ],
            "description": "Notes and parameters required before requesting an OAuth session."
          },
          "connectEndpoint": {
            "type": "string"
          },
          "analyticsMode": {
            "type": "string",
            "enum": ["provider", "scoped_history", "relay_counts", "not_implemented"],
            "description": "Implemented collector source. scoped_history uses authorized OnePost delivery history and available provider data; relay_counts returns separate relay-local counts without a global aggregate; not_implemented describes a OnePost implementation gap. Does not grant plan or provider access."
          },
          "analyticsNote": {
            "type": "string",
            "description": "Collector scope, required consent and missing metrics. Missing metrics must not be treated as zero."
          },
          "deletionMode": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "delete",
              "trash",
              "soft_delete",
              "request",
              "origin_only",
              null
            ],
            "description": "Implemented OnePost adapter behavior, not proof that a specific delivery can be deleted. Null means unavailable in this deployment; see deletionNote. request does not confirm erasure."
          },
          "deletionNote": {
            "type": "string",
            "description": "Provider/deployment restrictions and known limitations of publication deletion. Returned by the catalog and capabilities, including MCP."
          }
        },
        "required": [
          "id",
          "name",
          "connection",
          "formats",
          "implemented",
          "connectionAvailable",
          "publishingFormats"
        ]
      },
      "Connection": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "version": {
            "type": "string",
            "format": "uuid"
          },
          "profileId": {
            "type": "string",
            "format": "uuid"
          },
          "platform": {
            "type": "string",
            "enum": [
              "instagram",
              "tiktok",
              "youtube",
              "linkedin",
              "facebook",
              "threads",
              "pinterest",
              "bluesky",
              "discord",
              "telegram",
              "mastodon",
              "nostr",
              "lemmy",
              "devto",
              "hashnode",
              "whop",
              "listmonk",
              "reddit"
            ]
          },
          "name": {
            "type": "string"
          },
          "connectedAt": {
            "type": "string",
            "format": "date-time"
          },
          "channelId": {
            "type": "string"
          },
          "chatId": {
            "type": "string"
          },
          "teamId": {
            "type": "string"
          },
          "guildId": {
            "type": "string"
          },
          "accountId": {
            "type": "string"
          },
          "username": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "webhookId": {
            "type": "string"
          },
          "botId": {
            "type": "string"
          },
          "instance": {
            "type": "string",
            "format": "uri",
            "description": "Canonical Mastodon HTTPS origin."
          },
          "site": {
            "type": "string",
            "description": "Connected HTTPS site root."
          },
          "profileIds": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            }
          }
        },
        "required": [
          "id",
          "version",
          "profileId",
          "platform",
          "name",
          "connectedAt"
        ],
        "description": "Provider metadata only; secrets are never returned. Connect through scoped API keys or the dashboard; OAuth starts through one-time connection sessions."
      },
      "Media": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "kind": {
            "enum": [
              "photo",
              "video",
              "document"
            ]
          },
          "mime": {
            "enum": [
              "image/jpeg",
              "image/png",
              "video/mp4",
              "application/pdf"
            ]
          },
          "size": {
            "type": "integer",
            "minimum": 1
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "width": {
            "type": "integer"
          },
          "height": {
            "type": "integer"
          }
        },
        "required": [
          "id",
          "name",
          "kind",
          "mime",
          "size",
          "sha256",
          "createdAt"
        ]
      },
      "YouTubeOptions": {
        "type": "object",
        "properties": {
          "categoryId": {
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[0-9]{1,10}$"
              },
              {
                "type": "null"
              }
            ]
          },
          "privacy": {
            "enum": [
              "private",
              "unlisted",
              "public"
            ]
          },
          "madeForKids": {
            "type": [
              "boolean",
              "null"
            ]
          },
          "containsSyntheticMedia": {
            "type": "boolean"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Up to 500 characters including separators and quotes."
          },
          "defaultLanguage": {
            "type": "string",
            "maxLength": 35
          },
          "notifySubscribers": {
            "type": "boolean"
          },
          "embeddable": {
            "type": "boolean"
          },
          "publicStatsViewable": {
            "type": "boolean"
          },
          "hasPaidProductPlacement": {
            "type": "boolean"
          },
          "license": {
            "enum": [
              "youtube",
              "creativeCommon"
            ]
          },
          "recordingDate": {
            "type": "string",
            "format": "date-time",
            "description": "UTC timestamp ending in Z."
          },
          "playlistIds": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,128}$"
            }
          },
          "caption": {
            "$ref": "#/components/schemas/YouTubeCaptionTrack"
          },
          "extraCaptions": {
            "type": "array",
            "maxItems": 3,
            "items": {
              "$ref": "#/components/schemas/YouTubeCaptionTrack"
            }
          },
          "thumbnailMediaId": {
            "type": "string",
            "format": "uuid",
            "description": "ID of a JPEG or PNG in the account media library."
          }
        },
        "required": [
          "privacy",
          "madeForKids",
          "containsSyntheticMedia"
        ],
        "description": "YouTube video settings. Caption tracks have a combined limit of 64 KiB and must be distinct by language and name."
      },
      "YouTubeCaptionTrack": {
        "type": "object",
        "required": [
          "text",
          "language"
        ],
        "properties": {
          "text": {
            "type": "string",
            "description": "SRT or WebVTT file contents."
          },
          "language": {
            "type": "string",
            "maxLength": 35,
            "example": "en-US"
          },
          "name": {
            "type": "string",
            "maxLength": 150,
            "default": "Post"
          }
        }
      },
      "PlatformContent": {
        "type": "object",
        "propertyNames": {
          "type": "string",
          "enum": [
            "instagram",
            "tiktok",
            "x",
            "youtube",
            "linkedin",
            "facebook",
            "threads",
            "pinterest",
            "bluesky",
            "discord",
            "telegram",
            "mastodon",
            "nostr",
            "lemmy",
            "devto",
            "hashnode",
            "whop",
            "listmonk",
            "reddit"
          ]
        },
        "properties": {
          "linkedin": {
            "type": "object",
            "properties": {
              "autoLinkCard": {
                "type": "boolean",
                "description": "Tracks the composer choice. True marks a link attachment generated from the caption, false disables automatic link attachments in this draft."
              },
              "imageAlt": {
                "type": "object",
                "description": "Alternative text by LinkedIn photo media ID.",
                "additionalProperties": { "type": "string", "maxLength": 4000 }
              }
            }
          },
          "instagram": {
            "type": "object",
            "properties": {
              "imageAlt": {
                "type": "object",
                "description": "Alternative text by photo media ID. Supports images in feed posts and carousels.",
                "additionalProperties": { "type": "string", "maxLength": 500 }
              }
            }
          },
          "facebook": {
            "type": "object",
            "properties": {
              "imageAlt": {
                "type": "object",
                "description": "Alternative text by photo media ID for Page feed posts.",
                "additionalProperties": { "type": "string", "maxLength": 500 }
              }
            }
          },
          "mastodon": {
            "type": "object",
            "properties": {
              "imageAlt": {
                "type": "object",
                "description": "Alternative text by photo media ID. The account server can enforce a lower limit.",
                "additionalProperties": { "type": "string", "maxLength": 1500 }
              },
              "threadParts": {
                "type": "array", "minItems": 2, "maxItems": 25,
                "items": { "type": "string", "minLength": 1, "maxLength": 10000 },
                "description": "Ordered text parts of a Mastodon thread. Publication media applies to the first part. The account server's current character limit applies to each part."
              },
              "threadReplyMediaIds": {
                "type": "array", "minItems": 1, "maxItems": 24,
                "description": "Photo media IDs per reply, excluding the first post. Use an empty array for a reply without photos. The account server's media limits apply.",
                "items": { "type": "array", "maxItems": 4, "uniqueItems": true,
                  "items": { "type": "string", "format": "uuid" } }
              },
              "threadReplyImageAlt": {
                "type": "array", "minItems": 1, "maxItems": 24,
                "description": "Optional alternative text by photo ID for each reply. Entries align with threadReplyMediaIds; use an empty object when a reply has no descriptions.",
                "items": { "type": "object", "maxProperties": 4,
                  "additionalProperties": { "type": "string", "maxLength": 1500 } }
              }
            }
          },
          "x": {
            "type": "object",
            "properties": {
              "threadParts": {
                "type": "array",
                "minItems": 2,
                "maxItems": 25,
                "items": { "type": "string", "minLength": 1 },
                "description": "Ordered text parts of an X thread. Each part is limited to 280 weighted characters. Publication media applies to the first part."
              },
              "threadReplyMediaIds": {
                "type": "array", "minItems": 1, "maxItems": 24,
                "description": "Photo media IDs per reply, excluding the first post. Use an empty array for a reply without photos. Each reply accepts up to four JPEG or PNG images of up to 5 MB.",
                "items": { "type": "array", "maxItems": 4, "uniqueItems": true,
                  "items": { "type": "string", "format": "uuid" } }
              },
              "threadReplyImageAlt": {
                "type": "array", "minItems": 1, "maxItems": 24,
                "description": "Optional alternative text by photo ID for each reply. Entries align with threadReplyMediaIds; use an empty object when a reply has no descriptions.",
                "items": { "type": "object", "maxProperties": 4,
                  "additionalProperties": { "type": "string", "maxLength": 1000 } }
              }
            }
          },
          "threads": {
            "type": "object",
            "properties": {
              "threadParts": {
                "type": "array",
                "minItems": 2,
                "maxItems": 25,
                "items": { "type": "string", "minLength": 1, "maxLength": 500 },
                "description": "Ordered text parts of a Threads thread. An image, video, or photo carousel applies to the first post. Polls and long text attachments are incompatible."
              }
            }
          },
          "telegram": {
            "type": "object",
            "description": "Bot or native account publishing. Stories and sendAs require a native account connection. Private messages are not supported. Telegram enforces permissions, boosts and rate limits.",
            "properties": {
              "text": {
                "type": "string",
                "maxLength": 10000
              },
              "mediaType": {
                "enum": [
                  "STORIES"
                ],
                "description": "Omit for a regular post. Stories require one photo or MP4 video and expire after 24 hours."
              },
              "storyPrivacy": {
                "enum": [
                  "contacts",
                  "everyone"
                ],
                "default": "contacts",
                "description": "Audience for personal Stories. Channels and groups use Telegram audience rules."
              },
              "sendAs": {
                "type": "string",
                "pattern": "^-?[1-9][0-9]{0,24}$",
                "description": "Only an id returned by the selected connection telegram-senders endpoint."
              },
              "parseMode": {
                "enum": [
                  "HTML",
                  "MarkdownV2"
                ],
                "description": "MarkdownV2 is available through Bot API only; omit for plain text."
              },
              "asDocument": {
                "type": "boolean"
              },
              "hasSpoiler": {
                "type": "boolean"
              }
            }
          },
          "bluesky": {
            "type": "object",
            "description": "Text: up to 300 graphemes and 3000 UTF-8 bytes. Attach up to four JPEG/PNG images of 2,000,000 bytes each, or one MP4 within the media library limits. Video processing uses the existing check/resume publication endpoints; resume after video_ready creates the post. Provider account limits still apply.",
            "properties": {
              "title": {
                "type": "string",
                "maxLength": 100
              },
              "text": {
                "type": "string",
                "maxLength": 10000,
                "description": "The provider-specific grapheme and byte limits are enforced before publication."
              },
              "threadParts": {
                "type": "array", "minItems": 2, "maxItems": 25,
                "items": { "type": "string", "minLength": 1 },
                "description": "Ordered text parts of a Bluesky thread, at most 300 graphemes and 3000 UTF-8 bytes per part. Publication media applies to the first part."
              },
              "threadReplyMediaIds": {
                "type": "array", "minItems": 1, "maxItems": 24,
                "description": "Photo media IDs per reply, excluding the first post. Provide an empty array for each reply without photos. Each reply accepts up to four JPEG or PNG images of up to 2 MB.",
                "items": { "type": "array", "maxItems": 4, "uniqueItems": true,
                  "items": { "type": "string", "format": "uuid" } }
              },
              "threadReplyImageAlt": {
                "type": "array", "minItems": 1, "maxItems": 24,
                "description": "Optional alternative text by photo ID for each reply. Entries align with threadReplyMediaIds; use an empty object when a reply has no descriptions.",
                "items": { "type": "object", "maxProperties": 4,
                  "additionalProperties": { "type": "string", "maxLength": 2000 } }
              },
              "imageAlt": {
                "type": "object",
                "description": "Image media IDs mapped to alternative text.",
                "additionalProperties": {
                  "type": "string",
                  "maxLength": 2000
                }
              },
              "altText": {
                "type": "string",
                "maxLength": 500,
                "description": "Alternative text for video."
              }
            }
          }
        },
        "additionalProperties": {
          "type": "object",
          "properties": {
            "title": {
              "type": "string",
              "maxLength": 100
            },
            "text": {
              "type": "string",
              "maxLength": 10000
            }
          }
        }
      },
      "PostInput": {
        "type": "object",
        "properties": {
          "profileId": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string",
            "description": "Trimmed to 1–100 UTF-16 code units; no CR/LF."
          },
          "shortsTitleMode": {
            "type": "string",
            "enum": ["auto", "manual", "empty"],
            "description": "Optional Shorts editor state. A draft can keep an empty title field while retaining its saved display title."
          },
          "text": {
            "type": "string",
            "maxLength": 10000,
            "description": "Server counts UTF-16 code units."
          },
          "format": {
            "type": "string",
            "enum": [
              "text",
              "photo",
              "video",
              "document",
              "carousel"
            ]
          },
          "platforms": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "instagram",
                "tiktok",
                "youtube",
                "linkedin",
                "facebook",
                "threads",
                "pinterest",
                "bluesky",
                "discord",
                "telegram",
                "mastodon",
                "nostr",
                "lemmy",
                "devto",
                "hashnode",
                "whop",
                "listmonk",
                "reddit"
              ]
            },
            "maxItems": 22,
            "description": "Must support selected format; duplicates are normalized. Immediate publishing requires exactly one supported target."
          },
          "platformContent": {
            "$ref": "#/components/schemas/PlatformContent"
          },
          "mediaUrls": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uri",
              "maxLength": 2048
            },
            "maxItems": 20,
            "uniqueItems": true,
            "default": [],
            "description": "Public HTTPS references, mutually exclusive with mediaIds. Saved in drafts; direct draft publish rejects non-empty URLs. Use /api/publications to import and publish URL media. Omission clears URLs on full replacement."
          },
          "firstComment": {
            "type": "string",
            "maxLength": 10000,
            "default": "",
            "description": "Optional first comment for supported platforms and granted provider permissions. Omission clears it on full draft replacement."
          },
          "mediaIds": {
            "type": "array",
            "items": {
              "type": "string",
              "format": "uuid"
            },
            "maxItems": 20,
            "uniqueItems": true,
            "default": [],
            "description": "Full replacement; omission removes attachments. text: none; photo: up to 10; video: one supported video; document: one PDF (publishing currently supported by LinkedIn); carousel: 2–20 JPEG/MP4 files for Instagram, subject to maxCarouselItems in GET /api/platforms."
          },
          "youtubeOptions": {
            "$ref": "#/components/schemas/YouTubeOptions"
          },
          "plannedAt": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "timezone": {
            "type": "string",
            "description": "Valid IANA timezone, e.g. Europe/Warsaw."
          },
          "mastodonOptions": {
            "$ref": "#/components/schemas/MastodonOptions"
          }
        },
        "required": [
          "profileId",
          "title",
          "text",
          "format",
          "platforms",
          "timezone"
        ],
        "description": "Draft JSON body limit: 16 KiB. PATCH uses the same replacement contract, not partial merge. Saving never publishes; plannedAt is a desired draft date, not a scheduled job."
      },
      "Snapshot": {
        "type": "object",
        "properties": {
          "platform": {
            "type": "string",
            "description": "Platform identifier recorded when the delivery was created, including retired integrations."
          },
          "profileId": {
            "type": "string",
            "format": "uuid"
          },
          "title": {
            "type": "string"
          },
          "text": {
            "type": "string"
          },
          "format": {
            "type": "string",
            "enum": [
              "text",
              "photo",
              "video",
              "document",
              "carousel"
            ]
          },
          "media": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Media"
            }
          },
          "account": {
            "type": "string"
          },
          "accountId": {
            "type": "string"
          },
          "channelId": {
            "type": "string"
          },
          "chatId": {
            "type": "string"
          },
          "teamId": {
            "type": "string"
          },
          "guildId": {
            "type": "string"
          },
          "webhookId": {
            "type": "string"
          },
          "botId": {
            "type": "string"
          },
          "youtubeTitle": {
            "type": "string"
          },
          "articleTitle": {
            "type": "string"
          },
          "categoryId": {
            "type": "string"
          },
          "youtubeOptions": {
            "$ref": "#/components/schemas/YouTubeOptions"
          },
          "mastodonOptions": {
            "$ref": "#/components/schemas/MastodonOptions"
          },
          "site": {
            "type": "string",
            "description": "Original connected site root."
          }
        },
        "required": [
          "platform",
          "profileId",
          "title",
          "text",
          "format",
          "media",
          "account"
        ]
      },
      "DeliveryResult": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "phase": {
            "type": "string"
          },
          "providerStatus": {
            "type": "integer"
          },
          "url": {
            "anyOf": [
              {
                "type": "string",
                "format": "uri"
              },
              {
                "type": "null"
              }
            ]
          },
          "messageId": {
            "type": "string"
          },
          "messageIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "videoId": {
            "type": "string"
          },
          "articleId": {
            "type": "string"
          },
          "attachmentIds": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "accepted": {
            "type": "boolean"
          },
          "confirmation": {
            "type": "string"
          },
          "safeRetry": {
            "type": "boolean"
          },
          "bytesAccepted": {
            "type": "integer"
          },
          "totalBytes": {
            "type": "integer"
          },
          "privacy": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "uploadStatus": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "processingStatus": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "statusId": {
            "type": "string",
            "description": "Mastodon status ID; its presence prevents a new automatic submission."
          }
        }
      },
      "Delivery": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "postId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "sending",
              "published",
              "failed",
              "uncertain"
            ]
          },
          "snapshot": {
            "$ref": "#/components/schemas/Snapshot"
          },
          "result": {
            "anyOf": [
              {
                "$ref": "#/components/schemas/DeliveryResult"
              },
              {
                "type": "null"
              }
            ]
          },
          "retryable": {
            "type": "boolean"
          },
          "retryOf": {
            "anyOf": [
              {
                "type": "string",
                "format": "uuid"
              },
              {
                "type": "null"
              }
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "postId",
          "status",
          "snapshot",
          "result",
          "retryable",
          "retryOf",
          "createdAt",
          "updatedAt"
        ],
        "description": "published confirms provider result; YouTube includes processing and chosen privacy. uncertain must not be blindly retried."
      },
      "Post": {
        "allOf": [
          {
            "$ref": "#/components/schemas/PostInput"
          },
          {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "format": "uuid"
              },
              "version": {
                "type": "string",
                "format": "uuid"
              },
              "status": {
                "const": "draft"
              },
              "media": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Media"
                }
              },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "updatedAt": {
                "type": "string",
                "format": "date-time"
              }
            },
            "required": [
              "id",
              "version",
              "status",
              "media",
              "createdAt",
              "updatedAt"
            ]
          }
        ],
        "properties": {
          "mastodonOptions": {
            "$ref": "#/components/schemas/MastodonOptions"
          }
        }
      },
      "MastodonOptions": {
        "type": "object",
        "required": [
          "visibility",
          "sensitive",
          "spoilerText"
        ],
        "properties": {
          "visibility": {
            "enum": [
              null,
              "public",
              "unlisted",
              "private",
              "direct"
            ],
            "description": "Must be explicitly selected before publishing."
          },
          "sensitive": {
            "type": "boolean"
          },
          "spoilerText": {
            "type": "string",
            "maxLength": 10000
          }
        }
      }
    },
    "responses": {
      "Error": {
        "description": "JSON error. Common statuses 400/401/403/404/405/409/412/413/429/500/502/503. Delivery failures can also be saved in a successful publish response.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
