litellm - 💡(How to fix) Fix [Bug]: /v1/images/edits with mask fails — "Attempted to access streaming request content, without having called read()" [1 participants]

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…
GitHub stats
BerriAI/litellm#26552Fetched 2026-04-27 05:29:36
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Participants
Timeline (top)
labeled ×3

Error Message

litellm.InternalServerError: InternalServerError: OpenAIException - Attempted to access streaming request content, without having called read().

Code Example

litellm.InternalServerError: InternalServerError: OpenAIException - Attempted to access streaming request content, without having called `read()`.

---

curl -X POST "https://<litellm-proxy>/v1/images/edits" \
  -H "Authorization: Bearer <api-key>" \
  -F "model=<openai-model-group>" \
  -F "[email protected]" \
  -F "[email protected]" \
  -F "prompt=Add a tree in the masked area" \
  -F "response_format=b64_json" \
  -F "size=1024x768"

---

{
  "model": "<openai-model-group>",
  "image": ["<_io.BytesIO object at 0x7fb36f41e6b0>"],
  "mask": ["<_io.BytesIO object at 0x7fb36f41d5d0>"],
  "prompt": "...(long prompt)...",
  "response_format": "b64_json",
  "size": "1024x768"
}

---

File "/app/.venv/lib/python3.13/site-packages/litellm/proxy/image_endpoints/endpoints.py", line 311, in image_edit_api
    return await processor.base_process_llm_request(
  File "/app/.venv/lib/python3.13/site-packages/litellm/proxy/common_request_processing.py", line 1068, in base_process_llm_request
    responses = await llm_responses
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5160, in async_wrapper
    return await self._ageneric_api_call_with_fallbacks(...)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 3810, in _ageneric_api_call_with_fallbacks
    raise e
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 3797, in _ageneric_api_call_with_fallbacks
    response = await self.async_function_with_fallbacks(**kwargs)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5634, in async_function_with_fallbacks
    return await self.async_function_with_fallbacks_common_utils(...)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5591, in async_function_with_fallbacks_common_utils
    raise original_exception
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5549, in async_function_with_fallbacks_common_utils
    raise original_exception
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5625, in async_function_with_fallbacks
    response = await self.async_function_with_retries(*args, **kwargs)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5888, in async_function_with_retries
    raise original_exception
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5817, in async_function_with_retries
    response = await self.make_call(original_function, *args, **kwargs)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5899, in make_call
    response = await response
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 3939, in _ageneric_api_call_with_fallbacks_helper
    raise e
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 3925, in _ageneric_api_call_with_fallbacks_helper
    response = await response
  File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 2097, in wrapper_async
    raise e
  File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 1896, in wrapper_async
    result = await original_function(*args, **kwargs)
  File "/app/.venv/lib/python3.13/site-packages/litellm/images/main.py", line 1064, in aimage_edit
    raise litellm.exception_type(
        model=model, ...)
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2456, in exception_type
    raise e
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 588, in exception_type
    raise InternalServerError(...)
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?

Sending a POST /v1/images/edits request with image, mask, prompt, size, and response_format through the LiteLLM proxy to an OpenAI model results in 500 with:

litellm.InternalServerError: InternalServerError: OpenAIException - Attempted to access streaming request content, without having called `read()`.

The request is well-formed multipart/form-data with a single image file and a single mask file (both PNG). The error occurs consistently on every retry (2 retries attempted).

This appears to be an httpx.RequestNotRead exception surfacing inside the image edit handler — the proxy seems to try accessing the streamed request body without calling .read() first.

Expected behavior: The proxy should forward the multipart form data to OpenAI's /v1/images/edits endpoint and return the edited image as b64_json.

Steps to Reproduce

curl -X POST "https://<litellm-proxy>/v1/images/edits" \
  -H "Authorization: Bearer <api-key>" \
  -F "model=<openai-model-group>" \
  -F "[email protected]" \
  -F "[email protected]" \
  -F "prompt=Add a tree in the masked area" \
  -F "response_format=b64_json" \
  -F "size=1024x768"

The client is a Node.js app using the Fetch API with FormData (undici). Single image, single mask, both sent as PNG blobs.

Request details from logs:

{
  "model": "<openai-model-group>",
  "image": ["<_io.BytesIO object at 0x7fb36f41e6b0>"],
  "mask": ["<_io.BytesIO object at 0x7fb36f41d5d0>"],
  "prompt": "...(long prompt)...",
  "response_format": "b64_json",
  "size": "1024x768"
}

Note: both image and mask are received as lists with a single BytesIO element each.

Relevant log output

File "/app/.venv/lib/python3.13/site-packages/litellm/proxy/image_endpoints/endpoints.py", line 311, in image_edit_api
    return await processor.base_process_llm_request(
  File "/app/.venv/lib/python3.13/site-packages/litellm/proxy/common_request_processing.py", line 1068, in base_process_llm_request
    responses = await llm_responses
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5160, in async_wrapper
    return await self._ageneric_api_call_with_fallbacks(...)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 3810, in _ageneric_api_call_with_fallbacks
    raise e
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 3797, in _ageneric_api_call_with_fallbacks
    response = await self.async_function_with_fallbacks(**kwargs)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5634, in async_function_with_fallbacks
    return await self.async_function_with_fallbacks_common_utils(...)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5591, in async_function_with_fallbacks_common_utils
    raise original_exception
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5549, in async_function_with_fallbacks_common_utils
    raise original_exception
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5625, in async_function_with_fallbacks
    response = await self.async_function_with_retries(*args, **kwargs)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5888, in async_function_with_retries
    raise original_exception
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5817, in async_function_with_retries
    response = await self.make_call(original_function, *args, **kwargs)
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 5899, in make_call
    response = await response
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 3939, in _ageneric_api_call_with_fallbacks_helper
    raise e
  File "/app/.venv/lib/python3.13/site-packages/litellm/router.py", line 3925, in _ageneric_api_call_with_fallbacks_helper
    response = await response
  File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 2097, in wrapper_async
    raise e
  File "/app/.venv/lib/python3.13/site-packages/litellm/utils.py", line 1896, in wrapper_async
    result = await original_function(*args, **kwargs)
  File "/app/.venv/lib/python3.13/site-packages/litellm/images/main.py", line 1064, in aimage_edit
    raise litellm.exception_type(
        model=model, ...)
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2456, in exception_type
    raise e
  File "/app/.venv/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 588, in exception_type
    raise InternalServerError(...)

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.83.13-nightly

Twitter / LinkedIn details

No response

extent analysis

TL;DR

The issue can likely be fixed by calling .read() on the request body before accessing its content in the LiteLLM proxy.

Guidance

  • Verify that the image and mask files are being sent correctly as multipart/form-data in the request.
  • Check the LiteLLM proxy code to ensure that .read() is called on the request body before accessing its content.
  • Consider adding error handling to catch and handle httpx.RequestNotRead exceptions.
  • Review the request logging to confirm that the image and mask files are being received as expected.

Example

# Example of calling .read() on the request body
async def image_edit_api(request):
    # ...
    body = await request.read()
    # Process the request body
    # ...

Notes

The issue seems to be related to the LiteLLM proxy not calling .read() on the request body before accessing its content. This is a common issue when working with asynchronous requests. The provided log output and request details suggest that the issue is occurring in the image_edit_api function.

Recommendation

Apply a workaround by calling .read() on the request body before accessing its content. This should fix the issue and allow the LiteLLM proxy to correctly process the request.

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