All insights

Model APIs

GPT-5 Token Limit: Context Window, Output Cap, and API Troubleshooting

GPT-5’s API documentation lists a 400,000-token context window, a 272,000-token maximum input, and a 128,000-token maximum output. Learn which limit applies and how to troubleshoot oversized requests.

Illustration for Gpt 5 token limit

GPT-5 API token limits

For the GPT-5 API model ID gpt-5 (default snapshot gpt-5-2025-08-07), OpenAI lists:

  • Context window: 400,000 tokens
  • Maximum input: 272,000 tokens
  • Maximum output: 128,000 tokens

These figures describe different limits: the 400,000-token context window does not mean you can send 400,000 input tokens. Follow the model’s separate input and output caps. OpenAI also explains that reasoning tokens are not visible in the answer but count toward output usage, so a short visible answer can consume more output tokens than its text suggests. (GPT-5 model documentation · Understanding and counting tokens)

Production note: OpenAI marks GPT-5 as deprecated. Check the current model documentation before choosing it for a new integration. The GPT-5 model page lists both the Responses and Chat Completions API as supported. (GPT-5 model documentation)

Troubleshoot a request that hits a token limit

1. Confirm the model and endpoint

Check the request’s model value and whether you use Responses or Chat Completions. The figures above are for the documented GPT-5 model; do not assume they apply to another GPT-5-family model or a different provider’s implementation. (GPT-5 model documentation)

2. Count the full input

A plain-text estimate can miss tokens from message structure, tools, schemas, images, and files. For a complete Responses API input, OpenAI provides an input-token counting endpoint. Its Python SDK reference documents client.responses.input_tokens.count(...), accepts fields including model and input, and returns an input_tokens count.

from openai import OpenAI

client = OpenAI()
count = client.responses.input_tokens.count(
    model="gpt-5",
    input="Your actual request input goes here",
)
print(count.input_tokens)

Count the same input and request components you intend to send. This count covers input; it does not predict how many output or reasoning tokens the response will use. If the input is too large, remove irrelevant history, summarize older turns, split a large document into smaller sections, or narrow retrieved material, then count again. (Input-token counting API reference · Token-counting guidance)

3. Check whether the output budget was exhausted

For GPT-5 on the Responses API, max_output_tokens sets the generation cap. Keep it at or below GPT-5’s documented 128,000-token maximum output. That generation budget includes reasoning tokens, not just the visible answer. (Controlling response length · Reasoning models)

To diagnose a response that stopped early, inspect the response status and details. OpenAI documents that status: incomplete with incomplete_details.reason set to max_output_tokens can mean either that generation reached the configured max_output_tokens cap or that it reached the context-window limit. Check the request size and configured cap before choosing a fix: raise the cap only when it is the binding constraint and sufficient context capacity remains. If context capacity is the constraint—or you cannot determine which limit bound—reduce input/history or the requested output and reasoning demand rather than reflexively raising the cap. A short answer by itself does not prove the output budget was exhausted. (Reasoning models)

If the request is rejected before a response is returned, inspect the API error details rather than assuming the output budget was exhausted. The sources cited here do not establish a specific error code or signature for requesting an output cap above GPT-5’s maximum.

4. Distinguish token limits from rate limits

A request-size or output-budget issue is different from an API rate-limit or account limit. Inspect the HTTP status and error details. OpenAI says a 429 can indicate a temporary rate limit, exhausted prepaid credits, or a spending or usage limit; rate limits can apply to requests per minute or tokens per minute. Follow the remedy for the reported error rather than shrinking the prompt automatically. (Troubleshooting API rate limits and 429 errors)

Quick rule: If the complete input count exceeds 272,000, reduce or split the input. If the response is incomplete with incomplete_details.reason set to max_output_tokens, that signal can indicate either the configured output cap or the context window was reached: raise the cap only if it is binding and context capacity remains; otherwise reduce input/history or output and reasoning demand. If the API returns a 429, inspect its error details for rate or account limits.

Sources

GPT-5 Model | OpenAI API

Understanding and counting tokens

Get input token counts | OpenAI API Reference

Counting tokens | OpenAI API

Controlling the length of OpenAI model responses

Reasoning models | OpenAI API

Troubleshooting API rate limits and 429 errors

Contact us