{
  "openapi": "3.1.0",
  "info": {
    "title": "C∞A∞I∞O chat API (public visitor endpoints)",
    "version": "1.0.0",
    "summary": "Talk to C∞A∞I∞O's AI chat bot, read its help articles, and hand the chat to a human (a real person).",
    "description": "These are the same public endpoints the chat widget on https://chrismai.ai calls. No API key, no OAuth: access is scoped per workspace (`workspace_id`) and per conversation (the `visitor_id` you choose acts as the conversation's secret; keep it private).\n\nTypical flow: `GET /api/widget/config` -> `POST /api/widget/conversations` with your first `message` -> read `messages` in the response -> `POST /api/widget/conversations/{id}/messages` for follow-ups -> optionally `POST .../email` so a human can reply by email, or `POST .../handoff` to ask for a human.\n\nEvery conversation is stored and visible to a human on our team (the business owner) in the operator inbox. Use it for real questions on behalf of a real person; do not send automated test traffic. Human replies are not instant (`reply_time` in the config); poll `GET /api/widget/conversations/{id}` sparingly, or leave an email.\n\nLimits: messages up to 2000 characters, 60 messages per conversation, 20 new conversations and 40 messages per 10 minutes per IP (`RateLimit-Limit`, `RateLimit-Remaining`, `Retry-After` headers).\n\nServer note: C∞A∞I∞O's widget calls the same-origin endpoint listed below (it serves the live site). The production host chatwithhuman.chrismai.ai is not open to non-browser clients yet. This document will be updated if the host changes.\n\nNot offered here: payments, accounts, OAuth, MCP or A2A. Every project is quoted per project; there is no public price list (https://chrismai.ai/llms.txt). Contact: _@schizophrenicfreak.dev",
    "contact": {
      "name": "C∞A∞I∞O",
      "email": "_@schizophrenicfreak.dev",
      "url": "https://chrismai.ai/"
    },
    "license": {
      "name": "Proprietary",
      "identifier": "LicenseRef-Proprietary"
    }
  },
  "security": [
    {}
  ],
  "servers": [
    {
      "url": "https://chrismai.ai/api/chat",
      "description": "Chat Worker currently serving the C∞A∞I∞O widget"
    }
  ],
  "externalDocs": {
    "description": "Human-readable guide",
    "url": "https://chrismai.ai/docs/api"
  },
  "tags": [
    {
      "name": "chat",
      "description": "Visitor conversations with the AI bot and a human"
    },
    {
      "name": "system",
      "description": "Health"
    }
  ],
  "paths": {
    "/api/widget/config": {
      "get": {
        "tags": [
          "chat"
        ],
        "operationId": "getWidgetConfig",
        "summary": "Workspace greeting, contact, availability and help articles",
        "parameters": [
          {
            "name": "workspace_id",
            "in": "query",
            "required": true,
            "description": "Workspace id. C∞A∞I∞O's own chat is `chrismai`.",
            "schema": {
              "type": "string",
              "examples": [
                "chrismai"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WidgetConfig"
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed for this workspace (`origin_not_allowed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown workspace or conversation (`unknown_workspace`, `unknown_conversation`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/widget/articles": {
      "get": {
        "tags": [
          "chat"
        ],
        "operationId": "searchArticles",
        "summary": "Help articles (FAQ), optionally filtered by a search string; best match first",
        "parameters": [
          {
            "name": "workspace_id",
            "in": "query",
            "required": true,
            "description": "Workspace id. C∞A∞I∞O's own chat is `chrismai`.",
            "schema": {
              "type": "string",
              "examples": [
                "chrismai"
              ]
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Search text (up to 200 characters)",
            "schema": {
              "type": "string",
              "maxLength": 200,
              "examples": [
                "price"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "articles"
                  ],
                  "properties": {
                    "articles": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Article"
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed for this workspace (`origin_not_allowed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown workspace or conversation (`unknown_workspace`, `unknown_conversation`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/widget/conversations": {
      "get": {
        "tags": [
          "chat"
        ],
        "operationId": "listConversations",
        "summary": "Your recent conversations (up to 20) for a visitor id",
        "parameters": [
          {
            "name": "workspace_id",
            "in": "query",
            "required": true,
            "description": "Workspace id. C∞A∞I∞O's own chat is `chrismai`.",
            "schema": {
              "type": "string",
              "examples": [
                "chrismai"
              ]
            }
          },
          {
            "name": "visitor_id",
            "in": "query",
            "required": true,
            "description": "The visitor id you created the conversation with.",
            "schema": {
              "$ref": "#/components/schemas/VisitorId"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConversationList"
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed for this workspace (`origin_not_allowed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown workspace or conversation (`unknown_workspace`, `unknown_conversation`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "chat"
        ],
        "operationId": "startConversation",
        "summary": "Start a conversation, optionally with the first message (the AI bot answers in the response)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StartConversationRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Conversation created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConversationTurn"
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed for this workspace (`origin_not_allowed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown workspace or conversation (`unknown_workspace`, `unknown_conversation`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "message longer than 2000 characters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited per IP (see `Retry-After`) or the conversation hit its 60-message limit (`conversation_limit`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/widget/conversations/{id}": {
      "get": {
        "tags": [
          "chat"
        ],
        "operationId": "getConversation",
        "summary": "Conversation state and full transcript (poll for a human reply)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "conversation_id returned when the conversation was created.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "visitor_id",
            "in": "query",
            "required": true,
            "description": "The visitor id you created the conversation with.",
            "schema": {
              "$ref": "#/components/schemas/VisitorId"
            }
          },
          {
            "name": "seen",
            "in": "query",
            "required": false,
            "description": "`1` marks human replies as read",
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConversationState"
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed for this workspace (`origin_not_allowed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown workspace or conversation (`unknown_workspace`, `unknown_conversation`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/widget/conversations/{id}/messages": {
      "post": {
        "tags": [
          "chat"
        ],
        "operationId": "sendMessage",
        "summary": "Send a message; returns the updated transcript including the bot's reply",
        "description": "Asking for a person in plain words (for example \"talk to a human\") hands the chat to a human, same as the handoff endpoint (`handed_off: true`).",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "conversation_id returned when the conversation was created.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "visitor_id",
                  "message"
                ],
                "properties": {
                  "visitor_id": {
                    "$ref": "#/components/schemas/VisitorId"
                  },
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2000
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConversationTurn"
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed for this workspace (`origin_not_allowed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown workspace or conversation (`unknown_workspace`, `unknown_conversation`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conversation is closed (`conversation_closed`); start a new one",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "message longer than 2000 characters",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited per IP (see `Retry-After`) or the conversation hit its 60-message limit (`conversation_limit`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/widget/conversations/{id}/handoff": {
      "post": {
        "tags": [
          "chat"
        ],
        "operationId": "requestHuman",
        "summary": "Hand the conversation to a human (a real person)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "conversation_id returned when the conversation was created.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "visitor_id"
                ],
                "properties": {
                  "visitor_id": {
                    "$ref": "#/components/schemas/VisitorId"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConversationState"
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed for this workspace (`origin_not_allowed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown workspace or conversation (`unknown_workspace`, `unknown_conversation`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Conversation is closed (`conversation_closed`); start a new one",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/widget/conversations/{id}/email": {
      "post": {
        "tags": [
          "chat"
        ],
        "operationId": "leaveEmail",
        "summary": "Leave an email address so a human can reply by email",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "conversation_id returned when the conversation was created.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "visitor_id",
                  "email"
                ],
                "properties": {
                  "visitor_id": {
                    "$ref": "#/components/schemas/VisitorId"
                  },
                  "email": {
                    "type": "string",
                    "format": "email",
                    "maxLength": 254
                  },
                  "name": {
                    "type": "string",
                    "maxLength": 200
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConversationState"
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed for this workspace (`origin_not_allowed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown workspace or conversation (`unknown_workspace`, `unknown_conversation`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/widget/conversations/{id}/rating": {
      "post": {
        "tags": [
          "chat"
        ],
        "operationId": "rateConversation",
        "summary": "Thumbs up or down",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "conversation_id returned when the conversation was created.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "visitor_id",
                  "value"
                ],
                "properties": {
                  "visitor_id": {
                    "$ref": "#/components/schemas/VisitorId"
                  },
                  "value": {
                    "type": "string",
                    "enum": [
                      "up",
                      "down"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "csat"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean",
                      "const": true
                    },
                    "csat": {
                      "type": "string",
                      "enum": [
                        "up",
                        "down"
                      ]
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing or invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Browser Origin not allowed for this workspace (`origin_not_allowed`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Unknown workspace or conversation (`unknown_workspace`, `unknown_conversation`)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "Server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/api/health": {
      "get": {
        "tags": [
          "system"
        ],
        "operationId": "health",
        "summary": "Liveness probe",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "const": "ok"
                    },
                    "timestamp": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error",
          "code"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "Human-readable message"
          },
          "code": {
            "type": "string",
            "description": "Machine code, e.g. unknown_workspace, invalid_visitor, conversation_closed"
          }
        }
      },
      "VisitorId": {
        "type": "string",
        "pattern": "^v_[A-Za-z0-9_-]{16,60}$",
        "description": "Chosen by you: `v_` plus 16-60 random URL-safe characters. Reuse it for the whole conversation and keep it private; it is the only proof the conversation is yours.",
        "examples": [
          "v_3kq9ZfA1xY7bLm2Pw0sT"
        ]
      },
      "Article": {
        "type": "object",
        "required": [
          "slug",
          "title",
          "body"
        ],
        "properties": {
          "slug": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "body": {
            "type": "string"
          }
        }
      },
      "WidgetConfig": {
        "type": "object",
        "description": "Selected fields; the widget also receives display settings (colors, voice, attachments, webcam header) that agents can ignore.",
        "additionalProperties": true,
        "required": [
          "workspace_id",
          "name",
          "greeting",
          "human",
          "articles"
        ],
        "properties": {
          "workspace_id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "greeting": {
            "type": "string"
          },
          "intro": {
            "type": [
              "string",
              "null"
            ]
          },
          "reply_time": {
            "type": [
              "string",
              "null"
            ]
          },
          "human": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "email": {
                "type": [
                  "string",
                  "null"
                ]
              },
              "online": {
                "type": "boolean"
              },
              "in_office_hours": {
                "type": "boolean"
              },
              "back_at": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "quick_links": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string"
                },
                "label": {
                  "type": "string"
                }
              }
            }
          },
          "suggestions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "articles": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Article"
            }
          },
          "ai": {
            "type": "object",
            "properties": {
              "mode": {
                "type": "string",
                "enum": [
                  "llm",
                  "scripted"
                ]
              }
            }
          },
          "test_mode": {
            "type": "boolean"
          }
        }
      },
      "StartConversationRequest": {
        "type": "object",
        "required": [
          "workspace_id",
          "visitor_id"
        ],
        "properties": {
          "workspace_id": {
            "type": "string",
            "examples": [
              "chrismai"
            ]
          },
          "visitor_id": {
            "$ref": "#/components/schemas/VisitorId"
          },
          "message": {
            "type": "string",
            "maxLength": 2000,
            "description": "First message (optional)"
          },
          "email": {
            "type": "string",
            "format": "email",
            "maxLength": 254,
            "description": "Optional reply address"
          },
          "name": {
            "type": "string",
            "maxLength": 200
          },
          "page_url": {
            "type": "string",
            "maxLength": 512,
            "description": "Page the question is about (optional)"
          },
          "website": {
            "type": "string",
            "maxLength": 0,
            "description": "Spam trap: leave empty or omit"
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "id",
          "role",
          "content"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "role": {
            "type": "string",
            "enum": [
              "visitor",
              "ai",
              "human",
              "system"
            ],
            "description": "visitor = you, ai = the bot, human = a person on our team"
          },
          "content": {
            "type": "string"
          },
          "author": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "attachments": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "ConversationState": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "conversation_id",
          "workspace_id",
          "status",
          "handled_by",
          "messages"
        ],
        "properties": {
          "conversation_id": {
            "type": "string"
          },
          "workspace_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "bot",
              "handoff",
              "closed"
            ]
          },
          "handled_by": {
            "type": "string",
            "enum": [
              "ai",
              "human",
              "waiting_for_human",
              "closed"
            ]
          },
          "human": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "online": {
                "type": "boolean"
              },
              "back_at": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          },
          "operator_typing": {
            "type": "boolean"
          },
          "operator_seen_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "needs_email": {
            "type": "boolean",
            "description": "true when waiting for a human who is offline and no email is on file"
          },
          "csat": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "up",
              "down",
              null
            ]
          },
          "mode": {
            "type": "string",
            "enum": [
              "llm",
              "scripted"
            ]
          },
          "ai_pending": {
            "type": "boolean",
            "description": "A reply is being reviewed by a human before it is sent"
          },
          "messages": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          }
        }
      },
      "ConversationTurn": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ConversationState"
          },
          {
            "type": "object",
            "properties": {
              "suggest_handoff": {
                "type": "boolean",
                "description": "The bot suggests talking to a human"
              },
              "handed_off": {
                "type": "boolean"
              },
              "fallback_reason": {
                "type": "string",
                "description": "Present when the AI model was not used for this turn"
              }
            }
          }
        ]
      },
      "ConversationList": {
        "type": "object",
        "required": [
          "conversations",
          "unread"
        ],
        "properties": {
          "unread": {
            "type": "integer"
          },
          "conversations": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "conversation_id": {
                  "type": "string"
                },
                "status": {
                  "type": "string",
                  "enum": [
                    "bot",
                    "handoff",
                    "closed"
                  ]
                },
                "unread": {
                  "type": "integer"
                },
                "updated_at": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "date-time"
                },
                "last_message": {
                  "type": [
                    "object",
                    "null"
                  ],
                  "properties": {
                    "role": {
                      "type": "string"
                    },
                    "content": {
                      "type": "string"
                    },
                    "author": {
                      "type": [
                        "string",
                        "null"
                      ]
                    },
                    "created_at": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
