Skip to main content

Endpoint

POST /api/chat
Authorization: Bearer <access_token>
Content-Type:  application/json
Returns SSE (text/event-stream).

Request body

FieldTypeRequiredDescription
questionstringThe user’s prompt; empty is rejected
agentstringFixed at App on the China cluster
providerstringLLM selection, see Providers
session_idstringMaintain context across turns. If absent, the server generates one and emits it via the first id event
prompt_namestringActivate a system prompt saved via /api/user/prompt/set
query_user_idstringAsk about a family member’s data; requires sharing permission
file_listarrayAttach files; see Files attached to chat
languagestringzh-CN / en; defaults to X-Language → user profile
timezonestringe.g. Asia/Shanghai

Providers

China cluster offers 5 providers, all supporting multi-turn context, streaming, and tool calls:
providerUnderlying modelUse case
DeepSeekFlashDeepSeek v4 FlashDefault — fast, low cost
DeepSeekProDeepSeek v4 ProComplex reasoning
kimiKimi K2.6Long context
minimaxMiniMax M2.7Natural Chinese expression
豆包Doubao Seed 2.0 LiteChinese, via Volcengine
GET /api/providers returns the current list at runtime.

Files attached to chat

file_list requires all five fieldsfile_url, file_name, file_key, file_type, file_size. The easiest path is to use POST /files/upload and feed its data array straight into file_list:
"file_list": [
  {
    "file_url":  "<signed CDN URL returned by /files/upload>",
    "file_name": "report.pdf",
    "file_key":  "uploads/20260522_xxx.pdf",
    "file_type": "application/pdf",
    "file_size": 102400
  }
]
The file_url must be the full signed URL returned by /files/upload — the LLM downstream will fetch it, and stripping the signature causes a 403.

SSE event types

Each event:
data: {"type": "...", "content": ..., "tool_id": "?", "is_delete": null}\n\n
typeWhencontent
idFirst eventweb_<uuid> — message id for this turn
queryTitleTool call / phase headerTool name or phase description
queryDetailTool call resultString (often JSON-stringified)
replyStreaming model replyText fragment — clients must concatenate
thinkingInternal thinkingText fragment
costStatisticsNear end{ model, input_tokens, output_tokens, total_tokens, total_cost }
errorExceptionError description
endStream endEmpty
tool_id lets you pair queryTitle / queryDetail for the same tool call.

Tools the Agent calls

The Agent uses health/file/chart tools on demand. Examples:
  • user-get_profile, user-search_health_indicators, user-fetch_health_data, user-get_genetic_data, user-get_journal_entries
  • file-list_global_files, file-ls, file-fetch_remote_files, file-read_file
  • chart tools: line / column / pie / radar / dual-axes / scatter / boxplot / sankey / etc.
  • data-search_medical_literature, data-get_fda_drugs, data-search_clinical_trials, etc.

Disabled on China cluster

The following tools are not called by the Agent on the China cluster:
  • tool-* (all tool- prefixed tools — Apple Watch, doctor recommendation)
  • user-get_events, user-get_food_records, user-list_medications, user-get_medication_details
If users ask “what did I eat” / “what meds am I on” / “recommend a doctor”, the Agent cannot pull that data automatically — use the relevant REST endpoint instead.

Live example

curl -N -X POST https://mcp.thetahealth.cn/api/chat \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"question":"Hello","agent":"App","provider":"DeepSeekFlash"}'
Partial output:
data: {"type": "id", "content": "web_223aa2af-..."}
data: {"type": "reply", "content": "Hi! ..."}
data: {"type": "costStatistics", "content": {"model": "dashscope/deepseek-v4-flash", ...}}
data: {"type": "end", "content": ""}