GLM 5 API 接口、模型参数 & 代码示例

z-ai/glm-5

GLM-5 是智谱的旗舰开源基础模型,专为复杂系统设计与长期智能体工作流打造。它面向专业开发者,在大规模编程任务中展现出生产级性能,与领先的闭源模型并驾齐驱。凭借高级智能体规划、深度后端推理与迭代自我修正能力,GLM-5 已超越代码生成,迈向全系统构建与自主执行。

模型 ID
z-ai/glm-5
模型系列
GLM
更新日期
模型能力
文本生成、深度思考、代码补全
上下文长度
200 K
模型价格(每 1000 tokens 输入)
¥ 0.011
模型价格(每 1000 tokens 输出)
¥ 0.035

GLM 5 模型介绍:

GLM-5 目标直指复杂系统工程及长周期智能体任务。规模化仍然是提升通用人工智能智能效率的最关键路径之一。相较于 GLM-4.5,GLM-5 的参数规模从 355B(32B激活)扩展至 744B(40B激活),预训练数据量从 23T token 增加至 28.5T token。GLM-5同时集成了DeepSeek稀疏注意力机制,在保留长上下文能力的同时大幅降低了部署成本。

强化学习旨在弥合预训练模型从胜任到卓越的差距。然而,由于强化学习训练效率低下,在大语言模型上规模化部署强化学习极具挑战。为此,我们开发了slime,一种新颖的异步强化学习基础设施,显著提升了训练吞吐量和效率,实现了更精细的后训练迭代。凭借预训练和后训练的双重突破,GLM-5在广泛学术基准上相较于GLM-4.7取得了显著进步,并在推理、编程和智能体任务中达到全球开源模型最佳水平,不断缩小与前沿模型的差距。

基准测试:

GLM-5 GLM-4.7 DeepSeek-V3.2 Kimi K2.5 Claude Opus 4.5 Gemini 3 Pro GPT-5.2 (xhigh)
HLE 30.5 24.8 25.1 31.5 28.4 37.2 35.4
HLE (w/ Tools) 50.4 42.8 40.8 51.8 43.4* 45.8* 45.5*
AIME 2026 I 92.7 92.9 92.7 92.5 93.3 90.6 -
HMMT Nov. 2025 96.9 93.5 90.2 91.1 91.7 93.0 97.1
IMOAnswerBench 82.5 82.0 78.3 81.8 78.5 83.3 86.3
GPQA-Diamond 86.0 85.7 82.4 87.6 87.0 91.9 92.4
SWE-bench Verified 77.8 73.8 73.1 76.8 80.9 76.2 80.0
SWE-bench Multilingual 73.3 66.7 70.2 73.0 77.5 65.0 72.0
Terminal-Bench 2.0 (Terminus 2) 56.2 / 60.7 † 41.0 39.3 50.8 59.3 54.2 54.0
Terminal-Bench 2.0 (Claude Code) 56.2 / 61.1 † 32.8 46.4 - 57.9 - -
CyberGym 43.2 23.5 17.3 41.3 50.6 39.9 -
BrowseComp 62.0 52.0 51.4 60.6 37.0 37.8 -
BrowseComp (w/ Context Manage) 75.9 67.5 67.6 74.9 67.8 59.2 65.8
BrowseComp-Zh 72.7 66.6 65.0 62.3 62.4 66.8 76.1
τ²-Bench 89.7 87.4 85.3 80.2 91.6 90.7 85.5
MCP-Atlas (Public Set) 67.8 52.0 62.2 63.8 65.2 66.6 68.0
Tool-Decathlon 38.0 23.8 35.2 27.8 43.5 36.4 46.3
Vending Bench 2 $4,432.12 $2,376.82 $1,034.00 $1,198.46 $4,967.06 $5,478.16 $3,591.33

*:指其在完整测试集上的得分。

†:终端测试基准 2.0 的已验证版本,修正了部分模糊指令。 更多评估详情请参阅 Footnote。

