AI Chat v2 API Integration Guide
AI Chat v2 API (/aichat2/conversations) is a new-generation conversation interface and a comprehensive upgrade to the AI Chat API. Building on v1's simplicity and managed multi-turn conversations, it adds:
- Multimodal user input: Pass text + images + file blocks directly through the structured
messagefield, without first attaching them indirectly usingreferences. - Agent-style tool calling: Includes a set of tools for web searches, webpage scraping, file reading, and more, and can connect to user-authorized MCP servers (Google Drive, Notion, Slack, GitHub, etc.), allowing the model to autonomously call tools over multiple rounds within a single request to complete complex tasks.
- Structured streaming events: Use
accept: text/event-streamorapplication/x-ndjsonto receive token-by-tokentext_delta,tool_use,tool_result,thinking,citation,card,artifact, and other events, making it easy to render each type separately on the frontend. - Interruptible / resumable: When the model needs additional information from the user, it emits an
ask_user_questionevent and pauses; the next call can continue by supplying the answer throughtool_results. - Conversation management: Query, update, delete, or share saved conversations through the same endpoint.
- Continuously updated model list: Includes current models such as GPT-5.4, Claude Opus 4.8, Claude Sonnet 4.6, Gemini 3.1 Pro, GLM 5.1, DeepSeek V4, and Kimi K3 by default.
It is also fully backward-compatible with v1 at the request body level: simply pass model + question (+ optional stateful / id / references / preset) to receive a {answer, id} JSON response equivalent to v1. Therefore, migrating from /aichat/conversations does not require rewriting the client; you only need to change the path to /aichat2/conversations.
If you are currently using
/aichat/conversations, the old endpoint will remain available, and you can migrate at your own pace.
¶ Application Process
To use the AI Chat v2 API, first visit the Ace Data Cloud Console to obtain your API Token and keep it for later use.

If you have not yet logged in or registered, you will be automatically redirected to the login page to register and log in, and then automatically returned to the current page.
A general application's API Key can be used for services enabled for the account; a dedicated application's Key can be used within that application's service scope. Please check the Key's permissions, validity period, and limits, and confirm that the application balance is sufficient to pay for this request. Available trial credits are subject to what is displayed in your account; if the balance is insufficient, click the "Recharge" button.
📘 Full documentation: AI Chat v2 API →
¶ Basic Usage
The simplest usage is exactly the same as v1: pass model + question and receive {answer, id}.
CURL example:
curl -X POST 'https://api.acedata.cloud/aichat2/conversations' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
"model": "gpt-5.4",
"question": "用一句话介绍下 AceDataCloud。"
}'
Response:
{
"answer": "AceDataCloud 是一个聚合主流 AI 模型与多模态服务的统一 API 平台,开发者通过一个密钥即可调用 GPT、Claude、Gemini、Midjourney、Suno、Veo 等多家服务。",
"id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44"
}
Python example:
import requests
url = "https://api.acedata.cloud/aichat2/conversations"
headers = {
"accept": "application/json",
"authorization": "Bearer {token}",
"content-type": "application/json",
}
payload = {
"model": "gpt-5.4",
"question": "用一句话介绍下 AceDataCloud。",
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
Available model values can be found directly in the dropdown in the Try panel 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-8,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-preview,gemini-3.1-pro-preview,gemini-3.1-flash-image,gemini-3.1-pro-preview,gemini-2.5-flash-lite, etc. - xAI:
grok-4, etc. - DeepSeek:
deepseek-flash,deepseek-v4-pro,deepseek-v3.2. Flash also acceptsdeepseek-v4.1-flash,deepseek-v4.1-flash-1017, anddeepseek-v4-flash. - Moonshot:
kimi-k3.1-pro,kimi-k3,kimi-k2.6,kimi-k2.7-code - Zhipu:
glm-5.3,glm-5.2,glm-5.1,glm-5,glm-5-turbo,glm-4.7,glm-4.5v, etc.
For specific billing rules, see the Pricing card on the service page.
¶ Multi-Turn Conversations
As with v1, pass stateful: true to enable conversation saving, and the API will return an id; include the id in subsequent requests to continue the conversation without maintaining the messages history yourself.
First request:
curl -X POST 'https://api.acedata.cloud/aichat2/conversations' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
"model": "gpt-5.4",
"stateful": true,
"question": "记住一个数字:42。"
}'
Response:
{
"answer": "好的,我已经记住了 42。需要我用它做什么吗?",
"id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44"
}
Second request, including the same id:
curl -X POST 'https://api.acedata.cloud/aichat2/conversations' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
"model": "gpt-5.4",
"stateful": true,
"id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44",
"question": "我刚才让你记住的数字是多少?"
}'
{
"answer": "你让我记住的数字是 42。",
"id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44"
}
statefuldefaults totrue; omitting it is equivalent to explicitly passingtrue. Settingstateful: falseskips loading previous conversation history; this does not mean that the result of the current turn will not be saved, and it does not apply to tool workflows that need to pause and resume.
¶ Long Conversations and Original Text Preservation
Context compaction only organizes the content sent to the model for the current turn; it does not replace saved chat records. The complete saved messages can still be read through action: retrieve; explicit requests to edit or delete a conversation still take effect.
The model can search for and read historical original text page by page within the current conversation. When continuing to edit an article, citing figures, or preparing to publish, it should read the corresponding original text and must not substitute a summary for the body text. This capability does not automatically restore messages already lost in older versions.
If context compaction fails, retain the conversation ID and check the error event; the service will not overwrite the original text with an empty summary. Tool operations completed before the failure may still have taken effect, so check their results first to avoid duplicate generation or publication. When a conversation reaches the storage limit, an explicit error is returned; existing saved records will not be trimmed to free up space. Export any needed content and then start a new conversation.
¶ Streaming Responses
v2 supports two streaming formats, selected according to the accept header:
| Scenario | accept |
Data format |
|---|---|---|
| Web frontend / EventSource | text/event-stream |
data: {json}\n\n, with data: [DONE]\n\n as the final line |
| Server / CLI / Node streaming parsing | application/x-ndjson |
One JSON object per line |
| No streaming required | application/json (default) |
Returns {answer, id} in a single response |
¶ NDJSON Example
import json
import requests
url = "https://api.acedata.cloud/aichat2/conversations"
headers = {
"accept": "application/x-ndjson",
"authorization": "Bearer {token}",
"content-type": "application/json",
}
payload = {
"model": "gpt-5.4",
"stateful": True,
"question": "用三句话介绍杭州。",
}
with requests.post(url, json=payload, headers=headers, stream=True) as resp:
answer = ""
for line in resp.iter_lines():
if not line:
continue
event = json.loads(line)
if event.get("type") == "text_delta":
# 与 v1 兼容:增量片段同时通过 delta_answer 字段提供
answer += event["content"]
print(event["delta_answer"], end="", flush=True)
elif event.get("type") == "done":
print()
print("usage =", event.get("usage"))
Each NDJSON line is a structured event, the most common being text_delta:
{"type":"text_delta","content":"杭","delta_answer":"杭","id":"f2f4b3e8-..."}
{"type":"text_delta","content":"州","delta_answer":"州","id":"f2f4b3e8-..."}
{"type":"text_delta","content":"是","delta_answer":"是","id":"f2f4b3e8-..."}
...
{"type":"done","conversation_id":"f2f4b3e8-...","usage":{"prompt_tokens":21,"completion_tokens":58,"total_tokens":79},"terminal_reason":"natural_stop"}
¶ SSE Example
Using EventSource in the browser does not support a custom request body; using fetch and manually splitting on \n\n for parsing is recommended:
const resp = await fetch("https://api.acedata.cloud/aichat2/conversations", {
method: "POST",
headers: {
accept: "text/event-stream",
authorization: "Bearer {token}",
"content-type": "application/json",
},
body: JSON.stringify({
model: "gpt-5.4",
stateful: true,
question: "用三句话介绍杭州。",
}),
});
const reader = resp.body.getReader();
const decoder = new TextDecoder();
let buffer = "";
while (true) {
const { value, done } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const blocks = buffer.split("\n\n");
buffer = blocks.pop() ?? "";
for (const block of blocks) {
const dataLine = block.split("\n").find((l) => l.startsWith("data: "));
if (!dataLine) continue;
const payload = dataLine.slice(6);
if (payload === "[DONE]") return;
const event = JSON.parse(payload);
if (event.type === "text_delta") process.stdout.write(event.content);
}
}
¶ Streaming Event Types
type |
Meaning |
|---|---|
text_delta |
An incremental text fragment of the assistant's answer. content contains the new content; for v1 compatibility, the same event also carries delta_answer (equal to content) and id. |
thinking |
The model's reasoning process (appears only when the selected model exposes reasoning). |
tool_use |
The model decides to call a tool; the event carries tool_id, tool_name, and input. |
tool_result |
The result of a tool execution, paired with the preceding tool_use through tool_id; is_error indicates whether it failed. |
card |
A structured card produced by a tool (such as an image or link preview), suitable for direct rendering. |
citation |
A source URL provided as a citation for the corresponding text fragment. |
ask_user_question |
Emitted when the model needs additional information from the user; the conversation enters the awaiting_user_input state. See Resuming a Paused Conversation below. |
artifact |
A standalone output generated by the model (such as a code block or document), which can be saved or downloaded. |
system_message |
A system notification (not user or assistant content), used only for UI prompts. |
compact |
The model context has been compacted; saved original messages remain unchanged, and the client does not need to delete chat records. |
error |
An error occurred during the current turn; message describes the error. |
done |
The final conversation record for the current turn was saved successfully; carries usage (including prompt_tokens / completion_tokens / total_tokens) and terminal_reason. Whether the task was completed must still be determined from the terminal reason. |
For clients that only care about the final answer, concatenating the content of all text_delta events is equivalent to the answer in application/json mode. |
¶ Multimodal Input
If the user input contains images or files, pass message (an array) instead of question. Each array element is a content block:
{
"model": "gpt-5.4",
"stateful": true,
"message": [
{ "type": "text", "text": "这张图片里有几只猫?" },
{ "type": "image_url", "image_url": { "url": "https://cdn.acedata.cloud/cats.jpg" } }
]
}
Supported block types:
text— plain text, requires thetextfield.image_url— image, requiresimage_url.url.file_url— file (PDF, CSV, TXT, etc.), requiresfile_url.url.
¶ Relationship to v1 references
For compatibility with older clients, v2 still recognizes the references: ["https://...", ...] field:
- URLs with the suffix
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.
Therefore, if you only want to migrate from v1 without changing the request body, simply change the path to /aichat2/conversations, and the existing references usage will continue to work.
If you need finer control (for example, placing multiple images between text blocks, or when order matters), use the message array directly.
¶ Tool Calling and MCP
The core enhancement in v2 is that the model can autonomously call tools to complete multi-step tasks. This is enabled by default, and the client does not need to make any additional configuration in the request. Common scenarios:
- The user asks, “Help me search for recent new exhibitions in Shanghai” → the model calls the built-in web search → organizes the results into an answer.
- The user asks, “Read this PDF and write a summary” → the model calls file_read → writes a summary.
- The user has authorized Google Drive / GitHub / Notion, etc. in Connections → the model can call the corresponding MCP tools to read and write their data.
In NDJSON / SSE streams, tool calls are represented by two types of events, tool_use and tool_result, for example:
{"type":"tool_use","tool_id":"toolu_01ABCDEF","tool_name":"web_search","input":{"query":"上海 2026 春季展览"},"id":"f2f4b3e8-..."}
{"type":"tool_result","tool_id":"toolu_01ABCDEF","output":"...","is_error":false,"id":"f2f4b3e8-..."}
{"type":"text_delta","content":"目前","delta_answer":"目前","id":"f2f4b3e8-..."}
{"type":"text_delta","content":"上海","delta_answer":"上海","id":"f2f4b3e8-..."}
...
If you do not want to display tool call details on the frontend, simply ignore the tool_use / tool_result / card / citation events, and the model's final output will still stream through text_delta.
max_turns can limit the maximum number of rounds in which the model calls tools on its own during this request, with a range of 1–500 and a default of 500 when omitted. Setting it to a low value (such as max_turns: 1) can force a single response without allowing any tool calls.
¶ Asynchronous Execution and Unattended Authorization
If your call comes from an alert Webhook, CI/CD, a monitoring system, or another background task, you can set async: true to make the API return a task ID immediately while execution continues in the background:
{
"model": "gpt-5.5",
"async": true,
"question": "我的服务报警了,用个人微信通知微信群「AceDataCloud团队」……"
}
Example response:
{
"task_id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44",
"conversation_id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44",
"id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44",
"status": "queued"
}
You can then use action: retrieve + id to query the conversation result; you can also provide a callback_url, and the platform will POST { status, answer, usage, error } to your callback address when the task is complete. callback_url must use http / https and cannot directly specify localhost or a private IP literal address.
Background tasks usually have no one available to click confirm. If you want certain Skills or MCP Servers to perform actions such as sending, publishing, or writing in unattended mode, explicitly pass a preauthorization list in the request body:
{
"model": "gpt-5.5",
"async": true,
"allowed_skills": ["acedatacloud/personal-wechat"],
"allowed_mcp_servers": [],
"question": "我的服务报警了,用个人微信通知微信群「AceDataCloud团队」……"
}
The values in allowed_skills are the slugs of connected Skills; the values in allowed_mcp_servers are the slugs of connected MCP Servers. Skills / MCP Servers not included in the preauthorization list can still only preview, dry-run, or refuse to perform write operations in unattended mode.
If you need finer control, you can also use the equivalent unattended_policy object:
{
"unattended_policy": {
"allowed_skills": ["acedatacloud/personal-wechat"],
"allowed_mcp_servers": [],
"expires_at": 1790000000
}
}
Preauthorization consists of these two lists themselves: empty lists authorize no capabilities, and no additional switch field is needed.
Note: Preauthorization only means “this request allows these capabilities to skip human confirmation in unattended mode.” Each Skill must still support --unattended-confirm or the corresponding safety mechanism; otherwise, it will continue to dry-run and will not directly perform write operations.
¶ Resuming a Paused Conversation
Some tools cause the model to “ask the user a follow-up question.” The model then emits an ask_user_question event, and the conversation is frozen in the awaiting_user_input state:
{
"type": "ask_user_question",
"tool_id": "toolu_01XYZW",
"tool_name": "ask_user_question",
"question": "你希望生成的报告是中文还是英文?",
"options": ["中文", "英文"],
"id": "f2f4b3e8-..."
}
Render this event as a card on the frontend for the user to select an answer, then initiate the next request with the same id and pass the answer back through tool_results:
curl -X POST 'https://api.acedata.cloud/aichat2/conversations' \
-H 'accept: text/event-stream' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
"model": "gpt-5.4",
"stateful": true,
"id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44",
"tool_results": [
{
"tool_use_id": "toolu_01XYZW",
"output": "中文"
}
]
}'
The tool_use_id in the request body must exactly match the tool_id at the time of the pause; a mismatch will return 400. When tool_results is also present in the request, question / message / references will all be ignored.
If the user decides to abandon this question, simply pass a new question / message, and the platform will automatically mark the paused tool call as “skipped by user.”
¶ Conversation Management (CRUD)
The six conversation management operations retrieve, retrieve_batch, update, delete, share, and unshare all cost 0 Credits, and model can be omitted. Operation names are case-sensitive. When action is omitted or chat is specified, billing is based on the selected model's price.
¶ action: retrieve —— Retrieve a Conversation
curl -X POST 'https://api.acedata.cloud/aichat2/conversations' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
"action": "retrieve",
"id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44"
}'
Returns the complete conversation document (including messages history, model, title, tools_used, etc.).
¶ action: retrieve_batch —— List Conversation Summaries
{
"action": "retrieve_batch",
"model_group": "chatgpt",
"limit": 20,
"offset": 0
}
Returns { items: [...], total }. Summaries do not contain messages, making them suitable for sidebar lists; if the user opens a conversation, use action: retrieve to retrieve its complete messages separately.
Optional filtering parameters: user_id, application_id, model_group, model.
¶ action: update —— Change the Title or Rewrite History
{
"action": "update",
"id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44",
"title": "杭州旅行计划"
}
messages can also be passed, but the server performs strict schema validation (it must be in the collapsed ToolUseContent form), and noncompliant data will return 400. Generally, it is only recommended for changing the title.
¶ action: delete —— Delete a Conversation
{
"action": "delete",
"id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44"
}
Returns { id, success: true }. Deletion cannot be undone, so please confirm before calling.
¶ share and unshare —— Share or Revoke Sharing
Pass {"action": "share", "id": "<conversation ID>"} to create or refresh a public read-only snapshot of the conversation. The response contains id, share_id, and shared_at. Pass {"action": "unshare", "id": "<conversation ID>"} to revoke sharing, and the response is { id, success: true }.
¶ 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.acedata.cloud/aichat/conversationstohttps://api.acedata.cloud/aichat2/conversations. - If you previously passed v1 model names (such as
gpt-3.5,gpt-4-browsing, etc.), it is recommended to upgrade to contemporary models (such asgpt-5.4,claude-opus-4-8,gemini-3.1-pro-preview, etc.) when switching to v2. - The fields in the NDJSON stream remain backward compatible: each
text_deltaevent still includesdelta_answerandid, so clients that previously parseddelta_answerline by line do not need to be changed.
After migration, you can enable v2's new capabilities as needed (multimodal message, SSE, tool calls, action CRUD) and proceed at your own pace.
¶ Error Handling
Error responses follow a consistent format:
{
"error": {
"code": "chat_error",
"message": "model service returned an error"
},
"trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}
Common errors:
400 bad_request: Missing required fields,tool_use_idmismatch, invalidmessagesschema, etc.401 invalid_token: Incorrectauthorizationheader.404 not_found: The conversation corresponding to theiddoes not exist when usingaction: retrieve / update / delete / share / unshare.413 conversation_storage_limit: The conversation exceeds the storage limit; existing saved records were not overwritten.429 too_many_requests: The rate limit was triggered.503 context_compaction_failed: Context compaction failed; existing records were retained.500 conversation_persist_failed: The final save for this turn failed; receiving text does not mean the final record was saved successfully, so please query by conversation ID.500 chat_error: The service is temporarily unavailable, or no content was generated in this turn (no charge will be incurred).
In streaming responses, errors are emitted as {"type":"error","message":"..."} events, after which the stream ends. [DONE] only indicates that transmission has ended; when there is an error, it cannot be considered successful, and a successful done event will not be sent.
¶ Conclusion
While remaining backward compatible with v1, the AI Chat v2 API upgrades conversations from “single-turn / multi-turn Q&A” to “agent-based observable conversations”: multimodal input, tool calls, pausing / resuming, streaming structured events, and built-in CRUD. New integrations are recommended to use v2 directly; existing v1 integrations can migrate smoothly in stages. If you have any questions, please feel free to contact our technical support team.
