Token Counting
Estimate the token count for a message before sending it.
Count tokens
POST
/anthropic/v1/messages/count_tokens
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Required | The model to count tokens for. |
messages | array | Required | The messages to count tokens for. |
system | string/array | Optional | System prompt to include in the count. |
tools | array | Optional | Tools to include in the count. |
Request
cURL
curl https://api.hacxgpt.com/anthropic/v1/messages/count_tokens \
-H "x-api-key: hk-proj-YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "hacxgpt",
"messages": [
{"role": "user", "content": "Hello, how are you?"}
]
}'Response
Response
{
"input_tokens": 25
}Note
Token counts are estimates. Actual token usage during message creation may differ slightly.