Skip to main content
POST
Count Tokens
Estimate the token count before actually calling /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

The fields are the same as /v1/messages (can include system / tools / messages), and you don’t need to provide generation parameters like max_tokens.

Response

Billing

The count_tokens endpoint doesn’t consume model quota, but it is still subject to the OpenPAI gateway’s RPM rate limiting.