文本分词器
curl --request POST \
--url https://open.bigmodel.cn/api/paas/v4/tokenizer \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-5.2",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 2025?"
}
]
}
'import requests
url = "https://open.bigmodel.cn/api/paas/v4/tokenizer"
payload = {
"model": "glm-5.2",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 2025?"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'glm-5.2',
messages: [
{
role: 'user',
content: 'What opportunities and challenges will the Chinese large model industry face in 2025?'
}
]
})
};
fetch('https://open.bigmodel.cn/api/paas/v4/tokenizer', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/paas/v4/tokenizer")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"glm-5.2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What opportunities and challenges will the Chinese large model industry face in 2025?\"\n }\n ]\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/paas/v4/tokenizer"
payload := strings.NewReader("{\n \"model\": \"glm-5.2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What opportunities and challenges will the Chinese large model industry face in 2025?\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/paas/v4/tokenizer",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'glm-5.2',
'messages' => [
[
'role' => 'user',
'content' => 'What opportunities and challenges will the Chinese large model industry face in 2025?'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"id": "20241120141244890ab4ee4af84acf",
"usage": {
"prompt_tokens": 123,
"video_tokens": 123,
"image_tokens": 123,
"total_tokens": 123
},
"created": 1727156815,
"request_id": "1"
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}模型 API
文本分词器
Tokenizer 用于将文本切分为模型可识别的 token 并计算数量。它接收用户输入的文本,通过模型进行分词处理,最终返回对应的 token 数量。适用于文本长度评估、模型输入预估、对话上下文截断、费用计算等。点击 Try it 按钮可快速试用。
POST
/
paas
/
v4
/
tokenizer
文本分词器
curl --request POST \
--url https://open.bigmodel.cn/api/paas/v4/tokenizer \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-5.2",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 2025?"
}
]
}
'import requests
url = "https://open.bigmodel.cn/api/paas/v4/tokenizer"
payload = {
"model": "glm-5.2",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 2025?"
}
]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'glm-5.2',
messages: [
{
role: 'user',
content: 'What opportunities and challenges will the Chinese large model industry face in 2025?'
}
]
})
};
fetch('https://open.bigmodel.cn/api/paas/v4/tokenizer', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));HttpResponse<String> response = Unirest.post("https://open.bigmodel.cn/api/paas/v4/tokenizer")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"glm-5.2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What opportunities and challenges will the Chinese large model industry face in 2025?\"\n }\n ]\n}")
.asString();package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://open.bigmodel.cn/api/paas/v4/tokenizer"
payload := strings.NewReader("{\n \"model\": \"glm-5.2\",\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": \"What opportunities and challenges will the Chinese large model industry face in 2025?\"\n }\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://open.bigmodel.cn/api/paas/v4/tokenizer",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'glm-5.2',
'messages' => [
[
'role' => 'user',
'content' => 'What opportunities and challenges will the Chinese large model industry face in 2025?'
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}{
"id": "20241120141244890ab4ee4af84acf",
"usage": {
"prompt_tokens": 123,
"video_tokens": 123,
"image_tokens": 123,
"total_tokens": 123
},
"created": 1727156815,
"request_id": "1"
}{
"error": {
"code": "<string>",
"message": "<string>"
}
}Body
application/json
调用的模型代码。
Available options:
glm-5.2, glm-5.1, glm-5-turbo, glm-5, glm-4.7, glm-4.6, glm-4.6v, glm-4.5, glm-4.5-air Example:
"glm-5.2"
对话消息列表,包含当前对话的完整上下文信息。每条消息都有特定的角色和内容,模型会根据这些消息生成回复。消息按时间顺序排列,支持角色:system(系统消息,用于设定AI的行为和角色)、user(用户消息,来自用户的输入)、assistant(助手消息,来自AI的回复)。视觉模型支持纯文本和多模态内容(文本、图片、视频、文件)。注意不能只包含系统或助手消息。
Minimum array length:
1- 用户消息
- 系统消息
- 助手消息
Show child attributes
Show child attributes
模型可以调用的工具列表。支持函数调用、知识库检索和网络搜索。使用此参数提供模型可以生成 JSON 输入的函数列表或配置其他工具。最多支持 128 个函数。目前 GLM-4 系列已支持所有 tools,GLM-4.5 已支持 web search 和 retrieval。
Show child attributes
Show child attributes
请求唯一标识符。由用户端传递,ID长度要求:最少6个字符,最多64个字符,建议使用UUID格式确保唯一性,若未提供平台将自动生成。
Required string length:
6 - 64终端用户的唯一ID
Was this page helpful?