Takes the same headers and the same body as /messages (model, messages, and optionally system and tools) and returns the input token count without generating anything: {"input_tokens": 9}. It isn’t billed, but it counts toward your request rate limit.Errors use Anthropic’s shape, with the request ID in the body and in a request-id header; see the Inference API overview.
Authorizations
xApiKeyinferenceKey
x-api-key
string
header
required
Your inference API key. Send this or Authorization; if you send both, they must carry the same key.
Headers
anthropic-version
string
required
One value, for example 2023-06-01. Missing returns 400.
Example:
"2023-06-01"
Body
application/json
model
string
required
A chat model ID from GET /models. A model that doesn't serve Messages returns 404.
messages
object[]
required
The conversation, alternating user and assistant turns. Content is a string or an array of blocks; replay returned thinking and tool_use blocks, and answer each tool use with a tool_result block carrying its ID.
Show child attributes
system
stringarray · object[]
The system prompt.
tools
object[]
Tool definitions. Support varies by model.
Response
The input token count.
input_tokens
integer
The input token count.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"Pearl Inference Platform","colors":{"primary":"#2A2623","light":"#EFEDEA","dark":"#2A2623"},"logo":{"light":"https://mintcdn.com/pearl-research/qjVPdghcpi_iWwgo/logo/light.svg?fit=max\u0026auto=format\u0026n=qjVPdghcpi_iWwgo\u0026q=85\u0026s=a969569c61ca3aa40012ac0f3dbbe445","dark":"https://mintcdn.com/pearl-research/qjVPdghcpi_iWwgo/logo/dark.svg?fit=max\u0026auto=format\u0026n=qjVPdghcpi_iWwgo\u0026q=85\u0026s=eacd546258e1218dea6ff14f55e89b4c"},"favicon":{"light":"https://mintcdn.com/pearl-research/jPtzRu8ZOdp5WYZT/favicon/pearl-light.svg?fit=max\u0026auto=format\u0026n=jPtzRu8ZOdp5WYZT\u0026q=85\u0026s=97c85bf573b7866d8612883b555a32c7","dark":"https://mintcdn.com/pearl-research/jPtzRu8ZOdp5WYZT/favicon/pearl-dark.svg?fit=max\u0026auto=format\u0026n=jPtzRu8ZOdp5WYZT\u0026q=85\u0026s=9dc503cf63b998d03fa165c37e0921e1"},"api":{"playground":{"display":"interactive"},"examples":{"prefill":true,"autogenerate":false},"url":"full"},"appearance":{"default":"light","strict":true},"background":{"color":{"light":"#EFEEEB"}},"navbar":{"links":[{"href":"mailto:support@pearlresearch.ai","label":"Support"}],"primary":{"type":"button","label":"Dashboard","href":"https://platform.pearlresearch.ai"}},"seo":{"metatags":{"canonical":"https://platform.pearlresearch.ai/docs"}},"fonts":{"heading":{"family":"Urbanist"},"body":{"family":"Inter"}},"contextual":{"options":["copy","view","chatgpt","claude","perplexity","mcp","cursor","vscode"],"display":"header"},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"pearl-research","hasAudioNarration":false,"actualSubdomain":"pearl-research","customDomains":[],"gitSource":{"type":"github","owner":"duplex-foundation","repo":"cloud-platform-docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":"","_id":"6afac147dd50ae575c58a540"},"entitlements":{"AI_CHAT":{"status":"ENABLED"},"WEB_MCP":{"status":"ENABLED"},"NARRATION":{"status":"ENABLED"}},"buildId":"6aff1808a4a19f80cc241c5b","clientVersion":"0.0.4270","searchFilterCounts":[{"language":"default","tag":"Docs","count":37},{"language":"default","tag":"Integrations","count":16},{"language":"default","tag":"Inference API","count":14},{"language":"default","tag":"API Reference","count":12},{"language":"default","tag":"Account \u0026 Billing","count":6},{"language":"default","tag":"Get Started","count":6},{"language":"default","tag":"Management API","count":5},{"language":"default","tag":"Guides","count":2}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"/docs","hasChatPermissions":true,"hasWebMcpPermissions":true,"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":"site-roles","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":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":true},"customCss":[]}
{"page":{"pagePath":"reference/messages/count-tokens","slug":"/reference/messages/count-tokens","pageMetadata":{"title":"Count tokens","description":"Count a Messages request's input tokens without generating.","deprecated":null,"version":null,"sidebarTitle":"Count tokens","openapi":"/openapi/inference.yaml post /messages/count_tokens","href":"/reference/messages/count-tokens","autogeneratedByOpenApi":true},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Count a Messages request’s input tokens without generating.\"\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,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,p:`p`,..._provideComponents(),...props.components};return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`Takes the same headers and the same body as `,_jsx(_components.code,{children:`/messages`}),` (`,_jsx(_components.code,{children:`model`}),`, `,_jsx(_components.code,{children:`messages`}),`, and optionally `,_jsx(_components.code,{children:`system`}),` and `,_jsx(_components.code,{children:`tools`}),`) and returns the input token count without generating anything: `,_jsx(_components.code,{children:`{\"input_tokens\": 9}`}),`. It isn’t billed, but it counts toward your request rate limit.`]}),`\n`,_jsxs(_components.p,{children:[`Errors use Anthropic’s shape, with the request ID in the body and in a `,_jsx(_components.code,{children:`request-id`}),` header; see the `,_jsx(_components.a,{href:`/reference/inference#anthropic`,children:`Inference API overview`}),`.`]})]})}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":"Count tokens","description":"Count a Messages request's input tokens without generating.","deprecated":null,"version":null,"sidebarTitle":"Count tokens","openapi":"/openapi/inference.yaml post /messages/count_tokens","href":"/reference/messages/count-tokens","autogeneratedByOpenApi":true}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[],"codeExamples":{}},"jsLinks":[],"openApiReferenceData":{"operation":{"operationId":"countMessageTokens","summary":"Count tokens","description":"Count a Messages request's input tokens without generating.","security":["befd0612-f75b-4fed-be53-aa5e92fd3974","f3195fe5-6c93-498b-958b-798fefadc3c9"],"x-mint":{"href":"/reference/messages/count-tokens","metadata":{"sidebarTitle":"Count tokens"},"content":"Takes the same headers and the same body as `/messages` (`model`, `messages`, and optionally `system` and `tools`) and returns the input token count without generating anything: `{\"input_tokens\": 9}`. It isn't billed, but it counts toward your request rate limit.\n\nErrors use Anthropic's shape, with the request ID in the body and in a `request-id` header; see the [Inference API overview](/reference/inference#anthropic).\n"},"parameters":["7eeddcb2-f4f4-4d22-97c5-6a988fd21245"],"x-codeSamples":[{"lang":"bash","label":"cURL","source":"curl https://inference.pearlresearch.ai/v1/messages/count_tokens \\\n -H \"x-api-key: $PEARL_API_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"model\":\"YOUR_MODEL_ID\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}]}'\n"}],"requestBody":"4fabe58b-6231-4b80-afe5-b0970bb0220f","responses":{"200":"8af8310a-e3e2-4c51-b57a-8bf9007ff012","400":"c596f79c-6ad5-47c9-a464-90f17d04cfb6","401":"b5d9bf88-a0fe-48b0-a6bd-d8f7f3fabeac","402":"235c6a82-4c55-400d-b9a3-b29cbea69bdd","403":"6459f1aa-734b-448f-ad50-d598507735d9","404":"74756fb0-4ad1-492b-8132-ee6ea23bb9cc","413":"100d48a8-b61e-447c-a4df-c8617e9aec2a","429":"7e8ff89c-e3a3-4800-a41c-2256c7312192","500":"e1b71a41-6082-4d1a-9f0e-552d1e73941d","502":"a2583c69-ffa2-4c00-8eef-cd49f1ab09d3","503":"93b2bd2d-e66f-45f3-8f89-022d43e99a5b","504":"63377c5d-92fc-4e23-87eb-20ee5e1340f0","529":"0875c329-800c-4712-9138-cc40af369728"},"method":"post","type":"path","servers":["f6c31a79-dad6-4767-a559-ec5cffb3ed6a"],"path":"/messages/count_tokens","baseUrlOptions":["https://inference.pearlresearch.ai/v1"],"title":"Count tokens","codeSamples":[{"label":"cURL","lang":"bash","source":"curl https://inference.pearlresearch.ai/v1/messages/count_tokens \\\n -H \"x-api-key: $PEARL_API_KEY\" \\\n -H \"anthropic-version: 2023-06-01\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"model\":\"YOUR_MODEL_ID\",\"messages\":[{\"role\":\"user\",\"content\":\"Hello\"}]}'\n"}],"requiredOnlyExamples":false,"disableCodeSampleGeneration":true,"requestExampleType":"codeSamples","responseExampleType":"generated","prefillPlaygroundWithExample":true,"prefillPlaygroundExamples":[{"body.model":"YOUR_MODEL_ID","body.messages.items.0.role":"user","body.messages.items.0.content.oneOf.0":"Hello"}],"urlDisplay":"full"},"dependencies":{"parameters":{"7eeddcb2-f4f4-4d22-97c5-6a988fd21245":{"name":"anthropic-version","in":"header","required":true,"description":"One value, for example `2023-06-01`. Missing returns `400`.","schema":{"type":"string","example":"2023-06-01","isRequired":true,"description":"One value, for example `2023-06-01`. Missing returns `400`.","uniqueKey":"","typeLabel":"string"},"example":"2023-06-01"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["model","messages"],"properties":{"model":{"type":"string","description":"A chat model ID from `GET /models`. A model that doesn't serve Messages returns `404`.","isRequired":true,"uniqueKey":"model","typeLabel":"string"},"messages":{"type":"array","description":"The conversation, alternating `user` and `assistant` turns. Content is a string or an array of blocks; replay returned `thinking` and `tool_use` blocks, and answer each tool use with a `tool_result` block carrying its ID.","items":{"type":"object","properties":{"role":{"type":"string","enum":["user","assistant"],"uniqueKey":"messages.items.[INDEX].role","typeLabel":"enum\u003cstring>"},"content":{"oneOf":[{"type":"string","title":"string","uniqueKey":"messages.items.[INDEX].content.oneOf.0","typeLabel":"string"},{"type":"array","items":{"type":"object","uniqueKey":"messages.items.[INDEX].content.oneOf.1.items.[INDEX]","typeLabel":"object"},"title":"array","uniqueKey":"messages.items.[INDEX].content.oneOf.1","typeLabel":"array · object[]"}],"uniqueKey":"messages.items.[INDEX].content","typeLabel":"string | array · object[]"}},"uniqueKey":"messages.items.[INDEX]","typeLabel":"object"},"isRequired":true,"uniqueKey":"messages","typeLabel":"object[]"},"system":{"oneOf":[{"type":"string","title":"string","description":"The system prompt.","uniqueKey":"system.oneOf.0","typeLabel":"string"},{"type":"array","items":{"type":"object","uniqueKey":"system.oneOf.1.items.[INDEX]","typeLabel":"object"},"title":"array","description":"The system prompt.","uniqueKey":"system.oneOf.1","typeLabel":"array · object[]"}],"uniqueKey":"system","typeLabel":"string | array · object[]"},"tools":{"type":"array","description":"Tool definitions. Support varies by model.","items":{"type":"object","uniqueKey":"tools.items.[INDEX]","typeLabel":"object"},"uniqueKey":"tools","typeLabel":"object[]"}},"uniqueKey":"","typeLabel":"object"},"example":{"model":"YOUR_MODEL_ID","messages":[{"role":"user","content":"Hello"}]},"examples":{"Example":{"title":"Example","value":{"model":"YOUR_MODEL_ID","messages":[{"role":"user","content":"Hello"}]}}},"exampleType":"examples"}},"exampleType":"examples"},"responses":{"8af8310a-e3e2-4c51-b57a-8bf9007ff012":{"description":"The input token count.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","properties":{"input_tokens":{"type":"integer","description":"The input token count.","uniqueKey":"input_tokens","typeLabel":"integer"}},"uniqueKey":"","typeLabel":"object"},"examples":{"tokenCount":{"title":"tokenCount","summary":"Token count","value":{"input_tokens":9}}},"exampleType":"examples"}},"exampleType":"examples"},"c596f79c-6ad5-47c9-a464-90f17d04cfb6":{"description":"Invalid request: a missing `anthropic-version` or JSON `Content-Type`, malformed JSON, a missing or wrongly typed field, or an unsupported thinking setting.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"missingAnthropicVersion":{"title":"missingAnthropicVersion","summary":"Missing anthropic-version","value":{"type":"error","error":{"type":"invalid_request_error","message":"missing anthropic-version header"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"b5d9bf88-a0fe-48b0-a6bd-d8f7f3fabeac":{"description":"Missing, unknown, revoked, or expired API key, a key over its credit limit, or a management key.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"unknownKey":{"title":"unknownKey","summary":"Unknown API key","value":{"type":"error","error":{"type":"authentication_error","message":"unknown API key"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"235c6a82-4c55-400d-b9a3-b29cbea69bdd":{"description":"Your organization is out of credits. Top up on the [Billing](https://platform.pearlresearch.ai/billing) page, then retry.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"outOfCredits":{"title":"outOfCredits","summary":"Out of credits","value":{"type":"error","error":{"type":"billing_error","message":"your organization is out of credits"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"6459f1aa-734b-448f-ad50-d598507735d9":{"description":"Wrong endpoint for your organization's [inference region](/data-residency).","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"wrongRegion":{"title":"wrongRegion","summary":"Wrong endpoint for the region","value":{"type":"error","error":{"type":"permission_error","message":"wrong endpoint for your organization's inference region"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"74756fb0-4ad1-492b-8132-ee6ea23bb9cc":{"description":"Unknown model (code `model_not_found`), or one this endpoint doesn't serve.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"unknownModel":{"title":"unknownModel","summary":"Unknown model","value":{"type":"error","error":{"type":"not_found_error","message":"unknown model"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"100d48a8-b61e-447c-a4df-c8617e9aec2a":{"description":"Request body over 20 MiB.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"bodyTooLarge":{"title":"bodyTooLarge","summary":"Body over 20 MiB","value":{"type":"error","error":{"type":"request_too_large","message":"request body over 20 MiB"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"7e8ff89c-e3a3-4800-a41c-2256c7312192":{"description":"A [rate limit](/plans) for your organization and the model was reached. Wait for the `Retry-After` header's seconds.","headers":{"Retry-After":{"description":"Seconds to wait before retrying.","schema":{"type":"integer"}},"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"rateLimited":{"title":"rateLimited","summary":"Rate limit reached","value":{"type":"error","error":{"type":"rate_limit_error","message":"rate limit reached"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"e1b71a41-6082-4d1a-9f0e-552d1e73941d":{"description":"Internal error. Safe to retry with backoff.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"internalError":{"title":"internalError","summary":"Internal error","value":{"type":"error","error":{"type":"api_error","message":"internal error"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"a2583c69-ffa2-4c00-8eef-cd49f1ab09d3":{"description":"The model server failed or returned a malformed response. Retry with backoff.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"modelServerFailed":{"title":"modelServerFailed","summary":"Model server failed","value":{"type":"error","error":{"type":"api_error","message":"the model server failed"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"93b2bd2d-e66f-45f3-8f89-022d43e99a5b":{"description":"Temporarily unavailable, for example during a deploy. Retry after the `Retry-After` header's seconds.","headers":{"Retry-After":{"description":"Seconds to wait before retrying.","schema":{"type":"integer"}},"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"unavailable":{"title":"unavailable","summary":"Temporarily unavailable","value":{"type":"error","error":{"type":"api_error","message":"temporarily unavailable"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"63377c5d-92fc-4e23-87eb-20ee5e1340f0":{"description":"The model server timed out. Retry with backoff.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"timedOut":{"title":"timedOut","summary":"Model server timed out","value":{"type":"error","error":{"type":"timeout_error","message":"the model server timed out"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"},"0875c329-800c-4712-9138-cc40af369728":{"description":"No capacity for the model right now (code `no_capacity`). Retry with backoff.","headers":{"X-Request-ID":{"description":"The request ID. Send your own UUID in `X-Request-ID` to use it as the ID. Include the ID when you contact support.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"},"request-id":{"description":"The request ID, the same as `X-Request-ID`.","schema":{"type":"string"},"example":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}},"content":{"application/json":{"schema":{"type":"object","description":"Errors in Anthropic's shape, with the request ID in the body.","properties":{"type":{"type":"string","enum":["error"],"uniqueKey":"type","typeLabel":"enum\u003cstring>"},"error":{"type":"object","properties":{"type":{"type":"string","uniqueKey":"error.type","typeLabel":"string"},"message":{"type":"string","uniqueKey":"error.message","typeLabel":"string"},"code":{"type":"string","description":"Present only when set, for example `no_capacity`.","uniqueKey":"error.code","typeLabel":"string"}},"uniqueKey":"error","typeLabel":"object"},"request_id":{"type":"string","description":"The request ID, also in the `request-id` header.","uniqueKey":"request_id","typeLabel":"string"}},"uniqueKey":"","typeLabel":"object"},"examples":{"noCapacity":{"title":"noCapacity","summary":"No capacity","value":{"type":"error","error":{"type":"overloaded_error","message":"no capacity for the model right now","code":"no_capacity"},"request_id":"6f0b6e0a-6a8f-4c62-9b1e-3d2c1a0f9e87"}}},"exampleType":"examples"}},"exampleType":"examples"}},"security":{"befd0612-f75b-4fed-be53-aa5e92fd3974":{"xApiKey":{"type":"apiKey","in":"header","name":"x-api-key","description":"Your inference API key. Send this or `Authorization`; if you send both, they must carry the same key.","scopes":[],"schemeName":"xApiKey"}},"f3195fe5-6c93-498b-958b-798fefadc3c9":{"inferenceKey":{"type":"http","scheme":"bearer","description":"`Bearer` followed by an inference API key (`sk-prl-infapi-`). Create keys on the [API Keys](https://platform.pearlresearch.ai/api-keys) page. Management keys (`sk-prl-mgmt-`) cannot call models.","scopes":[],"schemeName":"inferenceKey"}}},"servers":{"f6c31a79-dad6-4767-a559-ec5cffb3ed6a":{"url":"https://inference.pearlresearch.ai/v1"}},"processedSecurityOptions":[{"schemes":[{"scheme":{"type":"apiKey","in":"header","name":"x-api-key","description":"Your inference API key. Send this or `Authorization`; if you send both, they must carry the same key.","scopes":[],"schemeName":"xApiKey"},"schema":{"title":"x-api-key","type":"string","description":"Your inference API key. Send this or `Authorization`; if you send both, they must carry the same key.","isRequired":true,"typeLabel":"string","deprecated":false},"schemeName":"xApiKey","name":"x-api-key"}],"title":"xApiKey"},{"schemes":[{"scheme":{"type":"http","scheme":"bearer","description":"`Bearer` followed by an inference API key (`sk-prl-infapi-`). Create keys on the [API Keys](https://platform.pearlresearch.ai/api-keys) page. Management keys (`sk-prl-mgmt-`) cannot call models.","scopes":[],"schemeName":"inferenceKey"},"schema":{"title":"Bearer Auth","type":"string","isRequired":true,"description":"`Bearer` followed by an inference API key (`sk-prl-infapi-`). Create keys on the [API Keys](https://platform.pearlresearch.ai/api-keys) page. Management keys (`sk-prl-mgmt-`) cannot call models.","format":"bearer","typeLabel":"string\u003cbearer>","deprecated":false},"schemeName":"inferenceKey","name":"Authorization"}],"title":"inferenceKey"}]},"originalFileLocation":"openapi/inference.yaml"},"subdomain":"pearl-research","siteName":"Pearl Inference Platform","title":"Count tokens - Pearl Inference Platform","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-11-16T15:31:08.188Z","originalFileLocation":"reference/messages/count-tokens.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=\"light\";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=\"light\"}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=\"Count a Messages request\u0026#x27;s input tokens without generating.\">\u003cmeta data-mint-head name=\"application-name\" content=\"Pearl Inference Platform\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_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=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Count tokens - Pearl Inference Platform\">\u003cmeta data-mint-head property=\"og:description\" content=\"Count a Messages request\u0026#x27;s input tokens without generating.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Pearl Inference Platform\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://pearl-research.mintlify.site/docs/_mintlify/api/og/v2?division=Inference+API\u0026amp;title=Count+tokens\u0026amp;description=Count+a+Messages+request%27s+input+tokens+without+generating.\u0026amp;theme=8053f473600c09a776e77e44\u0026amp;signature=4bce18948e460dfaae572abad9c50494fa1429b84c15a8f87500711ad09dbd96\">\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=\"Count tokens - Pearl Inference Platform\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Count a Messages request\u0026#x27;s input tokens without generating.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://pearl-research.mintlify.site/docs/_mintlify/api/og/v2?division=Inference+API\u0026amp;title=Count+tokens\u0026amp;description=Count+a+Messages+request%27s+input+tokens+without+generating.\u0026amp;theme=8053f473600c09a776e77e44\u0026amp;signature=4bce18948e460dfaae572abad9c50494fa1429b84c15a8f87500711ad09dbd96\">\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=\"/docs/mintlify-assets/_mintlify/favicons/pearl-research/k9be1f6J_artjsFA/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Pearl Inference Platform\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#2A2623\">\u003clink data-mint-head rel=\"canonical\" href=\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/docs/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/docs/reference/messages/count-tokens.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://platform.pearlresearch.ai/#organization\",\"name\":\"Pearl Inference Platform\",\"url\":\"https://platform.pearlresearch.ai\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/pearl-research/qjVPdghcpi_iWwgo/logo/light.svg?fit=max\u0026auto=format\u0026n=qjVPdghcpi_iWwgo\u0026q=85\u0026s=a969569c61ca3aa40012ac0f3dbbe445\"}},{\"@type\":\"WebSite\",\"@id\":\"https://platform.pearlresearch.ai/docs#website\",\"name\":\"Pearl Inference Platform\",\"url\":\"https://platform.pearlresearch.ai/docs\",\"publisher\":{\"@id\":\"https://platform.pearlresearch.ai/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens#webpage\",\"url\":\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens\",\"name\":\"Count tokens\",\"description\":\"Count a Messages request's input tokens without generating.\",\"dateModified\":\"2026-11-16T15:31:08.188Z\",\"isPartOf\":{\"@id\":\"https://platform.pearlresearch.ai/docs#website\"},\"breadcrumb\":{\"@id\":\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Inference API\",\"item\":\"https://platform.pearlresearch.ai/docs/reference/inference\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Count tokens\",\"item\":\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens\"}]},{\"@type\":[\"TechArticle\",\"APIReference\"],\"@id\":\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens#apireference\",\"headline\":\"Count tokens\",\"name\":\"Count tokens\",\"description\":\"Count a Messages request's input tokens without generating.\",\"url\":\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens\",\"mainEntityOfPage\":{\"@id\":\"https://platform.pearlresearch.ai/docs/reference/messages/count-tokens#webpage\"},\"dateModified\":\"2026-11-16T15:31:08.188Z\",\"publisher\":{\"@id\":\"https://platform.pearlresearch.ai/#organization\"},\"isPartOf\":{\"@id\":\"https://platform.pearlresearch.ai/docs#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Pearl Inference Platform\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"Pearl Inference Platform\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/docs/reference/messages/count-tokens.md","siteName":"Pearl Inference Platform","nav":{"global":null,"tabs":[{"tab":"Docs","pages":[{"title":"Docs","href":""}]},{"tab":"API Reference","groups":[{"group":"Inference API","pages":[{"title":"Overview","href":"/reference/inference"},{"title":"Chat completions","deprecated":null,"version":null,"sidebarTitle":"Chat completions","openapi":"/openapi/inference.yaml post /chat/completions","href":"/reference/chat-completions"},{"title":"Responses","deprecated":null,"version":null,"sidebarTitle":"Responses","openapi":"/openapi/inference.yaml post /responses","href":"/reference/responses"},{"title":"Messages","description":"Native Anthropic Messages responses and SSE events for compatible models.","deprecated":null,"version":null,"sidebarTitle":"Messages","openapi":"/openapi/inference.yaml post /messages","href":"/reference/messages"},{"title":"Count tokens","deprecated":null,"version":null,"sidebarTitle":"Count tokens","openapi":"/openapi/inference.yaml post /messages/count_tokens","href":"/reference/messages/count-tokens"},{"title":"Completions (legacy)","description":"Raw-prompt text completion, the pre-chat OpenAI shape, served for tooling that still speaks it.","deprecated":null,"version":null,"sidebarTitle":"Completions (legacy)","openapi":"/openapi/inference.yaml post /completions","href":"/reference/completions"},{"title":"List models","deprecated":null,"version":null,"sidebarTitle":"List models","openapi":"/openapi/inference.yaml get /models","href":"/reference/models"}]},{"group":"Management API","pages":[{"title":"Overview","href":"/reference/management"},{"title":"Rate limits","href":"/reference/management/rate-limits"},{"title":"Get credits","deprecated":null,"version":null,"sidebarTitle":"Credits","openapi":"/openapi/management.yaml get /credits","href":"/reference/management/credits"},{"title":"Get current API key","deprecated":null,"version":null,"sidebarTitle":"Current API key","openapi":"/openapi/management.yaml get /key","href":"/reference/management/key"},{"title":"Get activity","deprecated":null,"version":null,"sidebarTitle":"Activity","openapi":"/openapi/management.yaml get /activity","href":"/reference/management/activity"}]}]}]},"basePath":"","title":"Count tokens - Pearl Inference Platform","deploymentId":"dpl_53YqbBPsHdrqSGqXiWPGU7csRVod","buildId":"dpl_53YqbBPsHdrqSGqXiWPGU7csRVod","dynamics":["c2aa737661","2b790eda92","b0f84f53ff","a9bb46feb3"],"chunks":["OpenApiReferenceProvider-Ku9dSkH0.js","snippetPresets-Cjez4eet.js","utils-BqNa-fnS.js","style-to-object-BY3JEAdk.js","utils-DiE92JCe.js","v4-DIgz8zy6.js","addUniqueKeysToSchema-Bi0DpqVf.js","conditional-requirements-CFM0id0Q.js","cloneDeep-C6xnxscF.js","_Uint8Array-B7g0OYAt.js","isObject-FP1Yky1u.js","ApiExamples-Bf8Ecb5t.js","usePlaygroundInputsStore-BA942cq6.js","shallow-D0sePNkF.js","isEqual-CnnQO8sL.js","CodeSnippets-BTANoy1T.js","CodeSnippet-CTZvgJfu.js","getApiPlaygroundDisplay-BK2o1XYu.js","Page--B9YZ09u.js","DynamicMarkdown-CsgNpZb1.js","SectionHeading-C3K437Dy.js","icon-DlxjjqnB.js","MethodPill-Cr7Ib9nN.js","getPastedJson-DXo3wtHt.js","Check2Icon-ChEI-f_B.js","axios-CsQoIw0U.js","Markdown-CH4mv0N8.js","AssistantPageLink-BHjmqccN.js","dist-DYCPzQwJ.js","lib-DMeTj1gb.js","lib-B8HbPgcC.js","katex-Dbtb6Wk7.js","html-void-elements-mCSPHezU.js","marked.esm-CZWythHk.js"]}