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 non-streaming requests are not expected to exceed a 10-minute timeout. Streaming with the final-message helper returns the same complete Message object.
Official Source: https://platform.claude.com/docs/en/api/errors ↗