Skip to content

Problem proxying the reranker via litellm #11

Description

@oatmealm

I'm was trying to proxy embed-rerank via litellm. embeddings works great but there seems to be an issue with the re-ranker. I've tried cohere compatible api, which keeps failing.

curl http://[litellm]:4000/rerank -H   timeout: 
      "Content-Type: application/json" -H                10s
      "Authorization: Bearer sk-1234" -d
      '{"model":"qwen3-reranker-4b","query":"What is the
       capital of the United
      States?","documents":["Carson City is the capital
      city of Nevada.","Washington, D.C. is the capital
      of the United States."],"top_n":2}')
  ⎿ {                                                        
      "error": {
        "message": "2 validation errors for
    RerankResponse\nresults.0.document\n  Input should be a
    valid dictionary [type=dict_type, input_value=None,
    input_type=NoneType]\n    For further information visit
    https://errors.pydantic.dev/2.10/v/dict_type\nresults.1.d
    ocument\n  Input should be a valid dictionary
    [type=dict_type, input_value=None, input_type=NoneType]\n
        For further information visit
    https://errors.pydantic.dev/2.10/v/dict_type",
        "type": "None",
        "param": "None",
        "code": "500"
      }
    }

According to Claude, embed-rerank should omit the document field entirely when return_documents is false (or not provided), not include it with a null value.

Huggingface api works though.

Activity

  1. self-assigned this
    on Nov 14, 2025
  2. joonsoome commented on Nov 14, 2025

    @joonsoome
    Owner

    @oatmealm

    Thanks a lot for the detailed report and for sharing the curl example – this was very helpful.

    You’re absolutely right about the root cause: on the Cohere‑compatible /v1/rerank (and /v2/rerank) endpoints, embed-rerank is currently returning a document field with a null value when return_documents is false or not provided. For example, responses look like:

    {
      "results": [
        {
          "index": 0,
          "relevance_score": 0.87,
          "document": null
        }
      ],
      "meta": { ... }
    }
    

    However, the Cohere API (and litellm’s RerankResponse model) expect one of two things:

    Either no document field at all, or
    A proper object when return_documents=true.
    Because embed-rerank is sending document: null, litellm’s Pydantic model rejects it with the error you’re seeing (Input should be a valid dictionary for results.[i].document).

    The fix on our side is to make the Cohere rerank endpoints omit document entirely when return_documents is false (or omitted), instead of including it with a null value. Concretely, we’ll update the Cohere router so that the response is serialized with None fields excluded, so the JSON becomes:

    {
      "results": [
        {
          "index": 0,
          "relevance_score": 0.87
          // no "document" field when return_documents=false
        }
      ],
      "meta": { ... }
    }
    

    This matches both Cohere’s behavior and litellm’s expectations.

    As you noted, the HuggingFace/TEI /rerank endpoint already behaves correctly, which is why it works fine in your setup. The issue is specific to the Cohere‑compatible rerank endpoints and their current handling of document.

    I’ll ship this change so that litellm’s Cohere proxy works out of the box. In the meantime, a possible workaround is to use the TEI /rerank or the OpenAI‑style /openai/rerank endpoint, which don’t include null documents.

  3. joonsoome commented on Nov 14, 2025

    @joonsoome
    Owner

    Please check this :
    #13

  4. oatmealm commented on Nov 19, 2025

    @oatmealm
    Author

    So far no issues. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions