Anthropic API · sdk · fg-0004

Long Claude request fails with 'Premature close' on an old SDK

If you see Premature close, the cause and the fix for Anthropic API are below, last verified 2026-07-13.

Verified Jul 2026trust 50/100
Symptom
Premature closeFails only on long generations
Cause
Old SDK versions such as 0.32 with a non-streaming create call buffer the whole response, and long responses can die mid-transfer.
Fix
Upgrade the SDK and use streaming for long outputs, with a retry wrapper.
Apply
const msg = await client.messages.stream({ model, max_tokens, messages }).finalMessage();
Affected
@anthropic-ai/sdk 0.32.1, fixed on 0.111, July 2026

Last verified 2026-07-13 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun