PRODUCTION SCENARIO
A report generator calls the Messages API without streaming and sets max_tokens to 100,000 for a single long document. The SDK raises a validation error before sending, and manual HTTP attempts sometimes drop mid-way.
What is the recommended fix?
Answering here is anonymous. Nothing is saved unless you sign in.
Show answer and explanation
Answer: Stream the response and collect it with the SDK's final-message helper
The errors page warns against a large max_tokens without streaming or batches, notes that networks drop idle connections, and says the SDKs validate that a non-streaming request will not exceed a ten-minute timeout. Streaming and collecting with the final-message helper returns the same complete Message object. A longer client timeout does not stop an intermediate network dropping an idle connection. Four parallel calls each generate their own continuation, and an automatic retry regenerates the whole report at full cost.
Official Source: https://platform.claude.com/docs/en/api/errors ↗