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();
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.
POST
/
paas
/
v4
/
tokenizer
Text Tokenizer
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();
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.
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.
The task number submitted by the client or generated by the platform when the request was initiated.
Example:
"1"
Was this page helpful?
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Overview - Z.AI DEVELOPER DOCUMENT","description":"Use GLM models like GLM-5.3 \u0026 GLM-5.3-FLASH for AI coding in Claude Code, Kilo Code, Cline, OpenCode, Clawdbot/OpenClaw and more. Plans from $18/month—fast, reliable code generation and tool use for daily dev work.","colors":{"primary":"#141618","light":"#9fa0a0","dark":"#141618"},"logo":{"light":"https://mintcdn.com/zhipu-32152247/B_E8wI-eiNa1QlPV/logo/dark.svg?fit=max\u0026auto=format\u0026n=B_E8wI-eiNa1QlPV\u0026q=85\u0026s=75deefa9dea5bdbc84d4da68885c267f","dark":"https://mintcdn.com/zhipu-32152247/B_E8wI-eiNa1QlPV/logo/light.svg?fit=max\u0026auto=format\u0026n=B_E8wI-eiNa1QlPV\u0026q=85\u0026s=c1ecf1af358fa8eeab8c06052337f8f6","href":"https://z.ai/model-api"},"favicon":"https://mintcdn.com/zhipu-32152247/ZWmez2h5N6TCeIMS/favicon.svg?fit=max\u0026auto=format\u0026n=ZWmez2h5N6TCeIMS\u0026q=85\u0026s=f41adc4aa1fc28f2be33d46791810b1f","api":{"openapi":["openapi.json"],"params":{"expanded":"all"},"playground":{"display":"interactive","proxy":false},"examples":{"defaults":"all","languages":["bash","python","javascript","java"],"prefill":true}},"appearance":{"default":"dark","strict":false},"navbar":{"links":[{"href":"https://z.ai/manage-apikey/apikey-list","label":"API Keys"},{"href":"https://z.ai/manage-apikey/billing","label":"Payment Method"}]},"footer":{"socials":{"x":"https://x.com/Zai_org","github":"https://github.com/zai-org","discord":"https://discord.gg/QR7SARHRxK","linkedin":"https://www.linkedin.com/company/zdotai"}},"contextual":{"options":["copy","view"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"zhipu-32152247","hasAudioNarration":false,"actualSubdomain":"zhipu-32152247","customDomains":["docs.z.ai"],"gitSource":{"type":"github","owner":"zai-doc","repo":"zai-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"feedback":{"thumbs":true},"entitlements":{},"buildId":"6af2e811011c1c69443c6962","clientVersion":"0.0.4124","searchFilterCounts":[{"language":"default","tag":"Guides","count":25},{"language":"default","tag":"API Reference","count":18},{"language":"default","tag":"Coding Plan","count":18},{"language":"default","tag":"Get Started","count":10},{"language":"default","tag":"Guide","count":8},{"language":"default","tag":"Capabilities","count":7},{"language":"default","tag":"SDKs Guide","count":5},{"language":"default","tag":"Agent API","count":4},{"language":"default","tag":"Tool API","count":4},{"language":"default","tag":"GLM Coding Plan","count":4}]},"assistantConfig":{},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":"#footer div:last-child{display:none}.md\\:h-10{height:3rem}.prose-dark :where(a):not(:where([class~=not-prose],[class~=not-prose] *)){font-weight:900}.prose-dark :where(strong):not(:where([class~=not-prose],[class~=not-prose] *)){font-weight:900}"}],"page":{"pagePath":"api-reference/tools/tokenizer","slug":"/api-reference/tools/tokenizer","pageMetadata":{"title":"Tokenizer","openapi":"POST /paas/v4/tokenizer","description":"`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.","href":"/api-reference/tools/tokenizer"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx, jsxs: _jsxs} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n code: \"code\",\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsxs(_components.p, {\n children: [_jsx(_components.code, {\n children: \"Tokenizer\"\n }), \" is used to split text into \", _jsx(_components.code, {\n children: \"tokens\"\n }), \" 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 \", _jsx(_components.code, {\n children: \"token\"\n }), \" count. It is suitable for text length evaluation, model input estimation, dialogue context truncation, cost calculation, etc.\"]\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){return _jsx(_Fragment,{})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Tokenizer","openapi":"POST /paas/v4/tokenizer","description":"`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.","href":"/api-reference/tools/tokenizer"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[],"codeExamples":{}},"jsLinks":[],"openApiReferenceData":{"operation":{"summary":"Text Tokenizer","description":"`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.","requestBody":"7bdbe24e-bbf8-443a-998b-3798b771a19d","responses":{"200":"c3133c7f-10af-41e2-91b6-74791e7ed6ac","default":"e5a7a709-01b8-4f91-908f-9eeed93ba369"},"method":"post","type":"path","servers":["44e4d08f-f7aa-4799-a098-7f934b19b150"],"security":["0d10cd38-a9de-41b0-b59a-512787920e01"],"path":"/paas/v4/tokenizer","baseUrlOptions":["https://api.z.ai/api"],"title":"Text Tokenizer","codeSamples":[],"requestExampleLanguages":["bash","python","javascript","java"],"requiredOnlyExamples":false,"requestExampleType":"generated","responseExampleType":"generated","prefillPlaygroundWithExample":true,"prefillPlaygroundExamples":[{"body.model":"glm-4.6","body.messages.items.0.oneOf.0.role":"user","body.messages.items.0.oneOf.0.content.oneOf.1":"What opportunities and challenges will the Chinese large model industry face in 2025?"}],"disableProxy":true},"dependencies":{"parameters":{},"requestBody":{"content":{"application/json":{"schema":{"type":"object","required":["model","messages"],"properties":{"model":{"type":"string","description":"The model code to be called.","example":"glm-4.6","default":"glm-4.6","enum":["glm-4.6"],"isRequired":true,"uniqueKey":"model","typeLabel":"enum\u003cstring>"},"messages":{"type":"array","description":"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.","items":{"oneOf":[{"type":"object","title":"User Message","required":["role","content"],"properties":{"role":{"type":"string","enum":["user"],"description":"Role of the message author","default":"user","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.role","typeLabel":"enum\u003cstring>"},"content":{"oneOf":[{"type":"array","items":{"oneOf":[{"type":"object","title":"Text","required":["type","text"],"properties":{"type":{"type":"string","enum":["text"],"description":"Content type is text","default":"text","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.0.type","typeLabel":"enum\u003cstring>"},"text":{"type":"string","description":"Text content","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.0.text","typeLabel":"string"}},"additionalProperties":false,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.0","typeLabel":"Text · object"},{"type":"object","title":"Image","required":["type","image_url"],"properties":{"type":{"type":"string","enum":["image_url"],"description":"Content type is image URL","default":"image_url","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.1.type","typeLabel":"enum\u003cstring>"},"image_url":{"type":"object","description":"Image information","properties":{"url":{"type":"string","description":"Image URL or Base64 encoding. Image size limit is under 5M per image, with pixels not exceeding 6000*6000. GLM-5V are limited to 150 sheets.Supports jpg, png, jpeg formats.","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.1.image_url.url","typeLabel":"string"}},"required":["url"],"additionalProperties":false,"isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.1.image_url","typeLabel":"object"}},"additionalProperties":false,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.1","typeLabel":"Image · object"},{"type":"object","title":"Video","required":["type","video_url"],"properties":{"type":{"type":"string","enum":["video_url"],"description":"Content type is video URL","default":"video_url","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.2.type","typeLabel":"enum\u003cstring>"},"video_url":{"type":"object","description":"Video information.","properties":{"url":{"type":"string","description":"Video URL address.The video size is limited to within 200 MB,and the format supports `mp4`,`mkv`,`mov`.","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.2.video_url.url","typeLabel":"string"}},"required":["url"],"additionalProperties":false,"isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.2.video_url","typeLabel":"object"}},"additionalProperties":false,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.2","typeLabel":"Video · object"},{"type":"object","title":"File","required":["type","file"],"properties":{"type":{"type":"string","enum":["file"],"description":"Content type is file. New unified file type, compatible with the legacy `file_url` type but not recommended for new scenarios. Not support passing both the `file` and `image_url` or `video_url` parameters at the same time.","default":"file","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.3.type","typeLabel":"enum\u003cstring>"},"file":{"type":"object","description":"File content, supports one of `file_id`, `file_url`, or `file_data`. Single file size limit is `50M`.","properties":{"file_id":{"type":"string","description":"The ID returned by the [File Upload API](/api-reference/agents/file-upload), only GLM-5.3-Flash series supported.","uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.3.file.file_id","typeLabel":"string"},"file_url":{"type":"string","description":"File URL address. Only GLM-5.3-Flash series. Supports formats such as pdf, txt, word, jsonl, xlsx, pptx, with a maximum of 50.","uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.3.file.file_url","typeLabel":"string"},"file_data":{"type":"string","description":"Base64 file content in the format `data:\u003cMIME>;base64,\u003cBASE64_DATA>`.","uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.3.file.file_data","typeLabel":"string"},"filename":{"type":"string","description":"File name.","uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.3.file.filename","typeLabel":"string"}},"additionalProperties":false,"isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.3.file","typeLabel":"object"}},"additionalProperties":false,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX].oneOf.3","typeLabel":"File · object"}],"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0.items.[INDEX]","typeLabel":"Text · object | Image · object | Video · object | File · object"},"description":"Multimodal message content, supports text, images, video, file","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.0","typeLabel":"(Text · object | Image · object | Video · object | File · object)[]"},{"type":"string","description":"Text message content (can switch to multimodal message above)","example":"What opportunities and challenges will the Chinese large model industry face in 2025?","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content.oneOf.1","typeLabel":"string"}],"isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.0.content","typeLabel":"(Text · object | Image · object | Video · object | File · object)[] | string"}},"uniqueKey":"messages.items.[INDEX].oneOf.0","typeLabel":"User Message · object"},{"type":"object","title":"System Message","required":["role","content"],"properties":{"role":{"type":"string","enum":["system"],"description":"Role of the message author","default":"system","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.1.role","typeLabel":"enum\u003cstring>"},"content":{"type":"string","description":"Message text content","example":"You are a helpful assistant.","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.1.content","typeLabel":"string"}},"uniqueKey":"messages.items.[INDEX].oneOf.1","typeLabel":"System Message · object"},{"type":"object","title":"Assistant Message","description":"Can include tool calls","required":["role"],"properties":{"role":{"type":"string","enum":["assistant"],"description":"Role of the message author","default":"assistant","isRequired":true,"uniqueKey":"messages.items.[INDEX].oneOf.2.role","typeLabel":"enum\u003cstring>"},"content":{"type":"string","description":"Text message content","example":"I'll help you with that analysis.","uniqueKey":"messages.items.[INDEX].oneOf.2.content","typeLabel":"string"}},"uniqueKey":"messages.items.[INDEX].oneOf.2","typeLabel":"Assistant Message · object"}],"uniqueKey":"messages.items.[INDEX]","typeLabel":"User Message · object | System Message · object | Assistant Message · object"},"minItems":1,"isRequired":true,"uniqueKey":"messages","typeLabel":"(User Message · object | System Message · object | Assistant Message · object)[]"},"tools":{"type":"array","items":{"type":"object","title":"Function Call","properties":{"type":{"type":"string","default":"function","enum":["function"],"isRequired":true,"uniqueKey":"tools.items.[INDEX].type","typeLabel":"enum\u003cstring>"},"function":{"type":"object","properties":{"name":{"type":"string","description":"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.","minLength":1,"maxLength":64,"pattern":"^[a-zA-Z0-9_-]+$","isRequired":true,"uniqueKey":"tools.items.[INDEX].function.name","typeLabel":"string"},"description":{"type":"string","description":"A description of what the function does, used by the model to choose when and how to call the function.","isRequired":true,"uniqueKey":"tools.items.[INDEX].function.description","typeLabel":"string"},"parameters":{"type":"object","description":"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.","additionalProperties":true,"isRequired":true,"uniqueKey":"tools.items.[INDEX].function.parameters","typeLabel":"object"}},"required":["name","description","parameters"],"isRequired":true,"uniqueKey":"tools.items.[INDEX].function","typeLabel":"object"}},"required":["type","function"],"additionalProperties":false,"uniqueKey":"tools.items.[INDEX]","typeLabel":"Function Call · object"},"description":"List of tools the model can call. Supports up to `128` functions.","uniqueKey":"tools","typeLabel":"Function Call · object[]"},"request_id":{"type":"string","description":"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.","minLength":6,"maxLength":64,"uniqueKey":"request_id","typeLabel":"string"},"user_id":{"type":"string","description":"Unique ID for the end user, 6–128 characters. Avoid using sensitive information.","minLength":6,"maxLength":128,"uniqueKey":"user_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"Text Tokenization Example":{"title":"Text Tokenization Example","value":{"model":"glm-4.6","messages":[{"role":"user","content":"What opportunities and challenges will the Chinese large model industry face in 2025?"}]}}},"exampleType":"examples"}},"required":true,"exampleType":"examples"},"responses":{"c3133c7f-10af-41e2-91b6-74791e7ed6ac":{"description":"Business processing successful","content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string","example":"20241120141244890ab4ee4af84acf","description":"The task sequence number generated by the Zhipu AI Open Platform. Please use this number when calling the request result interface.","isRequired":true,"uniqueKey":"id","typeLabel":"string"},"usage":{"type":"object","properties":{"prompt_tokens":{"type":"number","description":"Prompt tokens in this input","uniqueKey":"usage.prompt_tokens","typeLabel":"number"},"image_tokens":{"type":"number","description":"Image tokens in this input","uniqueKey":"usage.image_tokens","typeLabel":"number"},"video_tokens":{"type":"number","description":"Video tokens in this input","uniqueKey":"usage.video_tokens","typeLabel":"number"},"total_tokens":{"type":"number","description":"Total tokens in this input","uniqueKey":"usage.total_tokens","typeLabel":"number"}},"isRequired":true,"uniqueKey":"usage","typeLabel":"object"},"created":{"type":"integer","format":"int64","example":1727156815,"uniqueKey":"created","typeLabel":"integer\u003cint64>"},"request_id":{"type":"string","example":"1","description":"The task number submitted by the client or generated by the platform when the request was initiated.","uniqueKey":"request_id","typeLabel":"string"}},"required":["id","usage"],"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"id":"20241120141244890ab4ee4af84acf","usage":{"prompt_tokens":123,"image_tokens":123,"video_tokens":123,"total_tokens":123},"created":1727156815,"request_id":"1"}}},"exampleType":"generated"}},"exampleType":"generated"},"e5a7a709-01b8-4f91-908f-9eeed93ba369":{"description":"The request has failed.","content":{"application/json":{"schema":{"required":["code","message"],"type":"object","description":"The request has failed.","properties":{"code":{"type":"integer","format":"int32","description":"Error code.","isRequired":true,"uniqueKey":"code","typeLabel":"integer\u003cint32>"},"message":{"type":"string","description":"Error message.","isRequired":true,"uniqueKey":"message","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"Example":{"title":"Example","value":{"code":123,"message":"\u003cstring>"}}},"exampleType":"generated"}},"exampleType":"generated"}},"security":{"0d10cd38-a9de-41b0-b59a-512787920e01":{"bearerAuth":{"type":"http","scheme":"bearer","description":"Use the following format for authentication: Bearer [\u003cyour api key>](https://z.ai/manage-apikey/apikey-list)","scopes":[],"schemeName":"bearerAuth"}}},"servers":{"44e4d08f-f7aa-4799-a098-7f934b19b150":{"url":"https://api.z.ai/api","description":"Production server"}},"processedSecurityOptions":[{"schemes":[{"scheme":{"type":"http","scheme":"bearer","description":"Use the following format for authentication: Bearer [\u003cyour api key>](https://z.ai/manage-apikey/apikey-list)","scopes":[],"schemeName":"bearerAuth"},"schema":{"title":"Bearer Auth","type":"string","isRequired":true,"description":"Use the following format for authentication: Bearer [\u003cyour api key>](https://z.ai/manage-apikey/apikey-list)","format":"bearer","typeLabel":"string\u003cbearer>","deprecated":false},"schemeName":"bearerAuth","name":"Authorization"}],"title":"bearerAuth"}]},"originalFileLocation":"openapi.json"},"subdomain":"zhipu-32152247","siteName":"Overview - Z.AI DEVELOPER DOCUMENT","title":"Tokenizer - Overview - Z.AI DEVELOPER DOCUMENT","navMaps":{"firstHrefInVersion":{"English":{"href":"/api-reference/tools/tokenizer","matchLevel":0}},"firstHrefInLanguage":{}},"lastModified":"2026-01-28T15:46:24.868Z","originalFileLocation":"api-reference/tools/tokenizer.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"dark\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"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.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Overview - Z.AI DEVELOPER DOCUMENT\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Tokenizer - Overview - Z.AI DEVELOPER DOCUMENT\">\u003cmeta data-mint-head property=\"og:description\" content=\"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.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Overview - Z.AI DEVELOPER DOCUMENT\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://docs.z.ai/api-reference/tools/tokenizer\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://zhipu-32152247.mintlify.site/_mintlify/api/og/v2?division=Tool+API\u0026amp;title=Tokenizer\u0026amp;description=%60Tokenizer%60+is+used+to+split+text+into+%60tokens%60+recognizable+by+the+model+and+calculate+the+count.+It+receives+user+input+text%2C+processes+it+through+the+model+f\u0026amp;theme=e598d81587661c063148304b\u0026amp;signature=78919d5b8f68054e286e28dac1bfc434eda7444db3f0d02666be61f5da00b936\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Tokenizer - Overview - Z.AI DEVELOPER DOCUMENT\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"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.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://zhipu-32152247.mintlify.site/_mintlify/api/og/v2?division=Tool+API\u0026amp;title=Tokenizer\u0026amp;description=%60Tokenizer%60+is+used+to+split+text+into+%60tokens%60+recognizable+by+the+model+and+calculate+the+count.+It+receives+user+input+text%2C+processes+it+through+the+model+f\u0026amp;theme=e598d81587661c063148304b\u0026amp;signature=78919d5b8f68054e286e28dac1bfc434eda7444db3f0d02666be61f5da00b936\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/zhipu-32152247/ksfquWFAc8TQf_Hb/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Overview - Z.AI DEVELOPER DOCUMENT\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#141618\">\u003clink data-mint-head rel=\"canonical\" href=\"https://docs.z.ai/api-reference/tools/tokenizer\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/api-reference/tools/tokenizer.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://docs.z.ai/#organization\",\"name\":\"Overview - Z.AI DEVELOPER DOCUMENT\",\"url\":\"https://docs.z.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/zhipu-32152247/B_E8wI-eiNa1QlPV/logo/dark.svg?fit=max\u0026auto=format\u0026n=B_E8wI-eiNa1QlPV\u0026q=85\u0026s=75deefa9dea5bdbc84d4da68885c267f\"}},{\"@type\":\"WebSite\",\"@id\":\"https://docs.z.ai#website\",\"name\":\"Overview - Z.AI DEVELOPER DOCUMENT\",\"url\":\"https://docs.z.ai\",\"publisher\":{\"@id\":\"https://docs.z.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://docs.z.ai/api-reference/tools/tokenizer#webpage\",\"url\":\"https://docs.z.ai/api-reference/tools/tokenizer\",\"name\":\"Tokenizer\",\"description\":\"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.\",\"dateModified\":\"2026-01-28T15:46:24.868Z\",\"isPartOf\":{\"@id\":\"https://docs.z.ai#website\"},\"breadcrumb\":{\"@id\":\"https://docs.z.ai/api-reference/tools/tokenizer#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://docs.z.ai/api-reference/tools/tokenizer#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Overview - Z.AI DEVELOPER DOCUMENT\",\"item\":\"https://docs.z.ai\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Tokenizer\",\"item\":\"https://docs.z.ai/api-reference/tools/tokenizer\"}]},{\"@type\":[\"TechArticle\",\"APIReference\"],\"@id\":\"https://docs.z.ai/api-reference/tools/tokenizer#apireference\",\"headline\":\"Tokenizer\",\"name\":\"Tokenizer\",\"description\":\"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.\",\"url\":\"https://docs.z.ai/api-reference/tools/tokenizer\",\"mainEntityOfPage\":{\"@id\":\"https://docs.z.ai/api-reference/tools/tokenizer#webpage\"},\"dateModified\":\"2026-01-28T15:46:24.868Z\",\"publisher\":{\"@id\":\"https://docs.z.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://docs.z.ai#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Overview - Z.AI DEVELOPER DOCUMENT\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Overview - Z.AI DEVELOPER DOCUMENT\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/api-reference/tools/tokenizer.md","siteName":"Overview - Z.AI DEVELOPER DOCUMENT","nav":{"global":null,"versions":[{"version":"English","tabs":[{"tab":"Guides","pages":[{"title":"Guides","href":"/guides/overview/quick-start"}]},{"tab":"API Reference","groups":[{"group":"Using the APIs","pages":[{"title":"Introduction","href":"/api-reference/introduction"},{"title":"Errors","href":"/api-reference/api-code"},{"title":"Rate Limits","url":"https://z.ai/manage-apikey/rate-limits","href":"/api-reference/rate-limit"}]},{"group":"Model API","pages":[{"title":"Chat Completion","openapi":"POST /paas/v4/chat/completions","href":"/api-reference/llm/chat-completion"}]},{"group":"Image API","pages":[{"title":"Generate Image","openapi":"POST /paas/v4/images/generations","href":"/api-reference/image/generate-image"},{"title":"Generate Image(Async)","openapi":"POST /paas/v4/async/images/generations","href":"/api-reference/image/generate-image-async"},{"title":"Retrieve Result","openapi":"GET /paas/v4/async-result/{id}","href":"/api-reference/image/get-image-status"}]},{"group":"Video API","pages":[{"title":"Generate Video(Async)","openapi":"POST /paas/v4/videos/generations","href":"/api-reference/video/generate-video"},{"title":"Retrieve Result","openapi":"GET /paas/v4/async-result/{id}","href":"/api-reference/video/get-video-status"}]},{"group":"Audio API","pages":[{"title":"Audio Transcriptions","openapi":"POST /paas/v4/audio/transcriptions","description":"Use the [GLM-ASR-2512](/guides/audio/glm-asr-2512) model to transcribe audio files into text, supporting multiple languages and real-time streaming transcription.","href":"/api-reference/audio/audio-transcriptions"}]},{"group":"Tool API","pages":[{"title":"Tokenizer","openapi":"POST /paas/v4/tokenizer","href":"/api-reference/tools/tokenizer"},{"title":"Layout Parsing","openapi":"POST /paas/v4/layout_parsing","description":"Use the [GLM-OCR](/guides/vlm/glm-ocr) model to parse the layout of documents and images and extract text content. Support OCR recognition of images and PDF documents, returning detailed layout information and visualization results.","href":"/api-reference/tools/layout-parsing"},{"title":"Web Search","openapi":"POST /paas/v4/web_search","href":"/api-reference/tools/web-search"},{"title":"Web Reader","openapi":"POST /paas/v4/reader","href":"/api-reference/tools/web-reader"}]},{"group":"Agent API","pages":[{"title":"Agent Chat","openapi":"POST /v1/agents","href":"/api-reference/agents/agent"},{"title":"File Upload","openapi":"POST /paas/v4/files","href":"/api-reference/agents/file-upload"},{"title":"Retrieve Result","openapi":"POST /v1/agents/async-result","href":"/api-reference/agents/get-async-result"},{"title":"Conversation History","openapi":"POST /v1/agents/conversation","href":"/api-reference/agents/agent-conversation"}]}]},{"tab":"Coding Plan","pages":[{"title":"Coding Plan","href":"/devpack/overview"}]},{"tab":"Released Notes","pages":[{"title":"Released Notes","href":"/release-notes/new-released"}]},{"tab":"Terms and Policy","pages":[{"title":"Terms and Policy","href":"/legal-agreement/privacy-policy"}]},{"tab":"Help Center","pages":[{"title":"Help Center","href":"/help/faq"}]}]}]},"basePath":"","title":"Tokenizer - Overview - Z.AI DEVELOPER DOCUMENT","buildId":"dpl_8hoxaqFTU7hTr6A2fUraxAyjuiZo","deploymentId":"dpl_8hoxaqFTU7hTr6A2fUraxAyjuiZo","dynamics":["c2aa737661","2b790eda92","b0f84f53ff","a9bb46feb3"],"chunks":["OpenApiReferenceProvider-CDiBsYGW.js","utils-KF9rPlmF.js","cloneDeep-izs3Hzxb.js","_Uint8Array-BVIqJ90l.js","isObjectLike-C8vmzPEN.js","isArray-Dcu1dQ5t.js","utils-C26urKTX.js","toString-BX-iyh8G.js","isSymbol-CSH9U2Gm.js","addUniqueKeysToSchema-BdjmJAC1.js","snippetPresets-3IpDBjt3.js","style-to-object-BY3JEAdk.js","v4-DIgz8zy6.js","conditional-requirements-CFM0id0Q.js","ApiExamples-D4x_2vvo.js","isEqual-BfaiBbcl.js","usePlaygroundInputsStore-BIWdc5Pa.js","shallow-LQqfiMNd.js","getApiPlaygroundDisplay-DryzlOZG.js","CodeSnippet-tcJujU4r.js","CodeSnippets-BHp0nVLL.js","Page-1CZdsdAn.js","getPastedJson-DU-1ayUv.js","icon-CZK2hPr4.js","MethodPill-DOaqmTFC.js","DuplicateIcon-B5-nUxxl.js","createIcon-CDP_U77G.js","DynamicMarkdown-GHvayGOn.js","SectionHeading-BYvpkmUD.js","axios-vUo_bRtp.js","Markdown-uxhlayGT.js","clsx-B35qUV0p.js","lib-DuNMoZ05.js","lib-B8HbPgcC.js","html-void-elements-mCSPHezU.js","dist-BvrGG8gU.js","katex-YMM-FMeD.js","marked.esm-CZWythHk.js","AssistantPageLink-CAf0yVYe.js"]}