BerriAI/litellm · error · TypeError

`body` on /v1/embeddings batch requests must be a JSON objec

Error message

`body` on /v1/embeddings batch requests must be a JSON object, but was missing or not an object

What it means

Validation while transforming an OpenAI /v1/embeddings batch entry to Vertex Gemini JSONL: the entry's body is missing or not a JSON object, so the required EmbedContentRequest cannot be built. The input at fault is the 'body' field of the JSONL line.

Source

Thrown at litellm/llms/vertex_ai/files/transformation.py:477

    Transforms a single OpenAI `/v1/embeddings` batch entry into Vertex Gemini Embedding
    batch rows, one per requested embedding.

    Example Vertex jsonl
    {"key": "id_1", "request": {"content": {"parts": [{"text": "Hello World"}]}, "output_dimensionality": 768, "task_type": "RETRIEVAL_DOCUMENT"}}

    Note that `content` is singular (an `EmbedContentRequest`, not a
    `GenerateContentRequest`) and that the `custom_id` round-trips through the top-level
    `key`. An `EmbedContentRequest` returns exactly one vector, so an entry whose `input`
    is an array fans out into one row per element and is reassembled on the way back.
    The docs put the per-row config in an `embed_content_config` sibling of `request`,
    but the API rejects that key outright and fails the whole batch job, so the config
    fields go inside the `EmbedContentRequest` itself.

    API Ref: https://cloud.google.com/vertex-ai/generative-ai/docs/embeddings/batch-prediction-genai-embeddings
    """
    openai_request_body = openai_entry.get("body")
    if not isinstance(openai_request_body, dict):
        raise TypeError(
            "`body` on /v1/embeddings batch requests must be a JSON object, but was missing or not an object"
        )
    embedding_input = openai_request_body.get("input")
    if embedding_input is None:
        raise ValueError("`input` is required on /v1/embeddings batch requests, but was not provided")

    elements = _openai_embedding_input_elements(embedding_input)
    if not elements:
        raise ValueError("`input` on /v1/embeddings batch requests must not be empty")

    embed_content_requests = tuple(
        transform_openai_input_gemini_embed_content(
            input=element,
            model=openai_request_body.get("model", ""),
            optional_params=openai_request_body,
        )
        for element in elements
    )

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Send the batch request body as a JSON object.
  2. Include a valid request body on the /v1/embeddings batch request.

Example fix

# ensure each batch line has a JSON object body.
Defensive patterns

Strategy: validation

When it happens

Trigger: Triggered when the body of a /v1/embeddings batch request is missing or not a JSON object.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/7d65f286cf87a84c. Report an issue: GitHub.