Skip to main content
POST
Estimate Token Count
The input structure for estimate-token-count is almost identical to that of chat completion.
If there is no error field, you can take data.total_tokens as the calculation result.

Authorizations

Authorization
string
header
required

The Authorization header expects a Bearer token. Use an MOONSHOT_API_KEY as the token. This is a server-side secret key. Generate one on the API keys page in your dashboard.

Body

application/json
model
enum<string>
default:kimi-k2.5
required

Model ID

Available options:
kimi-k2.7-code,
kimi-k2.7-code-highspeed,
kimi-k2.6,
kimi-k2.5,
moonshot-v1-8k,
moonshot-v1-32k,
moonshot-v1-128k,
moonshot-v1-auto,
moonshot-v1-8k-vision-preview,
moonshot-v1-32k-vision-preview,
moonshot-v1-128k-vision-preview
messages
object[]
required

A list of messages in the conversation so far. Each element has the format {"role": "user", "content": "Hello"}. role supports system, user, assistant, or tool. content must not be empty

Response

Token count estimation

data
object
required