Estimar tokens de LLM
token-estimateEstima heurísticamente cuántos tokens de LLM usa un texto, con un rango de ±25 %. El conteo real depende del tokenizador de cada modelo. Cuándo: un flujo de agente necesita un resultado exacto y repetible para un paso auxiliar (tokens, costos, reintentos, fragmentos, ranking, limpieza de JSON). No para: estimar el costo de llamadas a un LLM a partir de tokens (llm-cost-estimate). Efectos secundarios: ninguno (solo lectura, sin red, sin estado guardado). Determinista: la misma entrada da la misma salida. Límites: entrada JSON de hasta 64 KB, 1 s por llamada, resultado de hasta 1 MB.
EN: Heuristically estimates how many LLM tokens a text uses (Latin text ~4 chars/token, CJK ~1 char/token, code and punctuation denser) with a ±25% range. Real counts depend on each model's tokenizer. When: an agent loop needs an exact, repeatable result for a bookkeeping step (tokens, costs, retries, chunking, ranking, JSON clean-up). [EN completo / full EN: inputSchema.description]
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | Yes | Text (string; required). | |
| context_window | No | Optional context window to compare against (integer; optional; min 1; max 100000000). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| low | No | ||
| fits | No | ||
| high | No | ||
| words | No | ||
| characters | No | ||
| estimated_tokens | No | ||
| percent_of_window | No |