Skip to content

SaveFilesAsArtifactsPlugin: Can't handle too big files (PDFs) #3751

Closed

Description

@Smponias

Describe the bug
Using SaveFilesAsArtifactsPlugin works fine until the file gets too big.
Uploading a PDF with around 5MB - ✅
Uploading a PDF with around 50MB - ❌

Error: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Request contains an invalid argument.', 'status': 'INVALID_ARGUMENT'}}

To Reproduce
Run this code

root_agent = Agent(
    name="Super Cool Agent",
    model="gemini-2.5-flash",
    description="Analyzing the uploaded PDF",
    instruction="Analyze the uploaded PDF and give the user a short summary",
)

app = App(
    name='Super_Cool_Agent',
    root_agent=root_agent,
    plugins=[SaveFilesAsArtifactsPlugin()],
)

Expected behavior
I should be able to upload all files or get a proper error message.

Desktop (please complete the following information):

  • OS: macOS
  • Python version(python -V): 3.14
  • ADK version(pip show google-adk): 1.19.0

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used(e.g. gemini-2.5-pro): gemini-2.5-flash

Activity

  1. self-assigned this
    on Dec 1, 2025
  2. added
    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc
    on Dec 2, 2025
  3. added theissue type on Dec 2, 2025
  4. added 2 commits that reference this issue on Dec 2, 2025
    64a1208
    85f7c7c
  5. AakashSuresh2003 commented on Dec 4, 2025

    @AakashSuresh2003
    Contributor

    Hi @GWeale,

    Could you please review my PR and provide any suggestions?

  6. added a commit that references this issue on Dec 5, 2025
    5ce6ed8
  7. AakashSuresh2003 commented on Dec 5, 2025

    @AakashSuresh2003
    Contributor

    Hi @GWeale,

    As suggested, I’ve implemented an approach that uses file-size routing so the plugin now transparently supports files of all sizes without imposing a strict 20MB limit.

    Summary of the Solution

    I added automatic file-size detection and routing to ensure the correct upload path is used:

    • ≤ 20MB → processed via inline_data (fast path, no upload required)
    • 20MB–2GB → automatically uploaded via the Files API
    • > 2GB → proactively rejected with a clear, user-friendly error message explaining the API limit

    Additionally, the plugin now:

    • Converts Files API URIs into file_data references automatically.
    • Provides detailed feedback including filename, actual size, API limits, and next steps.
    • Handles Files API failures gracefully with actionable messaging.
    • Prevents the previous cryptic 400 INVALID_ARGUMENT error from reaching users.
  8. surajksharma07 commented on Feb 3, 2026

    @surajksharma07
    Collaborator

    @Smponias The plugin sends file data inline to the Gemini API which has a ~20MB limit — that's why your 50MB PDF hits a 400 INVALID_ARGUMENT.

    There's no size validation in save_files_as_artifacts_plugin.py currently.

    PR #3781 adds size-based routing (≤20MB inline, 20MB–2GB via Files API) but hasn't been merged yet.

    As a workaround, you can compress or split the PDF below 20MB before uploading, or use the Files API directly to upload the large file and pass the file URI to your agent instead.

  9. added
    answered[Status] This issue has been answered by the maintainer
    on Feb 3, 2026
  10. added 3 commits that reference this issue on Feb 21, 2026
    9c41b68
    8f3ebce
    2f15b35
  11. surajksharma07 commented on Mar 26, 2026

    @surajksharma07
    Collaborator

    @DeanChensj Please have a look into it.

  12. added a commit that references this issue on Jul 31, 2026
    9827790
  13. added a commit that references this issue on Aug 11, 2026
    416da39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

answered[Status] This issue has been answered by the maintainerservices[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions