SiliconFlow

创建对话请求(OpenAI)

Creates a model response for the given chat conversation.

POST
/chat/completions
AuthorizationBearer <token>required

Use the following format for authentication: Bearer

In: header

modelstringrequired

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.

Example"Pro/zai-org/GLM-4.7"
messagesarray<object>required

A list of messages comprising the conversation so far.

streamboolean

If set, tokens are returned as Server-Sent Events as they are made available. Stream terminates with data: [DONE]

Value infalse | true
max_tokensinteger

The 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.

enable_thinkingboolean

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    
Value infalse | true
thinking_budgetinteger

Maximum number of tokens for chain-of-thought output. This field applies to most Reasoning models.

Range128 <= value <= 32768
reasoning_effortstring

This 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.

Value in"high" | "max"
min_pnumber

Dynamic filtering threshold that adapts based on token probabilities.This field only applies to Qwen3.

Formatfloat
Rangevalue <= 1
stoparray<string> | string | null

Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.

Example"\n"
temperaturenumber

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.

Formatfloat
Rangevalue <= 2
top_pnumber

An 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.

Formatfloat
Rangevalue <= 1
top_knumber
Formatfloat
Rangevalue <= 100
frequency_penaltynumber

Number 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.

Formatfloat
Range-2 <= value <= 2
ninteger

Number of generations to return

Example1
response_formatText | JSON schema | JSON object

An 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.

typestringrequired

The type of response format being defined. Always text.

Value in"text"

JSON Schema response format. Used to generate structured JSON responses.

typestringrequired

The type of response format being defined. Always json_schema.

Value in"json_schema"
json_schemaJSON schemarequired

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.

typestringrequired

The type of response format being defined. Always json_object.

Value in"json_object"
toolsarray<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.

modelstringrequired

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.

Example"deepseek-ai/DeepSeek-OCR"
messagesarray<object>required

A list of messages comprising the conversation so far.

streamboolean

If set, tokens are returned as Server-Sent Events as they are made available. Stream terminates with data: [DONE]

Value intrue | false
max_tokensinteger

The 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.

stoparray<string> | string | null

Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.

Example"\n"
temperaturenumber

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.

Default0.7
Formatfloat
Example0.7
top_pnumber

An 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.

Formatfloat
Example0.7
top_knumber
Default50
Formatfloat
Example50
frequency_penaltynumber

Number 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.

Default0.5
Formatfloat
Example0.5
ninteger

Number of generations to return

Default1
Example1
response_formatText | JSON schema | JSON object

An 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.

typestringrequired

The type of response format being defined. Always text.

Value in"text"

JSON Schema response format. Used to generate structured JSON responses.

typestringrequired

The type of response format being defined. Always json_schema.

Value in"json_schema"
json_schemaJSON schemarequired

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.

typestringrequired

The type of response format being defined. Always json_object.

Value in"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.

idstring
choicesarray<object>
usageobject
createdinteger
modelstring
objectstring
Value in"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"