curl --request POST \
--url https://api.z.ai/api/paas/v4/tokenizer \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-4.6",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 2025?"
}
]
}
'import requests
url = "https://api.z.ai/api/paas/v4/tokenizer"
payload = {
"model": "glm-4.6",
"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-4.6',
messages: [
{
role: 'user',
content: 'What opportunities and challenges will the Chinese large model industry face in 2025?'
}
]
})
};
fetch('https://api.z.ai/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://api.z.ai/api/paas/v4/tokenizer")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"glm-4.6\",\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();{
"id": "20241120141244890ab4ee4af84acf",
"usage": {
"prompt_tokens": 123,
"image_tokens": 123,
"video_tokens": 123,
"total_tokens": 123
},
"created": 1727156815,
"request_id": "1"
}{
"code": 123,
"message": "<string>"
}Tokenizer
Tokenizer is used to split text into tokens recognizable by the model and calculate the count. It receives user input text, processes it through the model for tokenization, and finally returns the corresponding token count. It is suitable for text length evaluation, model input estimation, dialogue context truncation, cost calculation, etc.
curl --request POST \
--url https://api.z.ai/api/paas/v4/tokenizer \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "glm-4.6",
"messages": [
{
"role": "user",
"content": "What opportunities and challenges will the Chinese large model industry face in 2025?"
}
]
}
'import requests
url = "https://api.z.ai/api/paas/v4/tokenizer"
payload = {
"model": "glm-4.6",
"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-4.6',
messages: [
{
role: 'user',
content: 'What opportunities and challenges will the Chinese large model industry face in 2025?'
}
]
})
};
fetch('https://api.z.ai/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://api.z.ai/api/paas/v4/tokenizer")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"glm-4.6\",\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();{
"id": "20241120141244890ab4ee4af84acf",
"usage": {
"prompt_tokens": 123,
"image_tokens": 123,
"video_tokens": 123,
"total_tokens": 123
},
"created": 1727156815,
"request_id": "1"
}{
"code": 123,
"message": "<string>"
}Authorizations
Body
The model code to be called.
glm-4.6, glm-4.6v, glm-4.5 "glm-4.6"
The current conversation message list as the model’s prompt input, provided in JSON array format, e.g.,{“role”: “user”, “content”: “Hello”}. Possible message types include system messages, user messages. Note: The input must not consist of system or assistant messages only.
1- User Message
- System Message
- Assistant Message
Hide child attributes
Hide child attributes
Role of the message author
user List of tools the model can call. Supports up to 128 functions.
Hide child attributes
Hide child attributes
function Hide child attributes
Hide child attributes
The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.
1 - 64^[a-zA-Z0-9_-]+$A description of what the function does, used by the model to choose when and how to call the function.
Parameters defined using JSON Schema. Must pass a JSON Schema object to accurately define accepted parameters. Omit if no parameters are needed when calling the function.
Passed by the user side, needs to be unique; used to distinguish each request, 6–64 characters. If not provided by the user side, the platform will generate one by default.
6 - 64Unique ID for the end user, 6–128 characters. Avoid using sensitive information.
6 - 128Response
Business processing successful
The task sequence number generated by the Zhipu AI Open Platform. Please use this number when calling the request result interface.
"20241120141244890ab4ee4af84acf"
1727156815
The task number submitted by the client or generated by the platform when the request was initiated.
"1"
Was this page helpful?