#30217 [Bug] Anthropic `/v1/messages/count_tokens` ignores `api_base` and hardcodes `api.anthropic.com`, breaking self-hosted backends
## Core issue
This is a **routing bug**, not just a tokenizer fallback issue.
LiteLLM supports Anthropic-compatible custom backends using `custom_llm_provider: anthropic` with a custom `api_base`, for example `api_base: http://<self-hosted-backend>/v1`.
In this setup, Anthropic Messages API routes should respect the configured `api_base`.
The normal `/v1/messages` route does this correctly.
However, `/v1/messages/count_tokens` does not. It ignores the configured `api_base` and directly calls the hardcoded Anthropic SaaS endpoint: `https://api.anthropic.com/v1/messages/count_tokens`.
This means one Anthropic sub-route silently bypasses the user-configured backend.
## Why this matters
This breaks valid LiteLLM deployment patterns:
* **self-hosted Anthropic-compatible backends** * **vLLM** serving Anthropic-compatible `/v1/messages` * **air-gapped or firewall-restricted environments** * **Claude Code integrations** routed through LiteLLM to an internal backend
Expected behavior:
`/v1/messages/count_tokens` ā LiteLLM ā configured `api_base` ā `<api_base>/messages/count_tokens`
Actual behavior:
`/v1/messages/count_tokens` ā LiteLLM ā `https://api.anthropic.com/v1/messages/cā¦