Skip to content

core: request accumulates 52 images, exceeds provider max of 50 #47721

Open

Description

@prasaddpathak

Summary

Upstream request fails with [invalid_request_error] request contains 52 images, exceeding the maximum of 50 allowed per request after iterating on image assets in a single session.

Environment

  • opencode version: 1.18.21 (opencode2 v0.0.0-beta-19157)
  • OS: Darwin 25.6.0 arm64
  • Terminal: TERM=xterm-256color, TERM_PROGRAM=ghostty, COLORTERM=truecolor
  • Shell: /bin/zsh
  • Install/channel: beta
  • Active plugins: none found (no .opencode/plugin or .opencode/plugins; config has minimax provider + exa remote MCP only)

Reproduction

  1. In one session, iteratively build HTML visuals rendered via headless Chrome.
  2. Have the agent read PNG/GIF outputs after each iteration (hero-banner.png, anatomy-eta.png, decision-2am.png, plus GIF previews).
  3. After ~10-15 image reads across turns, any new request fails.
  4. Error: Error from provider (Console): Upstream request failed: [invalid_request_error] request contains 52 images, exceeding the maximum of 50 allowed per request

Expected Behavior

Old image attachments should be compacted, dropped, or blocked before hitting the provider cap — or at least warn with a way to continue text-only.

Actual Behavior

Request hard-fails at 52/50 images. Session is stuck: can't send even text-only prompts without hitting the image count.

Additional Context

  • Earlier in same session also saw: Unable to process image(s). Mouse mode is currently enabled, which limits image messages to one image per message.
  • Workflow: Substack visual iteration (1600px HTML -> Chrome screenshot -> read PNG). No manual image uploads, only agent read tool outputs.
  • Frequency: consistent once cap is hit; blocks the session.
  • Workaround tried: none yet — reporter asked agent to stop sending images. Proposed: new session / text-only mode.

Activity

  1. github-actions commented on Sep 7, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. Sugamsss commented on Oct 14, 2026

    @Sugamsss

    We ran into this on 2.0 as well and traced the exact core mechanism on current dev:

    1. boundImages() in packages/core/src/session/model-request.ts triggers only on bytes (>25 MiB). It enforces no count check, so 51 small screenshots (e.g. 50 KB each) still get sent and trigger provider 400 errors.
    2. packages/ai/src/provider-error.ts doesn’t classify image-count errors as context overflow, so automatic recovery never runs.
    3. When core does remove an image, its placeholder is a blind stub without the file path, so the model cannot re-read it.

    Proposed fix:

    • Add an image count ceiling to boundImages().
    • Keep the file path in the removal placeholder so the model has actionable recall via read.
    • Add image-count patterns to provider-error.ts so recovery kicks in.

    We have a working standalone implementation in opencode-prune-images and have this patch ready if you would like a core PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions