{
  "openapi": "3.0.3",
  "info": {
    "title": "SATLOOT fans API",
    "version": "1.0.0",
    "description": "Public content hub. Upload token writes content; admin token manages scoped consumer keys. Read published content without authentication. See /docs for delivery recovery and cursor semantics."
  },
  "servers": [
    {
      "url": "https://fans.satloot.com"
    }
  ],
  "paths": {
    "/api/v1/health": {
      "get": {
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        }
      }
    },
    "/api/v1/stats": {
      "get": {
        "summary": "Published-content statistics",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        }
      }
    },
    "/api/v1/posts": {
      "get": {
        "summary": "Read published posts; after=0 starts an ascending incremental feed",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "before",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "date",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "platform",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "summary": "Upload; source + external_id provides idempotency",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          },
          "201": {
            "description": "Created"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "external_id",
                  "title",
                  "body"
                ],
                "properties": {
                  "source": {
                    "type": "string",
                    "default": "grok-bot",
                    "maxLength": 80
                  },
                  "external_id": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 240
                  },
                  "body": {
                    "type": "string",
                    "maxLength": 60000
                  },
                  "summary": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "author": {
                    "type": "string"
                  },
                  "language": {
                    "type": "string",
                    "default": "zh-CN"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "published",
                      "draft",
                      "archived"
                    ],
                    "default": "published"
                  },
                  "published_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Timezone required. A published post cannot have a future date."
                  },
                  "source_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "tags": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "type": "string"
                    }
                  },
                  "media": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "type": "object",
                      "required": [
                        "type",
                        "url"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "image",
                            "video"
                          ]
                        },
                        "url": {
                          "type": "string",
                          "format": "uri",
                          "pattern": "^https://"
                        },
                        "alt": {
                          "type": "string"
                        },
                        "poster": {
                          "type": "string",
                          "format": "uri"
                        }
                      }
                    }
                  },
                  "platforms": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "type": "string"
                    }
                  },
                  "variants": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "required": [
                        "text"
                      ],
                      "properties": {
                        "title": {
                          "type": "string"
                        },
                        "text": {
                          "type": "string",
                          "maxLength": 60000
                        }
                      }
                    }
                  },
                  "expected_revision": {
                    "type": "integer",
                    "description": "Required for PUT; read the latest revision before changing a post."
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/posts/{post_id}": {
      "get": {
        "summary": "Read one published post",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "parameters": [
          {
            "name": "post_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "put": {
        "summary": "Replace a post using expected_revision (upload token)",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "external_id",
                  "title",
                  "body"
                ],
                "properties": {
                  "source": {
                    "type": "string",
                    "default": "grok-bot",
                    "maxLength": 80
                  },
                  "external_id": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "title": {
                    "type": "string",
                    "maxLength": 240
                  },
                  "body": {
                    "type": "string",
                    "maxLength": 60000
                  },
                  "summary": {
                    "type": "string",
                    "maxLength": 1000
                  },
                  "author": {
                    "type": "string"
                  },
                  "language": {
                    "type": "string",
                    "default": "zh-CN"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "published",
                      "draft",
                      "archived"
                    ],
                    "default": "published"
                  },
                  "published_at": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Timezone required. A published post cannot have a future date."
                  },
                  "source_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "tags": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "type": "string"
                    }
                  },
                  "media": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "type": "object",
                      "required": [
                        "type",
                        "url"
                      ],
                      "properties": {
                        "type": {
                          "type": "string",
                          "enum": [
                            "image",
                            "video"
                          ]
                        },
                        "url": {
                          "type": "string",
                          "format": "uri",
                          "pattern": "^https://"
                        },
                        "alt": {
                          "type": "string"
                        },
                        "poster": {
                          "type": "string",
                          "format": "uri"
                        }
                      }
                    }
                  },
                  "platforms": {
                    "type": "array",
                    "maxItems": 20,
                    "items": {
                      "type": "string"
                    }
                  },
                  "variants": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "object",
                      "required": [
                        "text"
                      ],
                      "properties": {
                        "title": {
                          "type": "string"
                        },
                        "text": {
                          "type": "string",
                          "maxLength": 60000
                        }
                      }
                    }
                  },
                  "expected_revision": {
                    "type": "integer",
                    "description": "Required for PUT; read the latest revision before changing a post."
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "post_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/admin/posts": {
      "get": {
        "summary": "Read drafts and archived posts (upload token)",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "after",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "before",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          },
          {
            "name": "date",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "platform",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/consumers": {
      "post": {
        "summary": "Create one scoped BOT key; token returned once (admin token)",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          },
          "201": {
            "description": "Created"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name",
                  "platforms"
                ],
                "properties": {
                  "name": {
                    "type": "string"
                  },
                  "platforms": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/consumers/{consumer_id}/revoke": {
      "post": {
        "summary": "Revoke a BOT key (admin token)",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "consumer_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/deliveries/claim": {
      "post": {
        "summary": "Atomically claim the next post for one allowed platform (consumer token)",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "platform"
                ],
                "properties": {
                  "platform": {
                    "type": "string"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/deliveries": {
      "get": {
        "summary": "Read this BOT's last 100 delivery records",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/api/v1/deliveries/{delivery_id}/receipt": {
      "post": {
        "summary": "Record success or failure (consumer token + claim token)",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "claim_token",
                  "state"
                ],
                "properties": {
                  "claim_token": {
                    "type": "string"
                  },
                  "state": {
                    "type": "string",
                    "enum": [
                      "sent",
                      "failed"
                    ]
                  },
                  "remote_id": {
                    "type": "string"
                  },
                  "remote_url": {
                    "type": "string",
                    "format": "uri"
                  },
                  "error": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "delivery_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/v1/admin/deliveries": {
      "get": {
        "summary": "Read recent delivery records across BOTs (admin token)",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    },
    "/api/v1/admin/deliveries/{delivery_id}/retry": {
      "post": {
        "summary": "Release failed/expired delivery only after checking it was not published",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "confirmed_not_published"
                ],
                "properties": {
                  "confirmed_not_published": {
                    "type": "boolean",
                    "enum": [
                      true
                    ]
                  }
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "delivery_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/rss.xml": {
      "get": {
        "summary": "RSS 2.0 feed, latest 100 published posts",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        }
      }
    },
    "/feed.json": {
      "get": {
        "summary": "JSON Feed 1.1, latest 100 published posts",
        "responses": {
          "200": {
            "description": "Success"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Invalid token or scope"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not found"
          },
          "409": {
            "description": "Duplicate or revision conflict"
          },
          "429": {
            "description": "Rate limited; wait and retry"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "PostInput": {
        "type": "object",
        "required": [
          "external_id",
          "title",
          "body"
        ],
        "properties": {
          "source": {
            "type": "string",
            "default": "grok-bot",
            "maxLength": 80
          },
          "external_id": {
            "type": "string",
            "maxLength": 200
          },
          "title": {
            "type": "string",
            "maxLength": 240
          },
          "body": {
            "type": "string",
            "maxLength": 60000
          },
          "summary": {
            "type": "string",
            "maxLength": 1000
          },
          "author": {
            "type": "string"
          },
          "language": {
            "type": "string",
            "default": "zh-CN"
          },
          "status": {
            "type": "string",
            "enum": [
              "published",
              "draft",
              "archived"
            ],
            "default": "published"
          },
          "published_at": {
            "type": "string",
            "format": "date-time",
            "description": "Timezone required. A published post cannot have a future date."
          },
          "source_url": {
            "type": "string",
            "format": "uri"
          },
          "tags": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string"
            }
          },
          "media": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "object",
              "required": [
                "type",
                "url"
              ],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": [
                    "image",
                    "video"
                  ]
                },
                "url": {
                  "type": "string",
                  "format": "uri",
                  "pattern": "^https://"
                },
                "alt": {
                  "type": "string"
                },
                "poster": {
                  "type": "string",
                  "format": "uri"
                }
              }
            }
          },
          "platforms": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string"
            }
          },
          "variants": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": [
                "text"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "text": {
                  "type": "string",
                  "maxLength": 60000
                }
              }
            }
          },
          "expected_revision": {
            "type": "integer",
            "description": "Required for PUT; read the latest revision before changing a post."
          }
        }
      }
    }
  }
}
