API ReferenceapiaiPOST /v1/ai/chat

POST /v1/ai/chat

Service: ai · operationId: (none)

Required scopes

(no scope declared — review service config)

Request body

{
  "type": "object",
  "properties": {
    "messages": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant"
            ]
          },
          "content": {
            "type": "string"
          }
        },
        "required": [
          "role",
          "content"
        ]
      },
      "minItems": 1
    },
    "brand_id": {
      "type": "string",
      "minLength": 1
    },
    "user_id": {
      "type": "string",
      "minLength": 1
    },
    "model": {
      "type": "string",
      "enum": [
        "claude-sonnet-4-6",
        "gpt-4o",
        "gpt-4o-mini",
        "gpt-4-turbo",
        "gpt-3.5-turbo"
      ]
    },
    "assistant_id": {
      "type": "string"
    },
    "rag_scope": {
      "type": "string"
    },
    "top_k": {
      "type": "integer",
      "exclusiveMinimum": 0
    },
    "threshold": {
      "type": "number",
      "minimum": 0,
      "maximum": 1
    },
    "temperature": {
      "type": "number",
      "minimum": 0,
      "maximum": 2
    },
    "max_tokens": {
      "type": "integer",
      "exclusiveMinimum": 0
    }
  },
  "required": [
    "messages",
    "brand_id",
    "user_id"
  ]
}

Responses

200 RAG-augmented chat response

{
  "type": "object",
  "properties": {
    "content": {
      "type": "string"
    },
    "model": {
      "type": "string"
    },
    "usage": {
      "type": "object",
      "properties": {
        "prompt_tokens": {
          "type": "number"
        },
        "completion_tokens": {
          "type": "number"
        },
        "total_tokens": {
          "type": "number"
        }
      },
      "required": [
        "prompt_tokens",
        "completion_tokens",
        "total_tokens"
      ]
    },
    "rag_context": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "content": {
            "type": "string"
          },
          "score": {
            "type": "number"
          }
        },
        "required": [
          "id",
          "content",
          "score"
        ]
      }
    },
    "citations": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer"
          },
          "content": {
            "type": "string"
          },
          "document_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "score": {
            "type": "number"
          }
        },
        "required": [
          "index",
          "content",
          "document_id",
          "score"
        ]
      }
    },
    "finish_reason": {
      "type": "string"
    },
    "template_id": {
      "type": "string"
    },
    "template_version": {
      "type": "string"
    }
  },
  "required": [
    "content",
    "model",
    "usage",
    "rag_context",
    "citations",
    "finish_reason",
    "template_id",
    "template_version"
  ]
}

400 Invalid input

{
  "type": "object",
  "properties": {
    "error": {
      "type": "string"
    },
    "message": {
      "type": "string"
    }
  },
  "required": [
    "error",
    "message"
  ]
}

500 Server error

{
  "type": "object",
  "properties": {
    "error": {
      "type": "string"
    },
    "message": {
      "type": "string"
    }
  },
  "required": [
    "error",
    "message"
  ]
}

Example

curl -X POST https://ai.platform.loop.health/v1/ai/chat \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ ... }'