hotai.news
← Back to AI WikiAI Wiki / Solve a problem

An API rejects an overlong input: how do you calculate the actual context and remove irrelevant content?

For a context-related 400, read the specific error and establish whether input, output or total window is exceeded. Character counts are not token counts, and tools, history and attachments can contribute.

HotAI.news · Sources checked with CodexPublished on 2026-10-20Sources checked on 2026-10-20
Our take

Start troubleshooting here

For a context-related 400, read the specific error and establish whether input, output or total window is exceeded. Character counts are not token counts, and tools, history and attachments can contribute. Inspect actual requests and model limits before reducing or splitting content. Removing the last message alone is not a reliable repair, and maximum output is not input capacity.

01

Preserve the complete error and identify the exceeded limit

This applies to long conversations failing suddenly, tool definitions triggering errors and identical material behaving differently across models. Preserve a sanitized request structure and model identifier and inspect proxy-specific limits. HTTP 400 has other causes, so use typed errors rather than indiscriminately trimming every rejected request.

02

Count all content in the actual request

Inspect system messages, history and tool results for duplicated assembly. Use supported model-specific counting and check output budgets and attachment limits. Context size and maximum output can be distinct limits. Some services additionally constrain file size or content-block counts, which require separate diagnosis.

03

Retain essential information and reserve output capacity

Retain essential constraints and evidence, remove confirmed duplication and summarize or segment long tool outputs with a continuation mechanism. Record what history compaction omits so user requirements survive. Split long material with coverage and citation checks at each stage instead of truncating the end until an accepted request silently changes the task.

04

Check that reduced requests still complete the original task

Confirm rejection is gone and the answer still covers the original question and evidence. Test near-boundary and ordinary short inputs and inspect lost conditions or duplication after compression. Success requires both API acceptance and maintained task quality. A 200 response is intermediate; disclose any necessarily reduced scope.

This article sent no model requests or measured capacity. Counting, attachments and window policies change and need version-specific documentation. Increasing output budgets can consume more context rather than repair input limits. Longer context does not itself guarantee accurate use of every fact; verify task outcomes and important details.

Checked sources

These sources support the concepts and methods described here. Examples and test scope are labeled separately; check the version of the tools you use.

Back to AI Wiki ↗