API StudioSDK StudioMonitoringMCP ServerSpec AuditFeatures
PricingBlogDocs
Log inStart for free
Blog/Engineering
Engineering·October 15, 2026·3 min read

Your API response is eating the agent's context window

Design bounded responses that preserve useful facts. Filter, select and aggregate before large intermediate payloads enter an agent's context.

#ai-agents#api-design#mcp#performance
Your API response is eating the agent's context window

An agent needs the total for overdue invoices. The API returns thousands of records, including nested customer profiles and audit histories. Most of that response contributes nothing to the calculation, but the model still has to process it if the entire payload enters its context.

Return the records and fields needed for the task, with enough context to check the calculation. Response size needs its own review even when the agent has only a few tools.

Put selection near the data

If the API supports server-side filtering, use it to select the intended records before transmission. If field selection is available, request the identifiers, amounts, dates and statuses the task needs. Apply tenant authorization before returning either details or aggregates.

Where suitable, expose an aggregate operation with explicit semantics. A total should say which records and time range it includes, what currency or unit applies, and whether the result is complete. A concise number without those boundaries can be more misleading than a verbose response.

Do not silently truncate. A capped result should advertise its limit and provide the documented continuation mechanism or a clear indication that more results exist. An agent cannot infer completeness reliably from the length of an array.

Preserve evidence and meaning

Keep stable resource identifiers and a supported way to fetch details. For a summary, retain the filters and observation time needed to reproduce it. If the data is eventually consistent, explain what freshness means for that endpoint.

Avoid dropping fields solely because they look repetitive. A currency code, timezone, null value or warning can change the interpretation of a result. Make projection rules explicit and test summaries against full records using synthetic fixtures.

An agent asking for a customer display name may not need the full customer object. It still needs a reliable association between that name and the resource it is discussing. Saving tokens must not turn distinct records into ambiguous prose.

Process intermediate results outside model context

Some workflows need large raw datasets for computation but only a small result for reasoning. A controlled execution layer can join, filter or aggregate records before passing the final output to the model.

Anthropic's programmatic tool-use engineering article describes one implementation of this pattern. Its measured savings belong to that implementation and workload. The general principle is useful independently: intermediate bytes need not all become model input.

Such a layer still needs ordinary controls: scoped credentials, bounded execution, output limits and safe handling of customer data. Moving processing into code changes where work happens; it does not remove authorization or privacy obligations.

Measure at the task boundary

Compare variants with the same records, question and correctness checks. Record response bytes, model input usage when available, elapsed time, call count and task success. A smaller response that forces repeated detail requests may be slower or more expensive overall.

Include difficult cases: empty matches, multiple currencies, missing optional fields and more results than the default cap. Check whether the agent recognizes an incomplete result instead of confidently reporting a partial total.

← PreviousHow to Choose an OpenAPI SDK Generator: 10 Questions to Ask

Related articles

Can an AI agent actually integrate your API? Build an eval to find out
Engineering·2 min read

Can an AI agent actually integrate your API? Build an eval to find out

Give an agent a real task, an isolated sandbox and a result you can verify. Check the records and code the agent produces.

October 15, 2026
MCP or CLI? Run the same API workflow through both
Engineering·2 min read

MCP or CLI? Run the same API workflow through both

Compare agent interfaces with the same task, permissions and outcome checks. Token counts mean little when one path does less work.

October 15, 2026
Your streaming API returned 200. Then it failed
Engineering·2 min read

Your streaming API returned 200. Then it failed

An HTTP success status starts a stream; it does not prove the operation finished. Design explicit completion, interruption and recovery semantics.

October 15, 2026
Who built this SDK? Proving package provenance from spec to registry
Engineering·2 min read

Who built this SDK? Proving package provenance from spec to registry

Connect a published SDK to its inputs and build workflow. Understand what trusted publishing and provenance establish, and what still needs review.

October 15, 2026

A letter when something ships

New SDK languages, changes in the generator, and now and then a longer piece on keeping docs from rotting. Roughly one a month.

Join developers keeping tabs on Octri.

Octri

Upload an OpenAPI spec. Get complete docs and production-ready SDKs in 10 languages, live in minutes.

Contact support

Product

  • API Studio
  • SDK Studio
  • Monitoring
  • MCP Server
  • Pricing
  • Open Source
  • Blog
  • Changelog
  • Press Kit

From your spec

  • Spec Audit
  • TypeScript SDK
  • Python SDK
  • Go SDK
  • Java SDK
  • MCP Server

Developers

  • Documentation
  • SDK Libraries
  • MCP Server
  • Monitoring
  • CLI
  • Support

Legal

  • Terms of Service
  • Privacy Policy
  • Fair Use Policy
  • Data Processing (DPA)
  • Cookie Policy
  • Security
  • Subprocessors

© 2026 Octri, LLC. All rights reserved.

Made by devs who got tired of hand-writing SDKs.