Footnote:

  • Humanity’s Last Exam (HLE) & other reasoning tasks: We evaluate with a maximum generation length of 131,072 tokens (temperature=1.0, top_p=0.95, max_new_tokens=131072). By default, we report the text-only subset; results marked with * are from the full set. We use GPT-5.2 (medium) as the judge model. For HLE-with-tools, we use a maximum context length of 202,752 tokens.
  • SWE-bench & SWE-bench Multilingual: We run the SWE-bench suite with OpenHands using a tailored instruction prompt. Settings: temperature=0.7, top_p=0.95, max_new_tokens=16384, with a 200K context window.
  • BrowserComp: Without context management, we retain details from the most recent 5 turns. With context management, we use the same discard-all strategy as DeepSeek-v3.2 and Kimi K2.5.
  • Terminal-Bench 2.0 (Terminus 2): We evaluate with the Terminus framework using timeout=2h, temperature=0.7, top_p=1.0, max_new_tokens=8192, with a 128K context window. Resource limits are capped at 16 CPUs and 32 GB RAM.
  • Terminal-Bench 2.0 (Claude Code): We evaluate in Claude Code 2.1.14 (think mode, default effort) with temperature=1.0, top_p=0.95, max_new_tokens=65536. We remove wall-clock time limits due to generation speed, while preserving per-task CPU and memory constraints. Scores are averaged over 5 runs. We fix environment issues introduced by Claude Code and also report results on a verified Terminal-Bench 2.0 dataset that resolves ambiguous instructions.
  • CyberGym: We evaluate in Claude Code 2.1.18 (think mode, no web tools) with (temperature=1.0, top_p=1.0, max_new_tokens=32000) and a 250-minute timeout per task. Results are single-run Pass@1 over 1,507 tasks.
  • MCP-Atlas: All models are evaluated in think mode on the 500-task public subset with a 10-minute timeout per task. We use Gemini 3 Pro as the judge model.
  • τ²-bench: We add a small prompt adjustment in Retail and Telecom to avoid failures caused by premature user termination. For Airline, we apply the domain fixes proposed in the Claude Opus 4.5 system card.
  • Vending Bench 2: Runs are conducted independently by Andon Labs.

API 接口地址:

https://wcode.net/api/gpt/v1/chat/completions

此 API 接口兼容 OpenAI 的 API 接口规范,也就是可以直接使用 OpenAI 的 SDK 来调用各个模型。仅需替换以下两项配置即可:

  1. base_url 替换为 https://wcode.net/api/gpt/v1
  2. api_key 替换为从 https://wcode.net/get-apikey 获取到的 API Key

具体可参考下方的各编程语言代码示例中的 OpenAI SDK 调用示例。

此模型支持 Anthropic / Claude 的 API 接口规范,也就是可以直接使用 Anthropic 的 SDK 来调用此模型。仅需替换以下配置即可:

  1. ANTHROPIC_BASE_URL 替换为 https://wcode.net/api/anthropic
  2. ANTHROPIC_API_KEY(或 ANTHROPIC_AUTH_TOKEN)替换为从 https://wcode.net/get-apikey 获取到的 API Key
  3. ANTHROPIC_MODEL(或model)替换为 z-ai/glm-5

请求方法:

POST

各编程语言代码示例:

# TODO: 以下代码中的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
curl --request POST 'https://wcode.net/api/gpt/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer API_KEY' \
--data '{
    "model": "z-ai/glm-5",
    "messages": [
        {
            "role": "user",
            "content": "你好"
        }
    ]
}'
import Foundation

