返回目录
模型与 MCP 插件

dsh-anthropic-request-size-guard

noahchalifour/dsh-anthropic-request-size-guard

DeepSeek Harness plugin: shrink oversized Claude requests so they never fail with HTTP 413 request_too_large

Stars
0
Forks
0
Issues
0
更新
1 个月前

PROJECT TOPICS

项目标签

INSTALL REFERENCE

安装参考

未验证
dsh plugin --profile web add github:noahchalifour/dsh-anthropic-request-size-guard

该命令指向仓库当前默认分支;尚无绑定当前 commit 的完整验证结果。

PROJECT README

README

dsh-anthropic-request-size-guard

Stops this Claude error in DeepSeek Harness:

claude API error (HTTP 413): { "error": { "type": "request_too_large",
  "message": "Request exceeds the maximum size" } }

Cause. The Anthropic Messages API rejects any request body over 32 MB. DSH re-sends the whole conversation every turn, including every image in history as base64. Long agent sessions that take screenshots (Android/iOS emulators, browsers) add about 1 MB per phone-sized PNG (about 1.33 MB once encoded), so after a few dozen screenshots every request fails and the session is stuck. A real stuck session had 34 screenshots at 1280×2856, for a 38 MB request.

Fix. This host plugin wraps fetch for api.anthropic.com/v1/messages requests. A request under the budget (default 30 MB) passes through byte-identical. A request over the budget is shrunk, cheapest step first:

  1. Re-encode large images as JPEG, starting at a 1568px long edge. Anthropic downsamples to about that size anyway, so the model sees practically the same image. It steps down (1280, 1024, 768, 512) only if needed. That real 38 MB request became 6.1 MB at the first step.
  2. If that is still not enough, replace the oldest images with a short text placeholder, five at a time, until the request fits.
  3. As a last resort, truncate the largest old text blocks (never the latest message).

Every step is deterministic and cached by content hash, so the history re-sent each turn stays byte-identical and the prompt cache keeps hitting.

Install

dsh plugin --profile desktop add github:noahchalifour/dsh-anthropic-request-size-guard

Then restart DSH. Image re-encoding uses sharp, which DSH already ships.

Config

Override in the profile cordis.patch.yml:

- id: anthropic-request-size-guard
  config:
    maxBytes: 30000000        # body budget in bytes (API limit is 32 MB)
    hosts: [api.anthropic.com]
    minImageBytes: 65536      # images smaller than this are never re-encoded
    dropChunk: 5              # oldest images dropped per step when needed

Limitation

Requests routed through a subscriptions-plugin HTTP proxy use undici's own fetch and bypass the wrapper.

Test

npm test

CLASSIFICATION EVIDENCE

分类依据

项目类型插件
功能分类模型与 MCP
规则置信度高

系统优先读取 GitHub Topics,再与站内分类词典和词根规则比对。当前命中: llm、anthropic、deepseek-harness。