The context window is the most tokens a model can handle in one request. The window covers the system prompt, the conversation history, and the tokens the model generates.
A 200K window with a 190K prompt leaves about 10K for the reply, so max_tokens must fit that leftover space.
WINDOW = 200_000
prompt_tokens = count_tokens(messages) # measure it, do not guess
max_tokens = min(4096, WINDOW - prompt_tokens - 500) # keep a safety margin
Models are stateless and keep nothing between calls, so each request resends the whole history.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