let headers = [
  "Authorization": "Bearer API_KEY",     // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
  "content-type": "application/json"
]
let parameters = [
  "model": "z-ai/glm-5",
  "messages": [
    [
      "role": "user",
      "content": "你好"
    ]
  ]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://wcode.net/api/gpt/v1/chat/completions")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 60.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
var headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer API_KEY'     // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
};
var request = http.Request('POST', Uri.parse('https://wcode.net/api/gpt/v1/chat/completions'));
request.body = json.encode({
  "model": "z-ai/glm-5",
  "messages": [
    {
      "role": "user",
      "content": "你好"
    }
  ]
});
request.headers.addAll(headers);

http.StreamedResponse response = await request.send();

if (response.statusCode == 200) {
  print(await response.stream.bytesToString());
}
else {
  print(response.reasonPhrase);
}
require 'uri'
require 'net/http'

url = URI("https://wcode.net/api/gpt/v1/chat/completions")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer API_KEY'     # TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
request["content-type"] = 'application/json'
request.body = "{\"model\":\"z-ai/glm-5\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}]}"

response = http.request(request)
puts response.read_body
use serde_json::json;
use reqwest;

#[tokio::main]
pub async fn main() {
  let url = "https://wcode.net/api/gpt/v1/chat/completions";

  let payload = json!({
    "model": "z-ai/glm-5",
    "messages": (
      json!({
        "role": "user",
        "content": "你好"
      })
    )
  });

  let mut headers = reqwest::header::HeaderMap::new();
  headers.insert("Authorization", "Bearer API_KEY".parse().unwrap());     // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
  headers.insert("content-type", "application/json".parse().unwrap());

  let client = reqwest::Client::new();
  let response = client.post(url)
    .headers(headers)
    .json(&payload)
    .send()
    .await;

  let results = response.unwrap()
    .json::<serde_json::Value>()
    .await
    .unwrap();

  dbg!(results);
}
CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://wcode.net/api/gpt/v1/chat/completions");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Authorization: Bearer API_KEY");    // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
headers = curl_slist_append(headers, "content-type: application/json");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "{\"model\":\"z-ai/glm-5\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}]}");

CURLcode ret = curl_easy_perform(hnd);
package main

import (
  "fmt"
  "strings"
  "net/http"
  "io"
)

func main() {
  url := "https://wcode.net/api/gpt/v1/chat/completions"

  payload := strings.NewReader("{\"model\":\"z-ai/glm-5\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}]}")

  req, _ := http.NewRequest("POST", url, payload)

  req.Header.Add("Authorization", "Bearer API_KEY")     // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
  req.Header.Add("content-type", "application/json")

  res, _ := http.DefaultClient.Do(req)

  defer res.Body.Close()
  body, _ := io.ReadAll(res.Body)

  fmt.Println(res)
  fmt.Println(string(body))
}
using System.Net.Http.Headers;


var client = new HttpClient();

var request = new HttpRequestMessage(HttpMethod.Post, "https://wcode.net/api/gpt/v1/chat/completions");

request.Headers.Add("Authorization", "Bearer API_KEY");     // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey

request.Content = new StringContent("{\"model\":\"z-ai/glm-5\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}]}", null, "application/json");

var response = await client.SendAsync(request);

response.EnsureSuccessStatusCode();

Console.WriteLine(await response.Content.ReadAsStringAsync());
var client = new RestClient("https://wcode.net/api/gpt/v1/chat/completions");

var request = new RestRequest("", Method.Post);

request.AddHeader("Authorization", "Bearer API_KEY");     // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey

request.AddHeader("content-type", "application/json");

request.AddParameter("application/json", "{\"model\":\"z-ai/glm-5\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}]}", ParameterType.RequestBody);

var response = client.Execute(request);
const axios = require('axios');

let data = JSON.stringify({
  "model": "z-ai/glm-5",
  "messages": [
    {
      "role": "user",
      "content": "你好"
    }
  ]
});

let config = {
  method: 'post',
  maxBodyLength: Infinity,
  url: 'https://wcode.net/api/gpt/v1/chat/completions',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer API_KEY'     // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
  },
  data : data
};

