BerriAI/litellm · error · Exception
Invalid task_type= . Expected one of=
Error message
Invalid task_type={task_type}. Expected one of={hf_tasks_embeddings} What it means
The sync HF embedding helper validates an explicitly passed task_type against the allowed set ('sentence-similarity', 'feature-extraction', 'rerank', 'embed', 'similarity', matching HF pipeline tags and TEI endpoints). Any other value raises a plain Exception before any request is made. If task_type is omitted, it is auto-derived from the model's pipeline_tag via the Hub API.
Solutions
- Use one of the exact allowed values: sentence-similarity, feature-extraction, rerank, embed, similarity
- Omit task_type entirely to auto-detect from the model's pipeline_tag on the Hub
- For plain embeddings, 'embed' (TEI endpoint) or 'feature-extraction' are the right choices
- Check the literal hf_tasks_embeddings in litellm/llms/huggingface/embedding/handler.py if unsure
Example fix
# before litellm.embedding(model="hf/BAAI/bge-m3", input=["hello"], task_type="text-embedding") # after litellm.embedding(model="hf/BAAI/bge-m3", input=["hello"], task_type="embed") # or omit task_type to auto-detect the pipeline tag
Defensive patterns
Strategy: validation
Validate before calling
ALLOWED = {"sentence-similarity", "feature-extraction", "rerank", "embed", "similarity"}
if task_type is not None and task_type not in ALLOWED:
raise ValueError(f"task_type must be one of {sorted(ALLOWED)}") Type guard
HF_TASK_TYPES = {"sentence-similarity", "feature-extraction", "rerank", "embed", "similarity"}
def is_valid_hf_task_type(t: str | None) -> bool:
return t is None or t in HF_TASK_TYPES Prevention
- Centralize the allowed set as a constant shared across all embedding call sites
- Prefer omitting task_type and letting pipeline_tag auto-detection choose
- Add a unit test asserting your config's task_type values are within the literal set
When it happens
Trigger: litellm.embedding(model='hf/<model>', input=[...], task_type='<bad>') with a value outside the set — e.g. 'text-embedding', 'embedding', or an OpenAI-style task name. Raised from the synchronous path (line 37).
Common situations: Copy-pasting task_type names from other providers (OpenAI/Azure/Vertex); assuming a free-form string; mismatched casing ('Embed'); passing the task name of a different HF model family.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- {error_str}
- reranker requires 2+ sentences
- sentence-similarity requires 2+ sentences
- api_base is required for hosted_vllm embeddings
- Bedrock batch embedding currently supports only Amazon…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/c7ec8fd8c8e5c71a.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/huggingface/embedding/handler.py:37
from .transformation import HuggingFaceEmbeddingConfig
config: Final = HuggingFaceEmbeddingConfig()
HF_HUB_URL: Final = "https://huggingface.co"
hf_tasks_embeddings: Final = (
Literal[ # pipeline tags + hf tei endpoints - https://huggingface.github.io/text-embeddings-inference/#/
"sentence-similarity", "feature-extraction", "rerank", "embed", "similarity"
]
)
def get_hf_task_embedding_for_model(model: str, task_type: str | None, api_base: str) -> str | None:
if task_type is not None:
if task_type in get_args(hf_tasks_embeddings):
return task_type
else:
raise Exception(f"Invalid task_type={task_type}. Expected one of={hf_tasks_embeddings}")
http_client: Final = HTTPHandler(concurrent_limit=1)
model_info: Final = http_client.get(url=f"{api_base}/api/models/{model}")
model_info_dict: Final = model_info.json()
pipeline_tag: Final[str | None] = model_info_dict.get("pipeline_tag", None)
return pipeline_tag
async def async_get_hf_task_embedding_for_model(model: str, task_type: str | None, api_base: str) -> str | None:
if task_type is not None:
if task_type in get_args(hf_tasks_embeddings):
return task_type
else:
raise Exception(f"Invalid task_type={task_type}. Expected one of={hf_tasks_embeddings}")
http_client: Final = get_async_httpx_client(View on GitHub (pinned to 77b7c6c40c)