BerriAI/litellm · error · ValueError
Unsupported tokenizer type
Error message
Unsupported tokenizer type
What it means
Tokenizer dispatch guard: the loaded tokenizer_json has a 'type' that matches no implemented tokenizer (huggingface or openai_tokenizer), so tokens cannot be computed with the supplied custom tokenizer. Fires when a custom_tokenizer JSON is unsupported.
Solutions
- Use a supported tokenizer type for token counting.
- Install the required tokenizer dependency (e.g. tiktoken) for the model.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/litellm_core_utils/token_counter.py:549 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/a18549cdb9721b7b.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/token_counter.py:549
enc: Final = tokenizer_json["tokenizer"].encode(text)
return len(enc.ids)
elif tokenizer_json["type"] == "openai_tokenizer":
model_to_use: Final = _fix_model_name(model)
try:
if "gpt-4o" in model_to_use:
encoding = tiktoken.get_encoding("o200k_base")
else:
encoding = tiktoken.encoding_for_model(model_to_use)
except KeyError:
print_verbose("Warning: model not found. Using cl100k_base encoding.")
encoding = tiktoken.get_encoding("cl100k_base")
def count_tokens(text: str) -> int:
return len(encoding.encode(text, disallowed_special=()))
else:
raise ValueError("Unsupported tokenizer type")
else:
def count_tokens(text: str) -> int:
return len(default_encoding.encode(text, disallowed_special=()))
return count_tokens
def _fix_model_name(model: str) -> str:
"""We normalize some model names to others"""
if model in litellm.azure_llms:
# azure llms use gpt-35-turbo instead of gpt-3.5-turbo 🙃
return model.replace("-35", "-3.5")
elif model in litellm.open_ai_chat_completion_models:
return model
else:
return "gpt-3.5-turbo"
View on GitHub (pinned to 77b7c6c40c)