{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/vera-health/json-schema/vera-health-chat-request-schema.json",
  "title": "ChatRequest",
  "description": "Request envelope for `POST /api/chat/v2`.",
  "x-generated": "2026-10-29",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/vera-health-openapi.json#/components/schemas/ChatRequest",
  "type": "object",
  "required": [
    "question",
    "metadata"
  ],
  "properties": {
    "question": {
      "type": "string",
      "description": "The clinical question to answer.",
      "minLength": 1
    },
    "context": {
      "description": "Optional prior conversation. Accepts either a free-form string or an array of `{role, content}` turns (recommended).",
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/$defs/ConversationTurn"
          }
        }
      ]
    },
    "metadata": {
      "$ref": "#/$defs/ChatMetadata"
    },
    "stream": {
      "type": "boolean",
      "description": "If `true` (default), the response is an SSE stream. If `false`, the response is a single JSON payload returned once the answer is complete.",
      "default": true
    }
  },
  "$defs": {
    "ChatMetadata": {
      "type": "object",
      "required": [
        "source",
        "thread_id",
        "message_id",
        "user_id",
        "timestamp"
      ],
      "description": "Your identifiers and routing fields. Returned **byte-identical** on every response event. Additional fields are accepted and echoed unchanged.",
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "metadata"
          ]
        },
        "source": {
          "type": "string",
          "description": "Your integration identifier. Echoed back unchanged on the non-streaming response. Pipeline routing is keyed off the API key, not this field — `metadata.source` cannot be used to select another partner's config."
        },
        "thread_id": {
          "type": "string",
          "description": "Your thread id. Vera does not interpret it."
        },
        "message_id": {
          "type": "string",
          "description": "Your message id."
        },
        "variation": {
          "type": "string",
          "description": "Free-form experiment / prompt variation tag."
        },
        "user_id": {
          "type": "string",
          "description": "Your end-user id (not a Vera user id)."
        },
        "timestamp": {
          "type": "string",
          "description": "ISO 8601 timestamp."
        }
      },
      "additionalProperties": true
    },
    "ConversationTurn": {
      "type": "object",
      "required": [
        "role",
        "content"
      ],
      "properties": {
        "role": {
          "type": "string",
          "enum": [
            "user",
            "assistant"
          ]
        },
        "content": {
          "type": "string"
        }
      }
    }
  }
}