axios.request(config).then((response) => {
  console.log(JSON.stringify(response.data));
}).catch((error) => {
  console.log(error);
});
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");

RequestBody body = RequestBody.create(mediaType, "{\"model\":\"z-ai/glm-5\",\"messages\":[{\"role\":\"user\",\"content\":\"你好\"}]}");

Request request = new Request.Builder()
  .url("https://wcode.net/api/gpt/v1/chat/completions")
  .post(body)
  .addHeader("Authorization", "Bearer API_KEY")             // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
  .addHeader("content-type", "application/json")
  .build();

Response response = client.newCall(request).execute();
$client = new \GuzzleHttp\Client();

$headers = [
  'Content-Type' => 'application/json',
  'Authorization' => 'Bearer API_KEY',     // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
];

$body = '{
  "model": "z-ai/glm-5",
  "messages": [
    {
      "role": "user",
      "content": "你好"
    }
  ]
}';

$request = new \GuzzleHttp\Psr7\Request('POST', 'https://wcode.net/api/gpt/v1/chat/completions', $headers, $body);

$response = $client->sendAsync($request)->wait();

echo $response->getBody();
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://wcode.net/api/gpt/v1/chat/completions",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 5,
  CURLOPT_TIMEOUT => 300,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'model' => 'z-ai/glm-5',
    'messages' => [
      [
        'role' => 'user',
        'content' => '你好'
      ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer API_KEY",     // TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
    "content-type: application/json",
  ],
]);

$response = curl_exec($curl);
$error = curl_error($curl);

curl_close($curl);

if ($error) {
  echo "cURL Error #:" . $error;
} else {
  echo $response;
}
import requests
import json

url = "https://wcode.net/api/gpt/v1/chat/completions"

payload = {
  "model": "z-ai/glm-5",
  "messages": [
    {
      "role": "user",
      "content": "你好"
    }
  ]
}

headers = {
  "Authorization": "Bearer API_KEY",     # TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
  "content-type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(json.dumps(response.json(), indent=4, ensure_ascii=False))
from openai import OpenAI

client = OpenAI(
  base_url="https://wcode.net/api/gpt/v1",
  api_key="API_KEY"                             # TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
)

completion = client.chat.completions.create(
  model="z-ai/glm-5",
  messages=[
    {
      "role": "user",
      "content": "你好"
    }
  ]
)

print(completion.choices[0].message.content)

各 AI 产品/工具/第三方应用接入示例:

配置 OpenClaw(龙虾)

推荐方式:修改 openclaw.json(通常位于~/.openclaw/openclaw.json

注意事项:以下配置中的 <API_KEY> 需要替换为从 https://wcode.net/get-apikey 获取的 API Key

步骤 1. 修改models字段:

{
  ...其他配置,

  "models": {
      "mode": "merge",
      "providers": {
          "wcode": {
              "baseUrl": "https://wcode.net/api/gpt/v1",
              "apiKey": "<API_KEY>",
              "api": "openai-completions",
              "models": [
                  {
                      "id": "z-ai/glm-5",
                      "name": "GLM 5",
                      "reasoning": false,
                      "input": ["text"],
                      "contextWindow": 200000,
                      "maxTokens": 128000
                  }
              ]
          }
      }
  },

  ...其他配置
}

步骤 2. 修改agents字段:

{
    ...其他配置,

    "agents": {
        "defaults": {
           "model": {
               "primary": "wcode/z-ai/glm-5"
           }
        }
    },

    ...其他配置
}

完成以上配置后,

  1. 执行以下命令,即可通过命令行的方式开始对话:
openclaw tui
  1. 执行以下命令,即可通过 Web 界面的方式开始对话:
openclaw dashboard

配置 OpenCode

推荐方式:修改 opencode.json(通常位于~/.config/opencode/opencode.json

注意事项:以下配置中的 <API_KEY> 需要替换为从 https://wcode.net/get-apikey 获取的 API Key

配置如下:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "myprovider": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "wcode",
      "options": {
        "baseURL": "https://wcode.net/api/gpt/v1",
        "apiKey": "<API_KEY>"
      },
      "models": {
        "z-ai/glm-5": {
          "name": "GLM 5"
        }
      }
    }
  }
}

