﻿# How OpenRouter middle-out transforms reshape a prompt

Understand OpenRouter context compression as middle-of-prompt removal or truncation, including why fitting a context window does not preserve every dependency.

Author: Retrivium editorial team
Updated: 2026-11-03
Canonical URL: https://retrivium.ai/journal/learn-openrouter-middle-out/
Language: en

A long conversation can exceed a model’s available context even when its latest question is small. OpenRouter’s Message Transforms documentation describes a context-compression plugin that removes or truncates middle material. This is a fitting mechanism, not a guarantee that the model receives a faithful semantic summary of everything that was removed.

## Use the current plugin contract

The current documentation enables the feature through the plugins array with the `context-compression` identifier. An older discussion of “middle-out” may describe the basic removal idea without matching the current request syntax. Build the actual request from the current official schema. For a hypothetical archive-summary app, keep its compression configuration explicit so a later maintainer can explain why some earlier messages were not available to the model.

## Understand what middle removal changes

The plugin reduces the prompt by removing or truncating material from its middle until it fits the selected context. Keeping the beginning and end can preserve broad setup and the latest request, but an important correction may sit between them. In the archive example, a middle message could revoke an earlier assumption. Losing that correction can change the answer even though the request now satisfies the token limit.

## Keep dependent tool records coherent

A tool result depends on the call that requested it, and later conclusions may depend on that observation. A generic middle-removal strategy should not replace application-aware history management for workflows that require exact relationships. Preserve the necessary call, result and accepted decision together according to the chosen API contract. For an audit-style archive answer, a compact evidence bundle may be more appropriate than arbitrary conversation truncation.

## Decide when exact recall is required

An informal conversation recap may tolerate lost detail, while a question about a specific contractual change may not. Choose behavior according to the product’s task. If exact evidence is necessary, retrieve the relevant source or shorten unrelated context deliberately. The application can also report that the available context is insufficient. A request that fits is useful only when its remaining content can still support the intended conclusion.

## Evaluate information loss explicitly

Create a representative long conversation with an important middle correction and compare the answer with and without application-controlled evidence selection. This is a hypothetical evaluation design, not a performance claim about OpenRouter. Inspect whether the final result still cites and follows the accepted facts. The test should assess the task’s information requirements rather than merely confirming that the oversized request stopped returning a context-length error.

## Documentation and further study

- [Message Transforms - Optimize AI Model Inputs](https://openrouter.ai/docs/guides/features/message-transforms).

- [OpenRouter API Reference - Complete Documentation](https://openrouter.ai/docs/api-reference/overview).

- [Provider Routing - Smart Multi-Provider Request Management](https://openrouter.ai/docs/guides/routing/provider-selection).

Related engineering guides: [Fetching the OpenRouter model catalog before deployment](/journal/openrouter-model-catalog-api/); [Tool calling through OpenRouter: the model proposes, your app executes](/journal/openrouter-tool-calling/).
