{"record":{"id":"a18549cdb9721b7b","repo":"BerriAI/litellm","slug":"unsupported-tokenizer-type","errorCode":null,"errorMessage":"Unsupported tokenizer type","messagePattern":"Unsupported tokenizer type","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/token_counter.py","lineNumber":549,"sourceCode":"                enc: Final = tokenizer_json[\"tokenizer\"].encode(text)\n                return len(enc.ids)\n\n        elif tokenizer_json[\"type\"] == \"openai_tokenizer\":\n            model_to_use: Final = _fix_model_name(model)\n            try:\n                if \"gpt-4o\" in model_to_use:\n                    encoding = tiktoken.get_encoding(\"o200k_base\")\n                else:\n                    encoding = tiktoken.encoding_for_model(model_to_use)\n            except KeyError:\n                print_verbose(\"Warning: model not found. Using cl100k_base encoding.\")\n                encoding = tiktoken.get_encoding(\"cl100k_base\")\n\n            def count_tokens(text: str) -> int:\n                return len(encoding.encode(text, disallowed_special=()))\n\n        else:\n            raise ValueError(\"Unsupported tokenizer type\")\n    else:\n\n        def count_tokens(text: str) -> int:\n            return len(default_encoding.encode(text, disallowed_special=()))\n\n    return count_tokens\n\n\ndef _fix_model_name(model: str) -> str:\n    \"\"\"We normalize some model names to others\"\"\"\n    if model in litellm.azure_llms:\n        # azure llms use gpt-35-turbo instead of gpt-3.5-turbo 🙃\n        return model.replace(\"-35\", \"-3.5\")\n    elif model in litellm.open_ai_chat_completion_models:\n        return model\n    else:\n        return \"gpt-3.5-turbo\"\n","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/token_counter.py#L531-L567","documentation":"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.","triggerScenarios":"Thrown at litellm/litellm_core_utils/token_counter.py:549 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a supported tokenizer type for token counting.","Install the required tokenizer dependency (e.g. tiktoken) for the model."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}