# Clavue v8.13.0 — Image Token Guard + SSE Error Classification

Released: 2026-05-19

## Highlights

### Image input: per-image token budget across every entry point

3P providers (GLM/Zhipu, Volc, OpenAI-Responses gateways) bill image base64
payloads as text tokens. A "safe" 3MB PNG can cost ~32k tokens and trigger
`prompt is too long` on the next turn even after passing the 5MB byte cap.

v8.13.0 wires a shared `applyTokenBudgetToImage` helper into every image
ingress point so the per-image cost is bounded by `CLAVUE_IMAGE_MAX_TOKENS`
(default 1500 tokens, set 0 to disable):

- Clipboard paste / drag-in
- PDF page extraction (multi-page reads, `FileReadTool`)
- Bash stdout image capture (matplotlib `dpi=300` charts etc.)
- SDK/bridge inbound `image` content blocks
- Pasted attachments path
- `AskUserQuestion` permission prompt
- `ExitPlanMode` permission prompt

The byte-budget pipeline still enforces the 5MB API hard limit. The token
budget is a second pass that only fires when an image would actually exceed
the per-image token cost.

### Responses adapter: SSE `response.failed` now carries Anthropic error type

When upstream GLM/Volc relays emit gRPC-style `error.code = "invalid_argument"`
on a streaming `response.failed` event, the SSE translator now wraps it in
`ResponsesStreamError` with the mapped Anthropic type
(`invalid_request_error`). Downstream classifiers (reactive compact,
rate-limit detection, auth retry) light up the same way they do on the
non-streaming envelope path that v8.12.x already covered.

## Configuration

| Env | Default | Effect |
|---|---|---|
| `CLAVUE_IMAGE_MAX_TOKENS` | `1500` | Per-image input token cap |
| `CLAVUE_IMAGE_MAX_TOKENS=0` | — | Disable token guard (byte-only resize) |
| `CLAVUE_IMAGE_MAX_TOKENS=<n>` | — | Custom budget (e.g. `4000` for detailed diagrams) |

## Verification

- 1510 / 1516 tests pass (6 skipped, 0 fail)
- `npm run check` full gate green: vendor → validate-repo → verify-dist →
  verify-source-build → source-purity → tests
- dist/cli.js entry smoke: `8.13.0 (Clavue)`
