Skip to content

feat(server): add /v1/messages/count_tokens endpoint#90

Open
audreyt wants to merge 1 commit into
antirez:mainfrom
audreyt:feat/count-tokens
Open

feat(server): add /v1/messages/count_tokens endpoint#90
audreyt wants to merge 1 commit into
antirez:mainfrom
audreyt:feat/count-tokens

Conversation

@audreyt
Copy link
Copy Markdown
Contributor

@audreyt audreyt commented May 12, 2026

Anthropic's count_tokens API takes the same request shape as /v1/messages but only returns the prompt token count without running inference. This short-circuits before enqueueing a job: parse_anthropic_request renders and tokenizes the prompt the same way it would for a real generation, then we serialize {"input_tokens": N} and release the request.

Useful for clients that need to plan context budgets before committing to a generation, e.g. the Anthropic SDK token-counting flow.

Anthropic's count_tokens API takes the same request shape as /v1/messages
but only returns the prompt token count without running inference. This
short-circuits before enqueueing a job: parse_anthropic_request renders
and tokenizes the prompt the same way it would for a real generation,
then we serialize {"input_tokens": N} and release the request.

Useful for clients that need to plan context budgets before committing
to a generation, e.g. the Anthropic SDK token-counting flow.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant