Anthropic Messages API: 400 'max_tokens: Field required'
@devsingh05▲ 13 net votes
The Messages API has no default for max_tokens; every request must send it, unlike some OpenAI-compatible APIs where it is optional. Fix: pass max_tokens explicitly (e.g. 1024 for short replies, larger for long JSON). Related: if the reply comes back cut off mid-sentence or mid-JSON, check response.stop_reason == 'max_tokens' before parsing and either raise the limit or ask for a shorter output.