{"record":{"id":"e7160b100868b2a5","repo":"zeroclaw-labs/zeroclaw","slug":"fal-ai-response-exceeds-the-1-mib-size-limit","errorCode":null,"errorMessage":"fal.ai response exceeds the 1 MiB size limit","messagePattern":"fal\\.ai response exceeds the 1 MiB size limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-tools/src/image_gen.rs","lineNumber":169,"sourceCode":"    model: &str,\n    prompt: &str,\n) -> String {\n    format!(\n        \"Image generated successfully.\\n\\\n         File: {path_display}\\n\\\n         Size: {size_kb} KB\\n\\\n         Model: {model}\\n\\\n         Prompt: {prompt}\\n\\\n         [IMAGE:{path_display}]\",\n    )\n}\n\nasync fn read_fal_success_body(response: reqwest::Response) -> anyhow::Result<Vec<u8>> {\n    let body = response_body::read_bounded(response, Some(FAL_RESPONSE_LIMIT_BYTES))\n        .await\n        .context(\"Failed to read fal.ai response\")?;\n    if body.overflowed {\n        anyhow::bail!(\"fal.ai response exceeds the 1 MiB size limit\");\n    }\n    Ok(body.bytes)\n}\n\nasync fn read_fal_error_text(response: reqwest::Response) -> anyhow::Result<String> {\n    response_body::read_text(response, Some(FAL_ERROR_LIMIT_BYTES))\n        .await\n        .map(|(text, _)| text)\n}\n\nasync fn read_generated_image_body(response: reqwest::Response) -> anyhow::Result<Vec<u8>> {\n    let body = response_body::read_bounded(response, Some(GENERATED_IMAGE_LIMIT_BYTES))\n        .await\n        .context(\"Failed to read generated image bytes\")?;\n    if body.overflowed {\n        anyhow::bail!(\n            \"Generated image exceeds the {} MiB size limit\",\n            GENERATED_IMAGE_LIMIT_BYTES / (1024 * 1024)","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-tools/src/image_gen.rs#L151-L187","documentation":"After a successful fal.ai generation, read_fal_success_body reads the JSON response through response_body::read_bounded with FAL_RESPONSE_LIMIT_BYTES = 1 MiB. If the provider's success payload crosses that cap, the bounded reader sets the overflowed flag and this error fires, so the tool fails instead of buffering an unbounded body. The usual cause is a fal app configured to return images inline (base64 data URIs) instead of URLs, which inflates the JSON far past 1 MiB.","triggerScenarios":"Generating with a fal.ai model/app whose output mode embeds base64 image data or data: URIs directly in the response JSON, or whose metadata payloads are enormous; a 1 MiB+ JSON body on a 2xx response triggers the bail. The bounded-reader test fal_success_body_rejects_oversized_chunked_response pins this behavior.","commonSituations":"Switching a fal app to inline/base64 output (e.g. data URI mode or b64_json-style fields), requesting very high prompt/metadata detail that bloats the JSON, or pointing the tool at a custom fal endpoint that returns bulky payloads.","solutions":["Configure the fal.ai model/app to return a hosted URL (fal media storage) rather than inline base64 data, and keep response_format URL-based.","Verify you are calling the intended endpoint with the right FAL key so unexpected bulky success bodies (or misrouted responses) are not being read.","If a legitimate workflow truly needs >1 MiB JSON, the limit is the internal constant FAL_RESPONSE_LIMIT_BYTES in crates/zeroclaw-tools/src/image_gen.rs; changing it is a code-level decision, not a runtime config."],"exampleFix":"# before (fal app output mode: inline/data URI)\n{\"images\":[{\"data\":\"iVBORw0KGgo...\"}]}      # >1 MiB JSON -> rejected\n\n# after (fal app output mode: hosted URL)\n{\"images\":[{\"url\":\"https://v3.fal.media/files/...\"}]}  # small JSON -> accepted","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match generate(request).await {\n    Err(e) if e.to_string().contains(\"1 MiB size limit\") => {\n        // fal app is returning inline base64: switch the app/output mode to hosted URLs and retry once\n        regenerate_with_url_output_mode(request).await\n    }\n    other => other,\n}","preventionTips":["Keep fal.ai apps in URL-output mode (fal media storage); avoid inline/base64 data-URI output modes.","Watch model/app version bumps for changed response shapes that inline image data.","Monitor response sizes near the 1 MiB cap so mode regressions are caught before failures."],"tags":["size-limit","fal-ai","image-gen","response-body","rust"],"backgroundTag":"response-size-limit-exceeded","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}