litellm - 💡(How to fix) Fix [Bug]: TypeError: 'async for' requires an object with aiter method, got NoneType when streaming models with reasoning field in delta

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

This call triggers the error

Root Cause

The issue occurs because the streaming parser/proxy fails to gracefully handle the non-standard reasoning key inside the delta object during an asynchronous iteration, resulting in the response object becoming None.

Code Example

import litellm
import asyncio

async def test_stream():
    # This call triggers the error
    response = await litellm.acompletion(
        model="scaleway/gemma-4-26b-a4b-it", 
        messages=[{"role": "user", "content": ""}],
        stream=True
    )
    async for chunk in response:
        print(chunk)

asyncio.run(test_stream())

---

When stream: false, the response is a single object. The reasoning field is present in choices[0].message.reasoning, and LiteLLM handles it correctly.


{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "It looks like your message was empty...",
      "reasoning": "The user sent an empty message..." 
    },
    "finish_reason": "stop"
  }]
}


When stream: true, the reasoning field is moved into the delta object of each chunk. This specific structure causes the LiteLLM streaming iterator to return None.


data: {"id":"...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"reasoning":"Final"},"finish_reason":null}]}
data: {"id":"...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"reasoning":" check"},"finish_reason":null}]}
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

When using stream=True with Scaleway (or any provider returning a reasoning field within the delta object), LiteLLM crashes with a TypeError.

The issue occurs because the streaming parser/proxy fails to gracefully handle the non-standard reasoning key inside the delta object during an asynchronous iteration, resulting in the response object becoming None.

Steps to Reproduce

  1. Use LiteLLM to call a Scaleway model with stream=True.
  2. The provider returns chunks where the delta contains a reasoning key (e.g., {"delta": {"reasoning": "..."}}).
  3. The async iterator fails.
import litellm
import asyncio

async def test_stream():
    # This call triggers the error
    response = await litellm.acompletion(
        model="scaleway/gemma-4-26b-a4b-it", 
        messages=[{"role": "user", "content": ""}],
        stream=True
    )
    async for chunk in response:
        print(chunk)

asyncio.run(test_stream())

Expected LiteLLM should either: Support the reasoning field in the delta object as part of the stream. Or, gracefully catch the unexpected field and continue iterating without returning None.

Actual The execution crashes with: TypeError: 'async for' requires an object with __aiter__ method, got NoneType

Relevant log output

When stream: false, the response is a single object. The reasoning field is present in choices[0].message.reasoning, and LiteLLM handles it correctly.


{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "It looks like your message was empty...",
      "reasoning": "The user sent an empty message..." 
    },
    "finish_reason": "stop"
  }]
}


When stream: true, the reasoning field is moved into the delta object of each chunk. This specific structure causes the LiteLLM streaming iterator to return None.


data: {"id":"...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"reasoning":"Final"},"finish_reason":null}]}
data: {"id":"...","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"reasoning":" check"},"finish_reason":null}]}

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

1.82.6

Twitter / LinkedIn details

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: TypeError: 'async for' requires an object with aiter method, got NoneType when streaming models with reasoning field in delta