创建对话请求(OpenAI)
Creates a model response for the given chat conversation.
Corresponding Model Name. We periodically update our models to enhance service quality. Changes may include model on/offlining or capability adjustments. We will strive to notify you via announcements or push messages. For a complete list of available models, please check the Models.
"Pro/zai-org/GLM-4.7"A list of messages comprising the conversation so far.
If set, tokens are returned as Server-Sent Events as they are made available. Stream terminates with data: [DONE]
false | trueThe maximum number of tokens to generate. Ensure that input tokens + max_tokens do not exceed the model’s context window. As some services are still being updated, avoid setting max_tokens to the window’s upper bound; reserve ~10k tokens as buffer for input and system overhead. See Models for details.
Switches between thinking and non-thinking modes. This field supports the following models:
- Pro/zai-org/GLM-5
- Pro/zai-org/GLM-4.7
- deepseek-ai/DeepSeek-V3.2
- Pro/deepseek-ai/DeepSeek-V3.2
- zai-org/GLM-4.6
- Qwen/Qwen3-8B
- Qwen/Qwen3-14B
- Qwen/Qwen3-32B
- Qwen/Qwen3-30B-A3B
- tencent/Hunyuan-A13B-Instruct
- zai-org/GLM-4.5V
- deepseek-ai/DeepSeek-V3.1-Terminus
- Pro/deepseek-ai/DeepSeek-V3.1-Terminus
- Qwen/Qwen3.5-397B-A17B
- Qwen/Qwen3.5-122B-A10B
- Qwen/Qwen3.5-35B-A3B
- Qwen/Qwen3.5-27B
- Qwen/Qwen3.5-9B
- Qwen/Qwen3.5-4B false | trueMaximum number of tokens for chain-of-thought output. This field applies to most Reasoning models.
128 <= value <= 32768This field only applies to deepseek-ai/DeepSeek-V4-Flash. In thinking mode, the default effort for regular requests is high; for certain complex agent-type requests (such as Claude Code, OpenCode), the effort is automatically set to max. In thinking mode, for compatibility reasons, low and medium are mapped to high, and xhigh is mapped to max.
"high" | "max"Dynamic filtering threshold that adapts based on token probabilities.This field only applies to Qwen3.
floatvalue <= 1Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
"\n"What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
floatvalue <= 2An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
We generally recommend altering this or temperature but not both.
floatvalue <= 1floatvalue <= 100Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
float-2 <= value <= 2Number of generations to return
1An object specifying the format that the model must output.
Setting to { "type": "json_schema", "json_schema": {...} } enables
Structured Outputs which ensures the model will match your supplied JSON
schema.
Setting to { "type": "json_object" } enables the older JSON mode, which
ensures the message the model generates is valid JSON. Using json_schema
is preferred for models that support it.
Default response format. Used to generate text responses.
The type of response format being defined. Always text.
"text"JSON Schema response format. Used to generate structured JSON responses.
The type of response format being defined. Always json_schema.
"json_schema"Structured Outputs configuration options, including a JSON Schema.
Recursive
JSON object response format. An older method of generating JSON responses.
Using json_schema is recommended for models that support it. Note that the
model will not generate JSON without a system or user message instructing it
to do so.
The type of response format being defined. Always json_object.
"json_object"A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.
Corresponding Model Name. To better enhance service quality, we will make periodic changes to the models provided by this service, including but not limited to model on/offlining and adjustments to model service capabilities. We will notify you of such changes through appropriate means such as announcements or message pushes where feasible.For a complete list of available models, please check the Models.
"deepseek-ai/DeepSeek-OCR"A list of messages comprising the conversation so far.
If set, tokens are returned as Server-Sent Events as they are made available. Stream terminates with data: [DONE]
true | falseThe maximum number of tokens to generate. Ensure that input tokens + max_tokens do not exceed the model’s context window. As some services are still being updated, avoid setting max_tokens to the window’s upper bound; reserve ~10k tokens as buffer for input and system overhead. See Models(https://cloud.siliconflow.cn/models) for details.
Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
"\n"What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
0.7float0.7An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
We generally recommend altering this or temperature but not both.
float0.750float50Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.
0.5float0.5Number of generations to return
11An object specifying the format that the model must output.
Setting to { "type": "json_schema", "json_schema": {...} } enables
Structured Outputs which ensures the model will match your supplied JSON
schema.
Setting to { "type": "json_object" } enables the older JSON mode, which
ensures the message the model generates is valid JSON. Using json_schema
is preferred for models that support it.
Default response format. Used to generate text responses.
The type of response format being defined. Always text.
"text"JSON Schema response format. Used to generate structured JSON responses.
The type of response format being defined. Always json_schema.
"json_schema"Structured Outputs configuration options, including a JSON Schema.
Recursive
JSON object response format. An older method of generating JSON responses.
Using json_schema is recommended for models that support it. Note that the
model will not generate JSON without a system or user message instructing it
to do so.
The type of response format being defined. Always json_object.
"json_object"Response Body
The response from the model. The response header contains the x-siliconcloud-trace-id field, which serves as a unique identifier for tracing requests, facilitating log queries and issue troubleshooting.
TypeScript Definitions
Use the response body type in TypeScript.
"chat.completion"curl --request POST \
--url https://api.siliconflow.cn/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "Pro/zai-org/GLM-4.7",
"messages": [
{"role": "system", "content": "你是一个有用的助手x"},
{"role": "user", "content": "你好,请介绍一下你自己"}
]
}'
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.siliconflow.cn/v1"
)
response = client.chat.completions.create(
model="Pro/zai-org/GLM-4.7",
messages=[
{"role": "system", "content": "你是一个有用的助手"},
{"role": "user", "content": "你好,请介绍一下你自己"}
]
)
print(response.choices[0].message.content)
fetch('https://api.siliconflow.cn/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
model: 'Pro/zai-org/GLM-4.7',
messages: [
{role: 'system', content: '你是一个有用的助手x'},
{role: 'user', content: '你好,请介绍一下你自己'}
]
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
curl --request POST \
--url https://api.siliconflow.cn/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "Pro/zai-org/GLM-4.7",
"messages": [
{"role": "system", "content": "你是一个有用的助手"},
{"role": "user", "content": "你好,请介绍一下你自己"}
],
"stream": true
}'
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.siliconflow.cn/v1"
)
response = client.chat.completions.create(
model="Pro/zai-org/GLM-4.7",
messages=[
{"role": "system", "content": "你是一个有用的助手"},
{"role": "user", "content": "你好,请介绍一下你自己"}
],
stream=True
)
print(response.choices[0].message.content)
fetch('https://api.siliconflow.cn/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
model: 'Pro/zai-org/GLM-4.7',
messages: [
{role: 'system', content: '你是一个有用的助手'},
{role: 'user', content: '你好,请介绍一下你自己'}
],
"stream": true,
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
curl --location 'https://api.siliconflow.cn/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{
"model": "zai-org/GLM-4.6V",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What'\''s in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image1.jpg"
}
}
]
}
],
"temperature": 0.7,
"max_tokens": 1000
}'
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.siliconflow.cn/v1"
)
response = client.chat.completions.create(
model="zai-org/GLM-4.6V",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://example.com/image1.jpg",
}
},
],
}
],
max_tokens=300,
)
print(response.choices[0])
fetch('https://api.siliconflow.cn/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
model: 'zai-org/GLM-4.6V',
messages: [
{role: 'user', content: 'What'\''s in this image?'},
{role: 'image_url', image_url: {url: 'https://example.com/image1.jpg'}}
],
temperature: 0.7,
max_tokens: 1000
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
curl --location 'https://api.siliconflow.cn/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{
"model": "Pro/zai-org/GLM-4.7",
"messages": [
{
"role": "user",
"content": "What is the weather like in Boston today?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}'
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.siliconflow.cn/v1"
)
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
}
}
]
messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]
completion = client.chat.completions.create(
model="Pro/zai-org/GLM-4.7",
messages=messages,
tools=tools,
tool_choice="auto"
)
print(completion)
const apiKey = 'YOUR_API_KEY';
fetch('https://api.siliconflow.cn/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
body: JSON.stringify({
model: "Pro/zai-org/GLM-4.7",
messages: [
{
role: "user",
content: "What is the weather like in Boston today?"
}
],
tools: [
{
type: "function",
function: {
name: "get_current_weather",
description: "Get the current weather in a given location",
parameters: {
type: "object",
properties: {
location: {
type: "string",
description: "The city and state, e.g. San Francisco, CA"
},
unit: {
type: "string",
enum: ["celsius", "fahrenheit"]
}
},
required: ["location"]
}
}
}
],
tool_choice: "auto"
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
{
"id": "019bdaa55225ef854b320e9b838f77ce",
"object": "chat.completion",
"created": 1768899826,
"model": "Pro/zai-org/GLM-4.7",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!...",
"reasoning_content": "..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 1540,
"total_tokens": 1555,
"completion_tokens_details": {
"reasoning_tokens": 1190
},
"prompt_tokens_details": {
"cached_tokens": 0
},
"prompt_cache_hit_tokens": 0,
"prompt_cache_miss_tokens": 15
},
"system_fingerprint": ""
}{
"code": 20012,
"message": "string",
"data": "string"
}"Invalid token""Forbidden""404 page not found"{
"message": "Request was rejected due to rate limiting. If you want more, please contact contact@siliconflow.cn. Details:TPM limit reached.",
"data": "string"
}{
"code": 50505,
"message": "Model service overloaded. Please try again later.",
"data": "string"
}"string"