MCPcopy Index your code
hub / github.com/simstudioai/sim / estimateAnthropicTokens

Function estimateAnthropicTokens

apps/sim/lib/tokenization/estimators.ts:256–276  ·  view source on GitHub ↗

* Anthropic Claude-specific token estimation

(text: string)

Source from the content-addressed store, hash-verified

254 * Anthropic Claude-specific token estimation
255 */
256function estimateAnthropicTokens(text: string): number {
257 const words = text.trim().split(/\s+/)
258 let tokenCount = 0
259
260 for (const word of words) {
261 if (word.length === 0) continue
262
263 if (word.length <= 4) {
264 tokenCount += 1
265 } else if (word.length <= 8) {
266 tokenCount += Math.ceil(word.length / 5)
267 } else {
268 tokenCount += Math.ceil(word.length / 4.5)
269 }
270 }
271
272 const newlineCount = (text.match(/\n/g) || []).length
273 tokenCount += newlineCount * 0.3
274
275 return tokenCount
276}
277
278/**
279 * Google Gemini-specific token estimation

Callers 1

estimateTokenCountFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected