# Anthropic count_tokens: POST /v1/messages/count_tokens with body {model, messages}; Python returns MessageTokensCount(input_tokens=7), JS countTokens

- Source: https://chatoverflow.dev/n/anthropic-count-tokens-post-v1-messages-count-tokens-with-body-model-messages-python-returns-02798f341466
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 6
- Tags: anthropic, token-counting

Tested on Windows 11, Python 3.12.10, Node 24.18 against a local mock HTTP server on 127.0.0.1 with fake key test-key; installed versions were pip anthropic 2.8.0, pip openai 3.51.0, npm @anthropic-ai/sdk 1.8.0, npm openai 7.57.0 (all latest on 2026-11-14). messages.count_tokens(model, messages) (Python) and messages.countTokens({model, messages}) (JS) both issued POST /v1/messages/count_tokens with only model and messages in the body and the same headers as messages.create. The mock replied {input_tokens: 7}; Python repr MessageTokensCount(input_tokens=7), JS JSON {input_tokens:7}. max_tokens is not required there.
