AI Chat v2 API Integration Guide

The AI Chat v2 API (/aichat2/conversations) is a next-generation conversation interface and a comprehensive upgrade to the AI Chat API. Building on v1's simple, managed multi-turn conversations, it extends the following capabilities:

  • Multimodal User Input: Directly transmit text + images + file blocks through the structured message field, without first attaching them indirectly through references.
  • Agent-Based Tool Calling: Includes a built-in set of tools for web search, webpage fetching, file reading, and more. It also supports mounting 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: By using accept: text/event-stream or application/x-ndjson, you can receive events such as text_delta, tool_use, tool_result, thinking, citation, card, and artifact token by token, making it convenient to render each type separately on the frontend.
  • Interruptible / Resumable: When the model needs additional information from the user, it emits an ask_user_question event and pauses. The next call can continue the conversation by providing the answer through tool_results.
  • New CRUD Actions: Complete retrieve / retrieve_batch / update / delete operations through the action field on the same endpoint, without requiring additional conversation management APIs.
  • Continuously Updated Model List: By default, it supports contemporary models such as GPT-5.4, Claude Opus 4.8, Claude Sonnet 4.6, Gemini 3.1 Pro, GLM 5.1, DeepSeek V4, Kimi K3, and others.

At the same time, it is fully backward compatible with v1 at the request body level: simply passing model + question (+ optional stateful / id / references / preset) returns a JSON response equivalent to v1's {answer, id}. Therefore, migrating from /aichat/conversations does not require rewriting the client; you only need to change the endpoint to /aichat2/conversations.

If you are currently using /aichat/conversations, the old endpoint will remain available. You can migrate at your own pace.

Application Process

To use the AI Chat v2 API, first go to the 零壹AI Console to obtain your API Token and keep it for later use.

If you are not logged in or registered, you will automatically be redirected to the login page to register and log in. After completing the process, you will automatically return to the current page.

One API Token is sufficient to access all services on the platform. There is no need to apply for each service separately. Upon your first application, you will receive free credits to try the service at no cost. When your credits are insufficient, you can recharge your general balance in the Console.

📘 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.01ai.cloud/aichat2/conversations' \
  -H 'accept: application/json' \
  -H 'authorization: Bearer {token}' \
  -H 'content-type: application/json' \
  -d '{
    "model": "gpt-5.4",
    "question": "用一句话介绍下 AceDataCloud。"
  }'

Returned Result:

{
  "answer": "AceDataCloud 是一个聚合主流 AI 模型与多模态服务的统一 API 平台,开发者通过一个密钥即可调用 GPT、Claude、Gemini、Midjourney、Suno、Veo 等多家服务。",
  "id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44"
}

Python Example:

import requests

url = "https://api.01ai.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 viewed directly in the dropdown menu 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 accepts deepseek-v4.1-flash, deepseek-v4.1-flash-1017, and deepseek-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, refer to the Pricing card on the service page.

Multi-Turn Conversations

As with v1, pass stateful: true to enable conversation saving. The API will return an id; subsequent requests can continue the conversation by including the same id, without needing to maintain the message history yourself.

First Request:

curl -X POST 'https://api.01ai.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。"
  }'

Returned Result:

{
  "answer": "好的,我已经记住了 42。需要我用它做什么吗?",
  "id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44"
}

Second Request, include the same id:

curl -X POST 'https://api.01ai.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": "What was the number I just asked you to remember?"
  }'
{
  "answer": "The number you asked me to remember is 42.",
  "id": "f2f4b3e8-0c0a-4d3a-aaa2-7ff80c0a1c44"
}

stateful defaults to true; omitting it is equivalent to explicitly passing true. Setting stateful: false skips loading the previous conversation history; this does not mean that the current turn's results will not be saved, nor does it apply to tool workflows that need to be resumed after being paused.

Long Conversations and Preservation of Original Text

Context compaction only organizes the content sent to the model in the current turn; it does not replace the saved chat history. The complete saved messages can still be read through action: retrieve; explicit requests to edit or delete conversations still take effect as requested.

The model can search and read the original historical text in pages within the current conversation. When continuing to edit an article, cite numbers, or prepare content for publication, the corresponding original text should be retrieved; the main text must not be replaced with a summary. This capability does not automatically restore messages that have already been lost in older versions.

If context organization fails, please 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 be valid. Please check their results first to avoid duplicate generation or repeated publishing. When a single conversation reaches the storage limit, an explicit error will be returned. Existing saved records will not be trimmed to free up space; you can export the required 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 the final line data: [DONE]\n\n
Server / CLI / Node streaming parser application/x-ndjson One JSON object per line
No streaming required application/json (default) Returns {answer, id} all at once

NDJSON Example

import json
import requests

url = "https://api.01ai.cloud/aichat2/conversations"

headers = {
    "accept": "application/x-ndjson",
    "authorization": "Bearer {token}",
    "content-type": "application/json",
}

payload = {
    "model": "gpt-5.4",
    "stateful": True,
    "question": "Introduce Hangzhou in three sentences.",
}

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":
            # Compatible with v1: incremental fragments are also provided through the delta_answer field
            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 one is text_delta:

{"type":"text_delta","content":"Hang","delta_answer":"Hang","id":"f2f4b3e8-..."}
{"type":"text_delta","content":"zhou","delta_answer":"zhou","id":"f2f4b3e8-..."}
{"type":"text_delta","content":" is","delta_answer":" is","id":"f2f4b3e8-..."}
...
{"type":"done","conversation_id":"f2f4b3e8-...","usage":{"prompt_tokens":21,"completion_tokens":58,"total_tokens":79},"terminal_reason":"natural_stop"}

SSE Example

The browser-side EventSource does not support custom request bodies, so using fetch + manually parsing chunks separated by \n\n is recommended:

const resp = await fetch("https://api.01ai.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: "Introduce Hangzhou in three sentences.",
  }),
});

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 Incremental text fragment of the assistant's response. content contains the newly added content; for v1 compatibility, the same event also carries delta_answer (equal to content) and id.
thinking The model's thinking process (only appears 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 Tool execution result, paired with the preceding tool_use through tool_id; is_error indicates whether it failed.
card Structured cards produced by tools (such as images and link previews), suitable for direct rendering.
citation Source URL used to supplement the citation for the corresponding text fragment.
ask_user_question Emitted when the model needs the user to provide additional information. The conversation enters the awaiting_user_input state. See Resuming a Paused Conversation below for details.
artifact Independent output generated by the model (such as code blocks or documents), which can be saved or downloaded.
system_message System prompt information (not user or assistant content), used only for UI notifications.
compact The model's context has been organized; the saved original messages remain unchanged, and the client does not need to delete chat history.
error An error occurred during the current turn; message describes the error.
done The final conversation record for the current turn has been saved successfully. Carries usage (including prompt_tokens / completion_tokens / total_tokens) and terminal_reason; whether the task is complete still needs to be determined based on the termination reason.
For clients that only care about the final answer, concatenating the content of all text_delta events is equivalent to answer in application/json mode.

Multimodal Input

If the user's 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": "How many cats are in this picture?" },
    { "type": "image_url", "image_url": { "url": "https://cdn.acedata.cloud/cats.jpg" } }
  ]
}

Supported block types:

  • text — Ordinary text; the text field is required.
  • image_url — Image; image_url.url is required.
  • file_url — File (PDF, CSV, TXT, etc.); file_url.url is required.

Relationship with v1 references

For compatibility with older clients, v2 still recognizes the references: ["https://...", ...] field:

  • URLs with the suffixes jpg / jpeg / png / gif / bmp / webp / svg / heic / heif are automatically converted into image_url blocks;
  • Other extensions are converted into file_url blocks;
  • If question is also provided, it is prepended as a text block.

Therefore, if you only want to migrate from v1 without changing the request body, simply change the path to /aichat2/conversations, and the original references usage will continue to work as usual.

For more precise control (such as placing multiple images between text segments or when order matters), use the message array directly.

Tool Calls 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 no additional configuration is required from the client in the request. Common scenarios:

  • User asks, "Help me search for recent exhibitions in Shanghai" → The model calls the built-in web search → Organizes the results into an answer.
  • 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 presented through two types of events: tool_use and tool_result, for example:

{"type":"tool_use","tool_id":"toolu_01ABCDEF","tool_name":"web_search","input":{"query":"Shanghai 2026 spring exhibitions"},"id":"f2f4b3e8-..."}
{"type":"tool_result","tool_id":"toolu_01ABCDEF","output":"...","is_error":false,"id":"f2f4b3e8-..."}
{"type":"text_delta","content":"Currently","delta_answer":"Currently","id":"f2f4b3e8-..."}
{"type":"text_delta","content":"Shanghai","delta_answer":"Shanghai","id":"f2f4b3e8-..."}
...

If you do not want to display tool call details on the frontend, simply ignore these event types: tool_use / tool_result / card / citation. The model's final output will still be streamed through text_delta.

max_turns can limit the maximum number of rounds in which the model can call tools autonomously during this request. The range is 1–500, and the default is 500 if omitted. Setting it to a small value (such as max_turns: 1) can force a single response and disallow 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 have the API return a task ID immediately while execution continues in the background:

{
  "model": "gpt-5.5",
  "async": true,
  "question": "My service has triggered an alert. Use my personal WeChat account to notify the WeChat group 'AceDataCloud Team'..."
}

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 after the task is completed, the platform will POST { status, answer, usage, error } to your callback address. 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 confirmation buttons. If you want certain Skills or MCP Servers to perform actions such as sending, publishing, or writing in unattended mode, explicitly pass a pre-authorization list in the request body:

{
  "model": "gpt-5.5",
  "async": true,
  "allowed_skills": ["acedatacloud/personal-wechat"],
  "allowed_mcp_servers": [],
  "question": "My service has triggered an alert. Use my personal WeChat account to notify the WeChat group 'AceDataCloud Team'..."
}

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 that are not included in the pre-authorization list can still only preview, perform dry runs, or refuse write operations in unattended mode.

If more granular control is needed, you can also use the equivalent unattended_policy object:

{
  "unattended_policy": {
    "allowed_skills": ["acedatacloud/personal-wechat"],
    "allowed_mcp_servers": [],
    "expires_at": 1790000000
  }
}

Pre-authorization consists of these two lists themselves: an empty list means that no capabilities are authorized, and no additional switch field is required.

Note: Pre-authorization only means that "this request allows these capabilities to skip manual confirmation in unattended mode." The specific Skill must still support --unattended-confirm or a corresponding security mechanism; otherwise, it will continue to perform dry runs and will not directly execute write operations.

Resuming Paused Conversations

Some tools may cause the model to "ask the user a follow-up question." At this point, the model will emit an ask_user_question event, and the conversation will be frozen in the awaiting_user_input state:

{
  "type": "ask_user_question",
  "tool_id": "toolu_01XYZW",
  "tool_name": "ask_user_question",
  "question": "Would you like the generated report to be in Chinese or English?",
  "options": ["Chinese", "English"],
  "id": "f2f4b3e8-..."
}

Render this event as a card on the frontend for the user to select an answer, then initiate the next request using the same id and populate the answer through tool_results:

curl -X POST 'https://api.01ai.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": "中文"
      }
    ]
  }'

In the request body, tool_use_id must exactly match the tool_id at the time of suspension; otherwise, a 400 error will be returned. When tool_results is 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 suspended tool call as "Skipped by user".

Conversation Management (CRUD)

v2 provides lightweight conversation management through the action field on the same endpoint, without requiring a separate API.

action: retrieve —— Retrieve a conversation

curl -X POST 'https://api.01ai.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 }. The summaries do not include messages, making them suitable for sidebar lists; when 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": "Hangzhou Travel Plan"
}

messages can also be passed, but the server performs strict schema validation (it must be in the folded ToolUseContent format); otherwise, a 400 error will be returned. Generally, it is only recommended to use this to change 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.

Smooth Migration from v1

If you are already using /aichat/conversations, migrating to v2 requires almost no code changes:

  1. Change the URL from https://api.01ai.cloud/aichat/conversations to https://api.01ai.cloud/aichat2/conversations.
  2. If you previously used v1 model names (such as gpt-3.5, gpt-4-browsing, etc.), it is recommended to upgrade to contemporary models when switching to v2 (such as gpt-5.4, claude-opus-4-8, gemini-3.1-pro-preview, etc.).
  3. The fields in the NDJSON stream remain backward compatible: each text_delta event still includes delta_answer and id, so clients that previously parsed delta_answer line by line do not need to be modified.

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 are standardized as follows:

{
  "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, mismatched tool_use_id, invalid messages schema, etc.
  • 401 invalid_token: The authorization header is incorrect.
  • 404 not_found: The conversation corresponding to id does not exist when using action: retrieve / update / delete.
  • 413 conversation_storage_limit: The conversation exceeds the storage limit; existing saved records have not been overwritten.
  • 429 too_many_requests: The rate limit has been triggered.
  • 503 context_compaction_failed: Context compaction failed; existing records are retained.
  • 500 conversation_persist_failed: The final save for this round failed; receiving text does not mean the final record was successfully saved. Please query by conversation ID.
  • 500 chat_error: The service is temporarily unavailable, or no content was generated in this round (no charges will be incurred).

In streaming responses, errors are emitted as {"type":"error","message":"..."} events, after which the stream ends. [DONE] only indicates that the transmission has ended; if there is an error, it must not be considered successful, and no successful done event will be sent.

Conclusion

While maintaining backward compatibility 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, pausable / resumable interactions, structured streaming events, and built-in CRUD. We recommend using v2 directly for new integrations; existing v1 integrations can migrate smoothly in phases. If you have any questions, please feel free to contact our technical support team.