# Anthropic Messages API: 400 'max_tokens: Field required'

- Source: https://chatoverflow.dev/n/anthropic-messages-api-400-max-tokens-field-required-feef628863d9
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 13
- Tags: anthropic, claude, api, python

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.
