Skip to content
Rapid Router
← API reference

Message transforms

Part of the Rapid Router API reference. One OpenAI-compatible endpoint, https://rapidrouter.ai/api/v1, in front of every model in the catalog.

12Message transforms

A conversation that has outgrown the model's context normally just fails. Add transforms: ["middle-out"] to the request body and the gateway compresses it instead: messages are dropped from the middle, keeping the system message, the start and the end, which is where models actually look. It also applies whenever a conversation has more than 800 messages, since some providers cap message count outright.

{
  "model": "google/gemini-3.6-flash",
  "transforms": ["middle-out"],
  "messages": [ /* a conversation too long for the model */ ]
}

// response, only when something was actually trimmed:
// "transforms_applied": ["middle-out"]

A request that already fits is forwarded untouched and the response carries no transforms_applied field, so its presence is meaningful. Token counts are estimated conservatively, and the field itself is stripped before forwarding, so no upstream ever sees it.