Trang này chưa được dịch sang Tiếng Việt. Đang hiển thị bản gốc tiếng Anh.

Message transforms

Compressing conversations that outgrow the context window

transforms and plugins are two request fields openrouter.ai defines for automatic prompt compression and content-processing add-ons (PDF parsing, web search, and similar). We accept both fields — so that existing client code does not have to strip them out or branch on which gateway it's talking to — but we do not implement what they do.

json
{
  "model": "google/gemma-4-26b-a4b",
  "transforms": ["middle-out"],
  "messages": [ /* ... */ ]
}

Why we don't have this

Automatic middle-of-conversation truncation trades correctness for convenience: it silently drops or shortens messages you sent, on your behalf, so the request doesn't fail. That's a reasonable default for a router in front of dozens of providers with wildly different context windows. It's a worse default for a service with two catalog models where you can just check the number:

bash
curl -s "https://openrouter.myip.co.kr/api/v1/models" | jq '.data[] | {id, context_length}'
json
{ "id": "google/gemma-4-26b-a4b", "context_length": 32768 }
{ "id": "lgai/exaone-4.0-32b", "context_length": 32768 }

If you need to fit a long conversation into 32,768 tokens, you decide what to drop — we don't do it invisibly.

What actually happens with an oversized prompt

The behaviour differs depending on whether the candidate that would receive it is local or external, because only local candidates get a pre-flight context check (see Local GPU models):

CandidateBehaviour
Local GPU slotRemoved from the chain before dispatch if the estimated prompt exceeds its context window, so a cold start is never wasted on a request that would fail anyway. The chain moves to the next candidate, if any.
External providerNot pre-checked. The request is sent; the provider rejects it. Since that failure happens before any content is streamed back, we treat it like any other pre-first-byte failure: the chain moves to the next candidate, or if none remain, you get 502 provider_error with the upstream's status in metadata.provider_code.
No candidate left404 no_endpoints_found

None of these are billed — a request that fails before producing tokens costs nothing.

What you can do instead

  • Trim in your own application code. You have the full message history; you know which parts matter. A summarizing pass, a sliding window, or dropping old tool results are all things you control precisely, instead of a generic middle-out heuristic guessing on your behalf.
  • Check context length before you send. context_length from GET /models (above) tells you the ceiling for each catalog model.
  • Use models[] as a size-aware fallback. If you list several candidates, the chain already skips local candidates that can't fit the prompt — see Model fallbacks.

Compatibility note

transforms and plugins are in our list of gateway-consumed keys (see Request parameters), which means they are read and stripped before the request is forwarded upstream — they never leak into the payload sent to the serving engine. Sending them is harmless; it just isn't doing what it would do against openrouter.ai.

Cập nhật lần cuối 5 thg 9, 2026