Context window
The context window limits the amount of data that a model can process in one request. For chat models, input and output share this limit.
What is a token?
Section titled “What is a token?”A model processes text in small units. These units are called tokens. A token can be part of a word, a whole word, or a punctuation mark.
The number of tokens depends on the model. The number of words or characters does not give an exact token count.
What counts towards the context?
Section titled “What counts towards the context?”The input includes your current message and the conversation history sent with it. For applications that use tools, the input also includes tool definitions and results.
The output includes the tokens generated by the model. These can include tokens for internal reasoning. You can limit the maximum number of output tokens.
The input and maximum output must fit inside the context window together. Leave additional space for a safety margin.
Example
Section titled “Example”In this example, a model has a context window of 8,000 tokens.
| Input | Maximum output | Total | Result |
|---|---|---|---|
| 6,000 tokens | 1,000 tokens | 7,000 tokens | Fits. 1,000 tokens remain available. |
| 9,000 tokens | 1,000 tokens | 10,000 tokens | Does not fit. The input alone is too large. |
These numbers only explain the calculation. See the model limits for the context windows of available models.
What happens to earlier messages?
Section titled “What happens to earlier messages?”Earlier messages only count if the application sends them again. Thus, long conversations can fill the context window.
See Troubleshooting for steps to reduce an oversized request.