{
  "openapi": "3.1.0",
  "info": {
    "title": "PoseyAI Chat API",
    "version": "1.0.0",
    "description": "Streaming chat completions with tool use (web search, image generation) and optional persisted conversation history. Powered by Nate Posey & Co."
  },
  "servers": [
    {
      "url": "/",
      "description": "Same-origin"
    }
  ],
  "paths": {
    "/api/chat": {
      "post": {
        "summary": "Stream an assistant reply",
        "description": "Sends a conversation to PoseyAI and streams the reply back as a UI message stream. When a bearer token and threadId are supplied, the user message and the assistant reply are persisted to that conversation; otherwise the call runs in guest mode with no storage.",
        "security": [
          {
            "bearerAuth": []
          },
          {}
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChatRequest"
              },
              "example": {
                "threadId": "5f9c1c1e-0a2b-4c1d-9f11-6f0d2a3b4c5d",
                "messages": [
                  {
                    "id": "msg_1",
                    "role": "user",
                    "parts": [
                      {
                        "type": "text",
                        "text": "Summarise this quarter's AI funding news."
                      }
                    ]
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Server-sent UI message stream of the assistant reply.",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request body — `messages` must be an array."
          },
          "401": {
            "description": "Session expired or invalid bearer token."
          },
          "404": {
            "description": "Conversation not found for this user."
          },
          "500": {
            "description": "AI or backend not configured."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "ChatRequest": {
        "type": "object",
        "required": [
          "messages"
        ],
        "properties": {
          "messages": {
            "type": "array",
            "description": "Full conversation history in UI message format.",
            "items": {
              "$ref": "#/components/schemas/UIMessage"
            }
          },
          "threadId": {
            "type": "string",
            "format": "uuid",
            "description": "Conversation to persist to. Omit for guest mode (nothing is written to the database)."
          }
        }
      },
      "UIMessage": {
        "type": "object",
        "required": [
          "role",
          "parts"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "user",
              "assistant",
              "system"
            ]
          },
          "parts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/MessagePart"
            }
          }
        }
      },
      "MessagePart": {
        "type": "object",
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "text",
              "file"
            ],
            "description": "`text` for prose, `file` for image or document attachments."
          },
          "text": {
            "type": "string"
          },
          "mediaType": {
            "type": "string",
            "example": "application/pdf"
          },
          "url": {
            "type": "string",
            "description": "Data URL or https URL of the attachment."
          }
        }
      }
    }
  }
}