Count Tokens
Claude Messages
Count Tokens
POST /v1/messages/count_tokens — estimate token count without billing
POST
Count Tokens
Estimate the token count before actually calling
The fields are the same as
/v1/messages, useful for:
- Checking in advance whether you’ll exceed the context window.
- Precisely estimating cost in batch jobs.
- Showing the token count on the client.
Request
/v1/messages (can include system / tools / messages),
and you don’t need to provide generation parameters like max_tokens.
Response
Billing
Thecount_tokens endpoint doesn’t consume model quota, but it is still subject to the OpenPAI gateway’s RPM rate limiting.