ComposioHQ/composio · error · ResponseTooLargeError

Response size exceeds maximum allowed size ({max_size} bytes

Error message

Response size exceeds maximum allowed size ({max_size} bytes)

What it means

The authoritative size guard while streaming the body: as chunks are consumed, cumulative bytes are counted, and exceeding max_size raises ResponseTooLargeError immediately. This catches servers that lie about (or omit) Content-Length.

Source

Thrown at python/composio/core/models/_files.py:460

    if content_length is not None and content_length > max_size:
        response.close()
        raise ResponseTooLargeError(
            f"File size ({content_length} bytes) exceeds maximum allowed "
            f"size ({max_size} bytes)"
        )

    # Stream response with size tracking
    chunks: t.List[bytes] = []
    total_bytes = 0
    chunk_size = 8192  # 8 KB chunks

    try:
        for chunk in response.iter_content(chunk_size=chunk_size):
            if chunk:
                total_bytes += len(chunk)
                if total_bytes > max_size:
                    response.close()
                    raise ResponseTooLargeError(
                        f"Response size exceeds maximum allowed size ({max_size} bytes)"
                    )
                chunks.append(chunk)
    finally:
        response.close()

    content = b"".join(chunks)

    # Extract mimetype
    mimetype = response.headers.get("content-type", "application/octet-stream")
    # Handle mimetypes with charset or other parameters (e.g., "text/html; charset=utf-8")
    mimetype = mimetype.split(";")[0].strip()

    # Extract filename from URL (decode percent-encoded characters)
    parsed_url = urlparse(url)
    pathname = unquote(parsed_url.path)
    filename = os.path.basename(pathname) if pathname else ""

View on GitHub (pinned to 64b1b85502)

Solutions

  1. Compress or split the file so it stays under max_size.
  2. Use a smaller/downsampled remote artifact.
  3. Check the true size with curl -sL url | wc -c to confirm the body size.
  4. Where the API allows, pass a larger max_size.

Example fix

# before
file = FileModel.from_url(client, chunked_endpoint_url)  # actual body > limit
# after: pre-check actual size, then only attach if within budget
import requests
size = int(requests.head(url, allow_redirects=True).headers.get('Content-Length', 0))
if size < MAX:
    file = FileModel.from_url(client, url)
Defensive patterns

Strategy: try-catch

Validate before calling

import requests

def true_size(url: str) -> int:
    r = requests.head(url, timeout=10, allow_redirects=True)
    cl = r.headers.get('Content-Length')
    return int(cl) if cl else len(requests.get(url, stream=True).content)

Try / catch

from composio.core.models._files import ResponseTooLargeError

try:
    model = FileModel.from_url(client, url)
except ResponseTooLargeError as e:
    raise ValueError(f'artifact too large: {e}') from e

Prevention

When it happens

Trigger: FileModel.from_url where the actual streamed body exceeds max_size even though Content-Length was missing, zero (chunked encoding), or understated.

Common situations: Chunked transfer-encoding endpoints with no Content-Length; malicious/broken servers understating size; compressed encodings that expand.

Related errors


AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28). Data as JSON: /api/errors/4a8f1a05a4b36a18. Report an issue: GitHub.