General description of dialogue interface
Before use, press Access Basics to set
SHANHAI_BASE_URL(this site’s root address) andSHANHAI_API_KEY(this site’s token). The following command is suitable for Bash; the material example address must be replaced with a real address that can be downloaded directly.
interface format and selection
| Format | Request address | Main input | Final text position |
|---|---|---|---|
| Chat Completions | POST /v1/chat/completions |
messages | choices[].message.content |
| Messages | POST /v1/messages |
top-level system and messages | text of type:text |
| Responses | POST /v1/responses |
instructions and input | output message content[].text |
Existing applications will use the format it uses first. The compatible format examples below use qwen3.8-flash; the inputs and tools available for each model are still subject to the corresponding pages. Fields in the three formats cannot be mixed in one request. Interface compatibility does not mean that it automatically has built-in browsing, code execution, file hosting and other capabilities.
request parameters
| Parameter | Type | Required | Usage |
|---|---|---|---|
model |
string | is | The exact model name on this page |
messages |
array | is | Pass in complete conversations in chronological order, at least one |
messages[].role |
string | is | system Set task, user Ask a question, assistant is the historical answer, tool is the tool result |
messages[].content |
string / array / null | Depends on the message | Literal is usually a string; the tool call message can be null. The image content format is shown below. Ordinary file paths cannot be automatically uploaded as text |
messages[].tool_calls |
array | No | Keep the tool calls returned by the model as they are, and return them together with the corresponding tool results |
messages[].tool_call_id |
string | Tool result required | Same as the responded tool call id |
max_tokens |
integer | No | Limit the output length, example 1024 is not the model upper limit; the context also includes input and historical messages |
stream |
boolean | No | Default false; true Return segment by event |
stream_options.include_usage |
boolean | No | cooperates with stream:true to request the end usage; empty choices and empty usage are allowed during processing |
temperature |
number | No | Adjust the generated randomness; retain the model default value when not set, and may be fixed or ignored in thinking mode |
top_p |
number | No | Adjust the range of candidate words, usually only one with temperature |
stop |
string / array | No | Stop when encountering the specified text; do not write the end condition as a message role |
response_format |
object | No | {"type":"json_object"} Request JSON, and explicitly require JSON in the message; support is limited by the model and thinking mode |
tools |
array | No | Function tool definition; type is function, function is written with name, description, parameters |
tool_choice |
string / object | No | auto Determined by the model; none disabled; required or specified function needs model support |
parallel_tool_calls |
boolean | No | Whether parallel tool recommendations are allowed, the client should still process each call returned |
News, History and Thoughts
Each request passes in the history required for this round, retaining roles and order. Tool call assistant messages can have no text, but tool_calls must be retained. Some models return reasoning_content (thinking content), which should be saved separately from content (final answer); its original field position will be maintained during multiple rounds of postback.
Different models use different thinking switches, fill them in according to the model page. Do not pass thinking, enable_thinking, and reasoning_effort at the same time to express contradictory settings. The meaning of max_tokens varies by model; models that support max_completion_tokens can use it to limit the complete output, but do not pass both upper limits at the same time.
Request Example
curl --fail-with-body "$SHANHAI_BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $SHANHAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.8-flash",
"messages": [
{
"role": "system",
"content": "你是一位简明的中文助手。"
},
{
"role": "user",
"content": "用一句话介绍ShangHai Do。"
}
],
"max_tokens": 1024,
"stream": false
}'
Continuous output and dosage
Set stream:true; stream_options.include_usage:true can also be requested. The service returns data: events separated by blank lines. There is no guarantee that a network read corresponds to exactly one event.
curl -N --fail-with-body "$SHANHAI_BASE_URL/v1/chat/completions" \
-H "Authorization: Bearer $SHANHAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.8-flash",
"messages": [
{
"role": "user",
"content": "写一段产品介绍。"
}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}'
Read choices[].delta.content and splice them sequentially; reasoning_content is saved independently. The end may only contain usage and choices may be empty, or it may include usage in the last paragraph. Ends after receiving data: [DONE]. When the network is disconnected and there is no end event, the mark answer is not received completely. Do not automatically submit tool requests with external side effects repeatedly.
Tool definition, execution and result return
The first step is to provide the model with the function name, purpose and parameter structure. The following functions are implemented by your application, and this site will not access the weather service for you.
{
"model": "qwen3.8-flash",
"messages": [
{
"role": "user",
"content": "杭州现在天气如何?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询指定城市天气",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": ["city"],
"additionalProperties": false
}
}
}
],
"tool_choice": "auto",
"max_tokens": 1024
}
In the second step, the model may return an assistant message like this:
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_EXAMPLE",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"杭州\"}"
}
}
]
}
The third step is for the application to check whether the function name is in the allowed list, parse and verify the arguments, and then execute the function. Only perform operations allowed by the application, and confirm according to application permissions when operations involving sending, payment, deletion, etc. Append the actual results back to the history together with the original assistant message. The weather in the following example is fake data used to demonstrate the structure and must be replaced with actual results:
{
"model": "qwen3.8-flash",
"messages": [
{
"role": "user",
"content": "杭州现在天气如何?"
},
{
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_EXAMPLE",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"杭州\"}"
}
}
]
},
{
"role": "tool",
"tool_call_id": "call_EXAMPLE",
"content": "{\"city\":\"杭州\",\"weather\":\"示例:晴\",\"temperature_c\":25}"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "查询指定城市天气",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": ["city"],
"additionalProperties": false
}
}
}
],
"tool_choice": "auto",
"max_tokens": 1024
}
The model can then answer based on the tool results. When multiple tool_calls are returned in one round, the results of each id are returned separately. The continuously output function.arguments are fragments, which can be parsed after being merged according to tool_calls[].index. Don't treat function calls as final text, and don't leave out the original assistant message.
JSON output
Set response_format and text commands at the same time; JSON parsing and business field verification still need to be done after receiving. The output is not usable as full JSON when truncated by length. json_schema is not supported by all models and cannot be enabled simply because of interface compatibility.
{
"model": "qwen3.7-plus",
"enable_thinking": false,
"response_format": {
"type": "json_object"
},
"messages": [
{
"role": "user",
"content": "只输出 JSON 对象,含 title 字符串和 steps 字符串数组,主题为产品发布。"
}
],
"max_tokens": 1024
}
Picture Understanding
Image understanding is different from generating images. Models that support visual input can use the following content blocks; the example uses qwen3.7-plus. The address must be able to be downloaded directly, and the local path cannot be filled in. Don't take "the interface accepts an image field" as proof that all models support vision.
{
"model": "qwen3.7-plus",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "描述图中的主体和颜色。"
},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/photo.jpg"
}
}
]
}
],
"max_tokens": 1024
}
Messages Format
system is placed at the top level; max_tokens is required. Requests still use this site’s token, and it is recommended to bring anthropopic-version:2023-06-01.
curl --fail-with-body "$SHANHAI_BASE_URL/v1/messages" \
-H "Authorization: Bearer $SHANHAI_API_KEY" \
-H "Content-Type: application/json" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "qwen3.8-flash",
"system": "用简明中文回答。",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "介绍一下工具调用。"
}
]
}'
The returned content is an array of content blocks, and the text block type is text. Thinking blocks and tool blocks should be processed separately. Tool definition uses name, description, input_schema; after the model returns tool_use (id, name, input), add tool_result to the content of the next user, tool_use_id points to the original id, and content contains the tool result. When stop_reason is tool_use, the tool is executed, and when it is max_tokens, it means truncation.
{
"model": "qwen3.8-flash",
"max_tokens": 1024,
"messages": [
{
"role": "user",
"content": "杭州天气如何?"
},
{
"role": "assistant",
"content": [
{
"type": "tool_use",
"id": "toolu_EXAMPLE",
"name": "get_weather",
"input": {
"city": "杭州"
}
}
]
},
{
"role": "user",
"content": [
{
"type": "tool_result",
"tool_use_id": "toolu_EXAMPLE",
"content": "{\"weather\":\"示例:晴\"}"
}
]
}
],
"tools": [
{
"name": "get_weather",
"description": "查询天气",
"input_schema": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": ["city"],
"additionalProperties": false
}
}
]
}
Parse message_start, content_block_start, content_block_delta, content_block_stop, message_delta, message_stop during streaming; text comes from text_delta.text, and tool parameters come from input_json_delta.partial_json. Messages results cannot be read using Chat's choices.
Responses format
Simple requests can write input as a string; instructions are used to set tasks. The example uses a complete response. The client reads the text from the message content block of output. Do not assume that the original JSON must have an output_text shortcut field.
curl --fail-with-body "$SHANHAI_BASE_URL/v1/responses" \
-H "Authorization: Bearer $SHANHAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.8-flash",
"instructions": "用简明中文回答。",
"input": "介绍一下工具调用。",
"max_output_tokens": 1024,
"stream": false
}'
The function definition places type: function, name, description, parameters directly in tools, and no longer includes the function object. The function_call in the returned output contains call_id, name, and arguments; after the parameters are parsed and executed, the original output items and function_call_output are added to the next round of input, and the call_id must match.
{
"model": "qwen3.8-flash",
"input": [
{
"role": "user",
"content": "杭州天气如何?"
},
{
"type": "function_call",
"call_id": "call_EXAMPLE",
"name": "get_weather",
"arguments": "{\"city\":\"杭州\"}"
},
{
"type": "function_call_output",
"call_id": "call_EXAMPLE",
"output": "{\"weather\":\"示例:晴\"}"
}
],
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "查询天气",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string"
}
},
"required": ["city"],
"additionalProperties": false
}
}
],
"max_output_tokens": 1024
}
This is the usage of explicitly passing history. If the thinking output item is returned, it will also be retained. Functions such as previous_response_id, background tasks, and built-in tools require additional support from the current model service; this article does not treat them as common capabilities of all dialogue models. Streaming reads response.output_text.delta, tool parameters read response.function_call_arguments.delta; judge the final status by response.completed, response.failed or response.incomplete.
Return and error handling
| Condition | Treatment |
|---|---|
| 400 Parameter error | Check the model name, field position, combination constraints and model-specific parameters; modify it and then request |
| 401 / 403 | Check token, permissions, visible models; do not log full token |
| 429 | Wait according to the returned retry prompt and reduce the request frequency |
| 5xx or the connection is interrupted | Save the request number and error; when part of the content has been returned or the tool has been executed, confirm the status before trying again |
| finish_reason:length | Output truncation, upper limit adjustment or history shortening; JSON may be incomplete |
| The tool call returns | and the application continues to the next round; only displaying the tool parameters will not get the final answer |
usage records input, output and total Token number, cache details may appear in prompt_tokens_details.cached_tokens. Different agreement fields have different names, and the amount is subject to the consumption records of this site. Set a reasonable timeout when processing long tasks, and save the request number for troubleshooting.
model details
deepseek-v4-flash-0817、deepseek-v4-pro-0817、deepseek-v4.1-flash、deepseek-v4.1-flash-1017、glm-5.2、glm-5.3、glm-5.3-flash、kimi-k3、qwen3.7-plus、qwen3.7-max、qwen3.8-flash、qwen3.8-max
encountered a problem
If you encounter problems with calling or configuration, please contact the site customer service and provide the model name, task number, error time and error message. Do not provide the complete token.