Skip to content

[Bug]: reasoning field in Vercel AI Gateway streaming responses is not processed #16155

@YangJonggyu

Description

@YangJonggyu

What happened?

Describe the bug

Currently, litellm does not properly handle the reasoning field included in the delta object of streaming responses from Vercel AI Gateway. This results in the loss of important reasoning process data provided by the model.

Current Behavior

When Vercel AI Gateway sends a streaming chunk that includes the reasoning field, the information is absent from the final response stream object returned by litellm.

Example Vercel AI Gateway Stream Chunk:

{
    "data": {
        "id": "gen_01K8ZE8RV61CRN3QG42PCAXA39",
        "object": "chat.completion.chunk",
        "model": "minimax/minimax-m2",
        "choices": [
            {
                "index": 0,
                "delta": {
                    "reasoning": " down why the sky appears blue, which is linked to Rayleigh scattering...",
                    "reasoning_details": [...]
                },
                "finish_reason": null
            }
        ]
    }
}

Expected Behavior

Similar to how OpenRouter's streaming responses are handled, the value of the reasoning field should be parsed and included in litellm's standard response model, for instance, as a reasoning_content attribute.

Cause of the issue

The file litellm/llms/custom_llm/vercel_ai_gateway.py lacks a dedicated ChatCompletionStreamingHandler for Vercel AI Gateway's streaming responses. Consequently, the default handler fails to process provider-specific fields like reasoning.

Proposed Solution

  1. Create a VercelAIGatewayChatCompletionStreamingHandler class, taking inspiration from OpenRouterChatCompletionStreamingHandler.
  2. In the chunk_parser method of the new handler, add logic to map the value of choice["delta"]["reasoning"] to choice["delta"]["reasoning_content"].
  3. Implement the get_model_response_iterator method in the VercelAIGatewayConfig class to return an instance of the newly created custom handler.

Relevant log output

Are you a ML Ops Team?

No

What LiteLLM version are you on ?

v1.78.5

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions