PulseAugur
EN
LIVE 00:49:07

tiktoken undercounts Claude tokens, causing prompt failures · 2 sources tracked

A developer discovered that OpenAI's tiktoken library, commonly used for counting tokens in LLM prompts, significantly undercounts tokens for Anthropic's Claude models. This discrepancy, which averaged 14% on the developer's code-heavy inputs, led to numerous "prompt too long" errors when requests neared Claude's context limit. The issue arises because tiktoken uses OpenAI's tokenization vocabulary, which differs from Claude's. The developer found that specific content types like JSON and Python code exacerbated the undercounting. A proposed solution involves an initial estimate with tiktoken and a multiplier, followed by a precise count using Anthropic's `count_tokens` endpoint to trim prompts as needed. AI

IMPACT Highlights the need for precise token counting for LLM API calls, impacting cost estimation and prompt engineering.

RANK_REASON Developer discovers a practical issue with a common tool (tiktoken) when used with a specific AI model (Claude), leading to a workaround.

Read on Mastodon — mastodon.social →

AI-generated summary · Google Gemini · from 2 sources. How we write summaries →

tiktoken undercounts Claude tokens, causing prompt failures · 2 sources tracked

How we ranked this

Signal score
4 / 100
Composite score across the factors below. Higher = stronger signal that this story matters right now.
Newsworthiness bucket
Tool
Developer discovers a practical issue with a common tool (tiktoken) when used with a specific AI model (Claude), leading to a workaround.
Source corroboration
2 independent sources
Multiple independent publishers reporting the same story raises confidence that it's real and newsworthy.
Topics
product, infra
Editorial topic classification. Feeds into how the story surfaces on /topic/<slug> hub pages and into the per-entity coverage mix.
AI-industry relevance
High
Clearly on-topic for AI-industry coverage.
Story freshness
Same-day
Cluster formed today. Ranking reflects the current source set at time of score.

Full methodology in our editorial standards.

COVERAGE [2]

  1. dev.to — LLM tag TIER_1 English(EN) · jidonglab ·

    tiktoken Undercounts Claude Tokens: 37 of 418 Requests Blew the Limit

    <p>My nightly digest job died at 2:14 a.m. with a 400 and the message <code>prompt is too long</code>. My packer had measured the prompt at 181,874 tokens, comfortably under the 200K window. Claude said it was 207,431.</p> <p>That's a 14% gap, and it came from one lazy decision I…

  2. Mastodon — mastodon.social TIER_1 English(EN) · [email protected] ·

    Counting Claude tokens with tiktoken undercounted my prompts by 14%. 37 of 418 requests failed. Here's the audit and the count_tokens fix. # claude # llm # pyth

    Counting Claude tokens with tiktoken undercounted my prompts by 14%. 37 of 418 requests failed. Here's the audit and the count_tokens fix. # claude # llm # python # ai # software # coding # development # engineering # inclusive # community tiktoken Undercounts Claude Tokens: 37 o…