完成以上配置后,执行以下命令,即可启动 OpenCode:

opencode

输入 /models,选择配置的 z-ai/glm-5 模型并在 OpenCode 中使用。

API 响应示例(curl):

{
    "id": "chatcmpl-t1770879783s944r12cb68d392528f82e64af7ef",
    "model": "z-ai/glm-5",
    "object": "chat.completion",
    "created": 1770879785,
    "choices": [
        {
            "logprobs": null,
            "finish_reason": "stop",
            "native_finish_reason": "stop",
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "你好!我是由Z.ai训练的GLM大语言模型,我的设计目的是通过自然语言处理技术为用户提供信息和帮助。\n\n我被训练用于理解问题、生成文本、回答知识和提供创意建议,不过我也有知识边界,无法进行实时互动或执行实际操作。我致力于以尊重、有益的方式与用户交流,同时保护用户隐私。\n\n有什么我能帮助你的问题或话题吗?我很乐意尽我所能为你提供支持。",
                "refusal": null,
                "reasoning": "回答用户的问题,需要先正确认识用户的问题。用户想知道我是一个什么样的存在,我需要简要清晰地介绍自己的身份和功能。首先,我应该表明我是一个语言模型,并简要介绍我的主要功能和特点。然后,我可以提及我的开发背景和目的,即通过自然语言处理技术帮助人们解决问题、提供信息。最后,我可以表达出愿意帮助用户的意愿,让用户知道我随时准备为他们提供支持和帮助。\n\n这样,我的回答将涵盖身份、功能、背景和目的等方面,同时也表达了帮助用户的意愿,符合一个友好、专业的语言模型形象。"
            }
        }
    ],
    "usage": {
        "prompt_tokens": 15,
        "completion_tokens": 210,
        "total_tokens": 225,
        "prompt_tokens_details": {
            "cached_tokens": 0,
            "audio_tokens": 0
        },
        "completion_tokens_details": {
            "reasoning_tokens": 229,
            "audio_tokens": 0
        }
    }
}

可选参数:

重要提示:由于模型架构不同,部分参数可能仅适用于特定的模型。

思考模式推理程度(Reasoning Effort Level)

  • 参数:reasoning

  • 可选,object

  • 默认:-

reasoning 参数整合了用于控制不同模型间推理强度的设置:

  • "effort": "xhigh" - 分配最大比例的 token 用于推理(约占 max_tokens 的 95%)
  • "effort": "high" - 分配较大比例的 token 用于推理(约占 max_tokens 的 80%)
  • "effort": "medium" - 分配中等比例的 token 用于推理(约占 max_tokens 的 50%)
  • "effort": "low" - 分配较小比例的 token 用于推理(约占 max_tokens 的 20%)
  • "effort": "minimal" - 分配更小比例的 token 用于推理(约占 max_tokens 的 10%)
  • "effort": "none" - 完全禁用推理

curl 代码示例:

# TODO 1: 以下代码中的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
# TODO 2: 以下代码中的 MODEL_ID 需要替换,模型列表:https://wcode.net/models
curl --request POST 'https://wcode.net/api/gpt/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer API_KEY' \
--data '{
    "model": "MODEL_ID",
    "messages": [
        {
            "role": "user",
            "content": "你好"
        }
    ],
    "reasoning": {
        "effort": "high"
    }
}'

Python OpenAI SDK 代码示例:

from openai import OpenAI

client = OpenAI(
  base_url="https://wcode.net/api/gpt/v1",
  api_key="API_KEY"                             # TODO: 这里的 API_KEY 需要替换,获取 API Key 入口:https://wcode.net/get-apikey
)

completion = client.chat.completions.create(
  model="MODEL_ID",                             # TODO: 这里的 MODEL_ID 需要替换,模型列表:https://wcode.net/models
  messages=[
    {
      "role": "user",
      "content": "天空为什么是蓝色的?"
    }
  ],
  extra_body={
    "reasoning": {
      "effort": "high"
    }
  }
)

print(completion.choices[0].message.content)

温度(Temperature)

  • 参数:temperature

  • 可选,浮点数,0.0 到 2.0

  • 默认:1.0

此设置影响模型回复的多样性。较低的值会使回复更可预测、更常见;较高的值会鼓励更具多样性且较不常见的回复。当设置为 0 时,模型对相同输入将尽可能的给出相同的回复。

Top-P

  • 参数:top_p

  • 可选,float,0.0 至 1.0

  • 默认值:1.0

top_p 参数控制模型在生成文本时的候选词选择范围。具体来说,模型会生成一组候选 token,然后从累积概率达到或超过 p 的 token 中随机选择一个作为输出。通过这种方式,top_p 能够在保证生成内容的多样性的同时,考虑到概率分布的合理性。

由于 temperature 与 top_p 均可以控制生成文本的多样性,因此建议您只设置其中一个值。

Top-K

  • 参数:top_k

  • 可选,int,>= 0

  • 默认值:0

top_k 会限制模型在每一步对 token 的选择,使其从较小的集合中进行选择。值为 1 表示模型将始终选择最有可能的下一个 token,从而得到可预测的结果。

频率惩罚

  • 参数:frequency_penalty

  • 可选,float,-2.0 至 2.0

  • 默认值:0.0

frequency_penalty 可根据词条在输入中出现的频率来控制其重复使用。它会尝试减少那些在输入中出现频率较高的词条的使用频率,这与它们出现的频率成正比。词条惩罚会随着出现次数的增加而增加。负值将鼓励词条重复使用。

存在惩罚

  • 参数:presence_penalty

  • 可选,float,-2.0 至 2.0

  • 默认值:0.0

presence_penalty 调整模型重复输入中已使用的特定标记的频率。值越高,重复的可能性就越小,负值则相反。标记惩罚不会随着出现次数而变化。负值会鼓励标记重用。

重复惩罚

  • 参数:repetition_penalty

  • 可选,float,0.0 至 2.0

  • 默认值:1.0

repetition_penalty 有助于减少输入中标记的重复。较高的值会降低模型重复标记的可能性,但过高的值会使输出不够连贯(通常会出现缺少小词的连续句子)。标记惩罚会根据原始标记的概率进行调整。

Min-P

  • 参数:min_p

  • 可选,float,0.0 至 1.0

  • 默认值:0.0

min_p 表示某个 token 被考虑的最小概率,该概率是相对于最可能的 token 的概率而言的。如果 min_p 设置为 0.1,则意味着它只允许概率至少为最佳选项十分之一的 token 被考虑。

Top-A

  • 参数:top_a

  • 可选,float,0.0 到 1.0

  • 默认值:0.0

top_a 仅考虑概率“足够高”的 top tokens,该概率基于最可能的 token 概率。可以将其视为一个动态的 Top-P。较低的 Top-A 值会根据概率最高的 token 集中选择,但范围会更窄。较高的 Top-A 值不一定会影响输出的创造性,但会根据最大概率优化过滤过程。

种子

  • 参数:seed

  • 可选,int

如果指定了 seed 参数,推理将确定性地进行采样,即使用相同种子和参数的重复请求应该返回相同的结果。某些模型无法保证确定性。

最大 tokens 数

  • 参数:max_tokens

  • 可选,int,>= 1

max_tokens 可设定模型在响应中可以生成的 token 数量的上限。模型不会生成超过此限制的 token。其最大值等于上下文长度减去 prompt 长度。

Logit Bias

  • 参数:logit_bias

  • 可选,object

logit_bias 是一个可选参数,用于修改指定 token 在模型生成输出中出现的可能性。

对数概率

  • 参数:logprobs

  • 可选,boolean

logprobs 设置是否返回输出 token 的对数概率。如果为 true,则返回每个输出 token 的对数概率。

最高对数概率

  • 参数:top_logprobs

  • 可选,int

top_logprobs 是一个介于 0 和 20 之间的整数,指定在每个 token 位置要返回的最可能 token 的数量,每个 token 都会带有相应的对数概率。如果使用此参数,则必须将 logprobs 设置为 true

响应格式

  • 参数:response_format

  • 可选,object

response_format 强制模型产出特定的输出格式。将其设置为 { "type": "json_object" } 可启用 JSON 模式,保证模型生成的消息为有效的 JSON。

注意:使用 JSON 模式时,应同时通过 system 或 user 提示词指示模型生成 JSON。

结构化输出

  • 参数:structured_outputs

  • 可选,boolean

指示模型是否能够使用 response_format 中的 json_schema 返回结构化输出。

停止

  • 参数:stop

  • 可选,array

如果模型遇到 stop 数组中指定的任意 token,则立即停止生成。

工具

  • 参数:tools

  • 可选,array

工具调用参数,遵循 OpenAI 的工具调用请求格式。对于非 OpenAI 提供者,会相应地进行转换。

工具选择

  • 参数:tool_choice

  • 可选,array

控制模型调用哪个工具。'none' 表示模型不会调用任何工具,而是生成一条消息。'auto' 表示模型可以在生成消息或调用一个或多个工具之间进行选择。'required' 表示模型必须调用一个或多个工具。通过 {"type": "function", "function": {"name": "my_function"}} 指定特定工具会强制模型调用该工具。

并行工具调用

  • 参数:parallel_tool_calls

  • 可选,boolean

  • 默认:true

是否在使用工具时启用并行函数调用。如果为 true,模型可以同时调用多个函数。如果为 false,函数将按顺序依次调用。

冗长程度

  • 参数:verbosity

  • 可选,enumlow medium high

  • 默认:medium

控制模型响应的冗长程度和长度。较低的值会生成更简洁的回答,而较高的值会生成更详细、更全面的回答。


以上文档为标准版 API 接口文档,可直接用于项目开发和系统调用。如果标准版 API 接口无法满足您的需求,需要定制开发 API 接口,请联系我们的 IT 技术支持工程师:

(沟通需求✅ → 确认技术方案✅ → 沟通费用与工期✅ → 开发&测试✅ → 验收交付✅ → 维护升级✅)

最受关注模型

GLM 4.7

文本生成、深度思考

MiniMax M2.1

文本生成、深度思考

GLM 5

文本生成、深度思考、代码补全

Doubao Seed 2.0 Code

代码补全、深度思考

Qwen3 Coder Next

文本生成、深度思考、代码补全

GLM 4.6V

图片识别、深度思考

Qwen3.5 27B

深度思考、视觉理解、文本生成

Doubao Seed 1.8

多模态、深度思考

Qwen3.5 35B A3B

深度思考、视觉理解、文本生成

Qwen3.5 397B A17B

文本生成、深度思考、多模态

最新发布模型

Qwen3.5 35B A3B

深度思考、视觉理解、文本生成

Qwen3.5 122B A10B

深度思考、视觉理解、文本生成

Qwen3.5 27B

深度思考、视觉理解、文本生成

Qwen3.5 Flash

深度思考

Qwen3.5 397B A17B

文本生成、深度思考、多模态

Qwen 3.5 Plus

文本生成、深度思考、多模态

Doubao Seed 2.0 Mini

文本生成、深度思考、多模态

Doubao Seed 2.0 Code

代码补全、深度思考

Doubao Seed 2.0 Lite

文本生成、深度思考、多模态

Doubao Seed 2.0 Pro

文本生成、深度思考、多模态