翻篇收录说明
翻篇网页快照

Tokenizer - Overview - Z.AI DEVELOPER DOCUMENT

https://docs.z.ai/api-reference/tools/tokenizer

最近抓取:2026-12-03 18:07:26(北京时间)

最近内容变化:2026-12-03 18:07:26(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

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.

正文摘录

Text TokenizercURLcurl --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?" } ] } '200default{ "id": "20241120141244890ab4ee4af84acf", "usage": { "prompt_tokens": 123, "image_tokens": 123, "video_tokens": 123, "total_tokens": 123 }, "created": 1727156815, "request_id": "1" }POST/paas/v4/tokenizerTry itText TokenizercURLcurl --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?" } ] } '200default{ "id": "20241120141244890ab4ee4af84acf", "usage": { "prompt_tokens": 123, "image_tokens": 123, "video_tokens": 123, "total_tokens": 123 }, "created": 1727156815, "request_id": "1" }AuthorizationsAuthorizationstringheaderrequiredUse the following format for authentication: Bearer Bodyapplication/jsonmodelenum<string>default:glm-4.6requiredThe model code to be called.Available options: glm-4.6 Example:"glm-4.6"messages(User Message · object | System Message · object | Assistant Message · object)[]requiredThe 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.Minimum array length: 1User MessageSystem MessageAssistant MessageHide child attributesmessages.roleenum<string>default:userrequiredRole of the message authorAvailable options: user messages.content(Text · object | Image · object | Video · object | File · object)[]stringrequiredMultimodal message content, supports text, images, video, fileTextImageVideoFileHide child attributesmessages.content.typeenum<string>default:textrequiredContent type is textAvailable options: text messages.content.textstringrequiredText contenttoolsFunction Call · object[]List of tools the model can call. Supports up to 128 functions.Hide child attributestools.typeenum<string>default:functionrequiredAvailable options: function tools.functionobjectrequiredHide child attributestools.function.namestringrequiredThe 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.Required string length: 1 - 64Pattern: ^[a-zA-Z0-9_-]+$tools.function.descriptionstringrequiredA description of what the function does, used by the model to choose when and how to call the function.tools.function.parametersobjectrequiredParameters 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.request_idstringPassed 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.Required string length: 6 - 64user_idstringUnique ID for the end user, 6–128 characters. Avoid using sensitive information.Required string length: 6 - 128Response200application/jsonBusiness processing successfulidstringrequiredThe task sequence number generated by the Zhipu AI Open Platform. Please use this number when calling the request result interface.Example:"20241120141244890ab4ee4af84acf"usageobjectrequiredHide child attributesusage.prompt_tokensnumberPrompt tokens in this inputusage.image_tokensnumberImage tokens in this inputusage.video_tokensnumberVideo tokens in this inputusage.total_tokensnumberTotal tokens in this inputcreatedinteger<int64>Example:1727156815request_idstringThe task number submitted by the client or generated by the platform when the request was initiated.Example:"1"Was this page helpful?YesNo