{"record":{"id":"d7e0e798bb97598a","repo":"BerriAI/litellm","slug":"query-is-required-for-fireworks-ai-rerank","errorCode":null,"errorMessage":"query is required for Fireworks AI rerank","messagePattern":"query is required for Fireworks AI rerank","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/fireworks_ai/rerank/transformation.py","lineNumber":135,"sourceCode":"        # If 'Authorization' is provided in headers, it overrides the default.\n        if \"Authorization\" in headers:\n            default_headers[\"Authorization\"] = headers[\"Authorization\"]\n\n        # Merge other headers, overriding any default ones except Authorization\n        return {**default_headers, **headers}\n\n    def transform_rerank_request(\n        self,\n        model: str,\n        optional_rerank_params: dict,\n        headers: dict,\n        litellm_params: dict | None = None,\n    ) -> dict:\n        \"\"\"\n        Transform request to Fireworks AI rerank format\n        \"\"\"\n        if \"query\" not in optional_rerank_params:\n            raise ValueError(\"query is required for Fireworks AI rerank\")\n        if \"documents\" not in optional_rerank_params:\n            raise ValueError(\"documents is required for Fireworks AI rerank\")\n\n        # Handle model name - Fireworks AI expects model name like \"fireworks/qwen3-reranker-8b\"\n        # Remove fireworks_ai/ prefix if present\n        if model.startswith(\"fireworks_ai/\"):\n            model = model.replace(\"fireworks_ai/\", \"\")\n\n        # If model doesn't start with \"fireworks/\", add it\n        # But don't add if it already has the prefix\n        if not model.startswith(\"fireworks/\"):\n            model = f\"fireworks/{model}\"\n\n        request_data: Final = {\n            \"model\": model,\n            \"query\": optional_rerank_params[\"query\"],\n            \"documents\": optional_rerank_params[\"documents\"],\n        }","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/fireworks_ai/rerank/transformation.py#L117-L153","documentation":"transform_rerank_request() enforces the Fireworks rerank API contract before building the payload: a 'query' key must exist in optional_rerank_params. Rerank ranks documents against a query, so a request without one cannot be translated and is rejected client-side with this ValueError.","triggerScenarios":"Calling litellm.rerank() with documents (and model/api_key) but omitting query, e.g. litellm.rerank(model='fireworks_ai/...', documents=['a','b']).","commonSituations":"Porting code from a search/embedding API that takes only documents; dynamically built kwargs where the query variable is None or the key is typo'd (e.g. 'search_query'); the query is computed from user input and came back empty/missing in an edge case.","solutions":["Pass query as a positional/keyword argument: litellm.rerank(model=..., query='...', documents=[...]).","If kwargs are built dynamically, validate the dict contains both 'query' and 'documents' (truthy query) before calling rerank.","Check for typos or renaming from another SDK's parameter name (q, search_query, text) to litellm's 'query'."],"exampleFix":"# before\nresults = litellm.rerank(model=\"fireworks_ai/fireworks/qwen3-reranker-8b\", documents=[\"doc1\", \"doc2\"])\n\n# after\nresults = litellm.rerank(model=\"fireworks_ai/fireworks/qwen3-reranker-8b\", query=\"find doc1\", documents=[\"doc1\", \"doc2\"])","handlingStrategy":"validation","validationCode":"def safe_rerank_kwargs(model: str, query: str | None, documents: list[str]) -> dict:\n    if not query:\n        raise ValueError(\"Cannot rerank without a non-empty query\")\n    if not documents:\n        raise ValueError(\"Cannot rerank without documents\")\n    return {\"model\": model, \"query\": query, \"documents\": documents}","typeGuard":"def is_valid_rerank_request(params: dict) -> bool:\n    return (\n        isinstance(params.get(\"query\"), str)\n        and len(params[\"query\"]) > 0\n        and isinstance(params.get(\"documents\"), list)\n        and len(params[\"documents\"]) > 0\n    )","tryCatchPattern":"try:\n    litellm.rerank(**params)\nexcept ValueError as e:\n    if \"query is required\" in str(e):\n        # degrade gracefully: fall back to original document order\n        return list(range(len(params.get(\"documents\", []))))\n    raise","preventionTips":["Always call rerank with explicit keyword arguments — never **dynamically_built_dict without validation.","Short-circuit upstream when user input produced an empty query.","Unit-test the request-building layer for both missing-query and missing-documents cases."],"tags":["fireworks-ai","rerank","validation","request-validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}