{"uid":"cap_qTZF4LiOAi9PwQAAwG9bm","slug":"anthropic-token-counter-via-locus-x402-07a3e5a4","name":"Anthropic Token Counter via Locus x402","description":"Claude AI models — chat completions, vision, document processing, extended thinking, and tool use.","url":"https://anthropic.x402.paywithlocus.com/anthropic/count-tokens","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"model":{"type":"string"},"tools":{"type":"array","items":{}},"system":{"anyOf":[{"type":"string"},{"type":"array","items":{}}]},"messages":{"type":"array","items":{"type":"object","required":["role"],"properties":{"name":{"type":"string"},"role":{"type":"string"},"content":{"anyOf":[{"type":"string"},{"type":"array","items":{"type":"object","required":["type"],"properties":{"text":{"type":"string"},"type":{"type":"string"},"image_url":{"type":"object","required":["url"],"properties":{"url":{"type":"string"}},"additionalProperties":true}},"additionalProperties":true}},{"type":"null"}]},"tool_calls":{"type":"array","items":{"type":"object","additionalProperties":true}},"tool_call_id":{"type":"string"}},"additionalProperties":true}}}},"responseSchema":{"type":"json","example":{"data":{},"payment":{"scheme":"exact","settledUsdc":"0.001000","authorizedMaxUsdc":"0.001000"},"request":{"id":"00000000-0000-4000-8000-000000000000","statusUrl":"/requests/00000000-0000-4000-8000-000000000000"},"success":true}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.001","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.001/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.001","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_xyyayko85bBf6ocVJVGCv","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.001","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Counts the number of tokens that would be consumed by a given set of messages, system prompt, and tools for a specified Claude model, without sending a chat completion.","exampleAgentPrompt":"Before sending this conversation to Claude claude-3-5-sonnet-20241022, can you count how many tokens the messages array plus the system prompt would use so I know if we're within the context limit?","exampleUseCases":[{"title":"Pre-flight context window check","prompt":"Count the tokens for this message thread I'm about to send to claude-3-opus-20240229 — I want to make sure it fits within the context window before I actually call it."},{"title":"Tool definition token budgeting","prompt":"How many tokens will my system prompt and these five tool definitions consume when used with claude-3-5-haiku-20241022? I need to know how much room I have left for user messages."},{"title":"Prompt engineering cost audit","prompt":"I have a few different versions of my system prompt — can you run the token counter on each one using claude-3-5-sonnet-20241022 so I can pick the most token-efficient version?"}],"resultDescription":"Returns a token count for the specified model given the provided messages, system prompt, and tool definitions. The response includes a data object with the count result, a payment record showing 0.001 USDC settled, and a request tracking ID with a status URL.","failureModes":["Invalid or unsupported model ID returns an error","Malformed messages array (missing required fields) causes a 400-level error","Payment failure or insufficient USDC balance causes the call to be rejected","Messages exceed maximum allowed size for the token counting endpoint","Missing required 'model' field results in validation error"],"whenToPreferThis":"Use this endpoint when you need to pre-check token consumption before committing to a full Claude chat completion call — ideal for cost estimation, context window validation, and prompt optimization workflows. Prefer this over making a full completion call when you only need token counts and want to avoid generating output. Particularly useful when iterating on system prompts or tool definitions and needing to stay within context limits.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-14T06:31:41.408Z","isFirstParty":false}