The AI Chat v2 API (Documentation Index
Fetch the complete documentation index at: https://docs.xhuoapi.ai/llms.txt
Use this file to discover all available pages before exploring further.
/aichat2/conversations) is the next-generation conversational interface, a comprehensive upgrade of the AI Chat API. Building on the simplicity and multi-turn conversation hosting of v1, it extends with:
- Multimodal User Input: Directly pass text + images + file blocks via a structured
messagefield without needing to attach them indirectly viareferences. - Agent-style Tool Invocation: Built-in tools for web search, web scraping, file reading, etc., with the ability to mount user-authorized MCP servers (Google Drive, Notion, Slack, GitHub, etc.). The model can autonomously invoke tools multiple times within a single request to complete complex tasks.
- Structured Streaming Events: By setting
accept: text/event-streamorapplication/x-ndjson, you can receive token-by-token events such astext_delta,tool_use,tool_result,thinking,citation,card,artifact, etc., facilitating frontend rendering by event type. - Interruptible / Resumable: When the model needs additional user input, it emits an
ask_user_questionevent and pauses; the next call can resume by feeding back answers viatool_results. - New CRUD Actions: Supports
retrieve/retrieve_batch/update/deletevia the same endpoint using theactionfield, eliminating the need for separate session management APIs. - Continuously Updated Model List: Default access to contemporary models such as GPT-5.4, Claude Opus 4.7, Claude Sonnet 4.6, Gemini 3.1 Pro, GLM 5.1, DeepSeek V4, Kimi K2.5, and more.
model + question (+ optional stateful / id / references / preset) to get a {answer, id} JSON response equivalent to v1. Thus, migrating from /aichat/conversations only requires changing the path to /aichat2/conversations without rewriting the client.
If you are currently using /aichat/conversations, the old interface will remain available, so you can migrate at your own pace.
Application Process
To use the API, first apply for the corresponding service on the AI Chat v2 API page. After entering the page, click the “Acquire” button to obtain the credentials needed for requests. If you are not logged in or registered, you will be automatically redirected to the login page. After registering and logging in, you will be returned to the current page. A free quota is granted upon first application, allowing free usage of the API.Basic Usage
The simplest usage is identical to v1: passmodel + question and receive {answer, id}.
CURL example:
model values can be seen directly in the Try panel dropdown on the right. Common categories include:
- OpenAI:
gpt-5.4-mini,gpt-5.4-nano,gpt-5.2-pro,gpt-5.1-all,gpt-5-all,gpt-4.1,gpt-4o,gpt-4o-image,o3,o4-mini, etc. - Anthropic:
claude-opus-4-7,claude-opus-4-6,claude-opus-4-5-20251101,claude-sonnet-4-6,claude-sonnet-4-5-20250929,claude-haiku-4-5-20251001, etc. - Google:
gemini-3.1-pro,gemini-3.1-pro-preview,gemini-3.1-flash-image-preview,gemini-3-pro-preview,gemini-2.5-flash-lite, etc. - xAI:
grok-4,grok-4-1-fast,grok-4-1-fast-reasoning,grok-3-mini-fast, etc. - DeepSeek:
deepseek-v4-flash,deepseek-v3.2-exp,deepseek-r1-0528, etc. - Moonshot:
kimi-k2.5,kimi-k2-thinking,kimi-k2-thinking-turbo, etc. - Zhipu:
glm-5.1,glm-5,glm-5-turbo,glm-4.7,glm-4.5v, etc.
Multi-turn Conversations
As with v1, passstateful: true to enable session saving. The API returns an id; subsequent requests include this id to continue the conversation without maintaining the message history yourself.
First request:
id:
The default forstatefulistrue. Omitting it is equivalent to explicitly passingtrue. If you do not want the server to save this conversation, explicitly setstateful: false.
Streaming Responses
v2 supports two streaming formats, selectable via theaccept header:
| Scenario | accept | Data Format |
|---|---|---|
| Web frontend / EventSource | text/event-stream | data: {json}\n\n, ends with data: [DONE]\n\n |
| Server / CLI / Node streaming | application/x-ndjson | One JSON object per line |
| No streaming needed | application/json (default) | Single {answer, id} response |
NDJSON Example
text_delta:
SSE Example
Since browserEventSource does not support custom request bodies, it is recommended to use fetch with manual splitting by \n\n:
Streaming Event Types
type | Description |
|---|---|
text_delta | Incremental text fragment of the assistant’s answer. content is the new content; for v1 compatibility, the event also includes delta_answer (equal to content) and id. |
thinking | Model’s reasoning process (only appears if the selected model exposes reasoning). |
tool_use | Model decides to invoke a tool; event carries tool_id, tool_name, and input. |
tool_result | Result of tool execution, paired with the previous tool_use via tool_id; is_error indicates failure. |
card | Structured card output from tools (e.g., images, link previews), suitable for direct rendering. |
citation | Source URLs supplementing referenced text fragments. |
ask_user_question | Model requests additional user input, conversation enters awaiting_user_input state; see Resuming Paused Conversations. |
artifact | Independent artifacts generated by the model (e.g., code blocks, documents), can be saved or downloaded. |
system_message | System prompt messages (not user or assistant content), for UI hints only. |
compact | Internal context compression event, no special handling needed. |
error | Error occurred in this turn; message describes the error. |
done | Streaming response ended, includes usage (with prompt_tokens / completion_tokens / total_tokens) and terminal_reason. |
text_delta content fragments, which is equivalent to the answer in application/json mode.
Multimodal Input
If user input includes images or files, passmessage (an array) instead of question. Each array element is a content block:
text— plain text, requirestextfield.image_url— image, requiresimage_url.url.file_url— file (PDF, CSV, TXT, etc.), requiresfile_url.url.
Relation to v1 references
For backward compatibility, v2 still recognizes the references: ["https://...", ...] field:
- URLs with suffixes
jpg / jpeg / png / gif / bmp / webp / svg / heic / heifare automatically converted toimage_urlblocks; - Other extensions are converted to
file_urlblocks; - If
questionis also provided, it is prepended as atextblock.
/aichat2/conversations; the original references usage continues to work.
For finer control (e.g., placing multiple images between texts or preserving order), use the message array directly.
Tool Invocation and MCP
A core enhancement in v2 is that the model can autonomously invoke tools to complete multi-step tasks. This is enabled by default and requires no extra client configuration. Common scenarios:- User asks, “Help me search for recent exhibitions in Shanghai” → model invokes built-in web search → organizes results into an answer.
- User asks, “Read this PDF and write a summary” → model invokes file_read → writes summary.
- User has authorized Google Drive / GitHub / Notion, etc. in Connections → model can invoke corresponding MCP tools to read/write data.
tool_use and tool_result events, for example:
tool_use / tool_result / card / citation events; the model’s final output still flows through text_delta.
The max_turns parameter limits how many times the model can self-invoke tools in this request. The default upper limit is platform-determined. Setting it low (e.g., max_turns: 1) forces a single answer without any tool invocation.
Resuming Paused Conversations
Some tools cause the model to “ask the user” for clarification. The model emits anask_user_question event, and the conversation freezes in the awaiting_user_input state:
id, feeding back the answer via tool_results:
tool_use_id in the request must exactly match the paused tool_id; mismatches will return 400. When tool_results is present, question / message / references are ignored.
If the user decides to skip the question, simply send a new question or message; the platform will automatically mark the paused tool invocation as “user skipped.”
Conversation Management (CRUD)
v2 provides lightweight conversation management via the same endpoint using theaction field, no separate API needed.
action: retrieve — Fetch a conversation
messages history, model, title, tools_used, etc.).
action: retrieve_batch — List conversation summaries
{ items: [...], total }. Summaries do not include messages, suitable for sidebar lists. When the user opens a conversation, use action: retrieve to fetch full messages.
Optional filters: user_id, application_id, model_group, model.
action: update — Change title or rewrite history
messages can also be passed but the server performs strict schema validation (must be folded ToolUseContent form); invalid data returns 400. Generally, only title changes are recommended.
action: delete — Delete a conversation
{ id, success: true }. Deletion is irreversible; confirm before calling.
Smooth Migration from v1
If you are already using/aichat/conversations, migrating to v2 requires almost no code changes:
- Change the URL from
https://api.xhuoapi.ai/v1/aichat/conversationstohttps://api.xhuoapi.ai/v1/aichat2/conversations. - If you previously used v1 model names (e.g.,
gpt-3.5,gpt-4-browsing), it is recommended to upgrade to contemporary models (e.g.,gpt-5.4,claude-opus-4-7,gemini-3.1-pro) when switching to v2. - NDJSON stream fields remain backward compatible: each
text_deltaevent still carriesdelta_answerandid, so clients parsingdelta_answerline-by-line need no changes.
message, SSE, tool invocation, action CRUD) at your own pace.
Error Handling
Error responses have a unified format:400 bad_request: missing required fields,tool_use_idmismatch, invalidmessagesschema, etc.401 invalid_token: incorrectauthorizationheader.404 not_found: conversation with specifiediddoes not exist foraction: retrieve / update / delete.429 too_many_requests: rate limit exceeded.500 chat_error: upstream LLM error orcompletion_tokens=0for the turn (treated as no consumption, no charge).
{"type":"error","message":"..."} events, followed immediately by stream termination.

