Skip to content

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.

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.

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.

In this example, a model has a context window of 8,000 tokens.

InputMaximum outputTotalResult
6,000 tokens1,000 tokens7,000 tokensFits. 1,000 tokens remain available.
9,000 tokens1,000 tokens10,000 tokensDoes 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.

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.