{"record":{"id":"4a8f1a05a4b36a18","repo":"ComposioHQ/composio","slug":"response-size-exceeds-maximum-allowed-size-max-s","errorCode":null,"errorMessage":"Response size exceeds maximum allowed size ({max_size} bytes)","messagePattern":"Response size exceeds maximum allowed size \\((.+?) bytes\\)","errorType":"exception","errorClass":"ResponseTooLargeError","httpStatus":null,"severity":"error","filePath":"python/composio/core/models/_files.py","lineNumber":460,"sourceCode":"    if content_length is not None and content_length > max_size:\n        response.close()\n        raise ResponseTooLargeError(\n            f\"File size ({content_length} bytes) exceeds maximum allowed \"\n            f\"size ({max_size} bytes)\"\n        )\n\n    # Stream response with size tracking\n    chunks: t.List[bytes] = []\n    total_bytes = 0\n    chunk_size = 8192  # 8 KB chunks\n\n    try:\n        for chunk in response.iter_content(chunk_size=chunk_size):\n            if chunk:\n                total_bytes += len(chunk)\n                if total_bytes > max_size:\n                    response.close()\n                    raise ResponseTooLargeError(\n                        f\"Response size exceeds maximum allowed size ({max_size} bytes)\"\n                    )\n                chunks.append(chunk)\n    finally:\n        response.close()\n\n    content = b\"\".join(chunks)\n\n    # Extract mimetype\n    mimetype = response.headers.get(\"content-type\", \"application/octet-stream\")\n    # Handle mimetypes with charset or other parameters (e.g., \"text/html; charset=utf-8\")\n    mimetype = mimetype.split(\";\")[0].strip()\n\n    # Extract filename from URL (decode percent-encoded characters)\n    parsed_url = urlparse(url)\n    pathname = unquote(parsed_url.path)\n    filename = os.path.basename(pathname) if pathname else \"\"\n","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/ComposioHQ/composio/blob/64b1b85502b1beeb2379e6c9e8bf1104504fa637/python/composio/core/models/_files.py#L442-L478","documentation":"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.","triggerScenarios":"FileModel.from_url where the actual streamed body exceeds max_size even though Content-Length was missing, zero (chunked encoding), or understated.","commonSituations":"Chunked transfer-encoding endpoints with no Content-Length; malicious/broken servers understating size; compressed encodings that expand.","solutions":["Compress or split the file so it stays under max_size.","Use a smaller/downsampled remote artifact.","Check the true size with curl -sL url | wc -c to confirm the body size.","Where the API allows, pass a larger max_size."],"exampleFix":"# before\nfile = FileModel.from_url(client, chunked_endpoint_url)  # actual body > limit\n# after: pre-check actual size, then only attach if within budget\nimport requests\nsize = int(requests.head(url, allow_redirects=True).headers.get('Content-Length', 0))\nif size < MAX:\n    file = FileModel.from_url(client, url)","handlingStrategy":"try-catch","validationCode":"import requests\n\ndef true_size(url: str) -> int:\n    r = requests.head(url, timeout=10, allow_redirects=True)\n    cl = r.headers.get('Content-Length')\n    return int(cl) if cl else len(requests.get(url, stream=True).content)","typeGuard":null,"tryCatchPattern":"from composio.core.models._files import ResponseTooLargeError\n\ntry:\n    model = FileModel.from_url(client, url)\nexcept ResponseTooLargeError as e:\n    raise ValueError(f'artifact too large: {e}') from e","preventionTips":["Don't trust missing Content-Length; measure chunked endpoints before attaching.","Keep artifacts small; split large exports.","Handle ResponseTooLargeError distinctly from network errors."],"tags":["python","size-limit","streaming","download"],"backgroundTag":"response-too-large","analyzedSha":"64b1b85502b1beeb2379e6c9e8bf1104504fa637","analyzedAt":"2026-08-28T15:39:33.623Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}