{"record":{"id":"9a1ec7bcf9097cce","repo":"langchain-ai/deepagents","slug":"media-file-is-too-large-size-bytes-exceeds-max","errorCode":null,"errorMessage":"media file is too large: {size} bytes exceeds {max_bytes}","messagePattern":"media file is too large: (.+?) bytes exceeds (.+?)","errorType":"exception","errorClass":"ChannelMediaError","httpStatus":null,"severity":"error","filePath":"libs/talon/deepagents_talon/channels/base.py","lineNumber":324,"sourceCode":"        else:\n            metadata.pop(\"voice_path\", None)\n    return replace(message, metadata=metadata)\n\n\ndef validate_media_size(path: Path, *, max_bytes: int) -> None:\n    \"\"\"Validate a local media file against the configured global cap.\n\n    Args:\n        path: Local media file to inspect.\n        max_bytes: Maximum allowed media file size.\n\n    Raises:\n        ChannelMediaError: If the file exceeds `max_bytes`.\n    \"\"\"\n    size = path.stat().st_size\n    if size > max_bytes:\n        msg = f\"media file is too large: {size} bytes exceeds {max_bytes}\"\n        raise ChannelMediaError(msg)\n\n\ndef max_media_bytes_from_env(env: Mapping[str, str]) -> int:\n    \"\"\"Return the configured global media cap.\n\n    Args:\n        env: Environment variable mapping.\n\n    Returns:\n        Maximum media bytes allowed for channel media.\n\n    Raises:\n        ValueError: If the configured value is not a positive integer.\n    \"\"\"\n    value = env.get(MAX_MEDIA_BYTES_ENV)\n    if value is None:\n        return DEFAULT_MAX_MEDIA_BYTES\n    msg = f\"{MAX_MEDIA_BYTES_ENV} must be a positive integer byte count\"","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/talon/deepagents_talon/channels/base.py#L306-L342","documentation":"`validate_media_size` stats the media file and raises `ChannelMediaError` if its size exceeds the provided `max_bytes` cap. This enforces per-file size limits before attempting to upload media to a channel provider.","triggerScenarios":"Calling `validate_media_size` (via `validate_media`/`send_media` or inbound `_enforce_inbound_media_cap`) with a file whose `st_size` is greater than `max_bytes` — e.g. a video larger than the provider/channel limit.","commonSituations":"Sending long screen recordings or large PDFs over WhatsApp/Telegram which cap uploads; inbound media from a user exceeding the global `DEEPAGENTS_TALON_MAX_MEDIA_BYTES` cap; default 1 GB cap exceeded.","solutions":["Compress or re-encode the media (e.g. transcode video, downscale images) under the cap.","Raise the cap via `DEEPAGENTS_TALON_MAX_MEDIA_BYTES` or the per-call `max_bytes` argument if your provider allows it.","Catch `ChannelMediaError` and notify the sender the attachment is too large, optionally splitting the content."],"exampleFix":"# before\nvalidate_media(media, max_bytes=50 * 1024 * 1024)  # 50MB\n\n# after\nvalidate_media(compress_if_needed(media, limit=50 * 1024 * 1024), max_bytes=50 * 1024 * 1024)","handlingStrategy":"validation","validationCode":"path = Path(media.path)\nsize = path.stat().st_size\nif size > max_bytes:\n    raise ValueError(f'{path} is {size} bytes; cap is {max_bytes}')","typeGuard":null,"tryCatchPattern":"try:\n    await channel.send_media(media)\nexcept ChannelMediaError as exc:\n    if 'too large' in str(exc):\n        await channel.send_text('That attachment exceeds the size limit; try compressing it.')\n    else:\n        raise","preventionTips":["Check `stat().st_size` before send and compress when near the limit.","Set `DEEPAGENTS_TALON_MAX_MEDIA_BYTES` to the smallest limit your providers actually allow.","Stream or chunk very large outputs instead of attaching them."],"tags":["media","size-limit","validation"],"backgroundTag":"file-too-large","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}