api7 / api7/aisix

Prompt compression and context-window-aware truncation

Open
#765 0 comments 0 reactions 1 assignee View on GitHub

@moonming is already working on this.

Since Jul 15, 2026.

enhancement
Dominant language
Rust
Stars
157
Forks
32
Avg merge
1h 25m
Merged PRs (30d)
145

Description

Description

Nothing compresses a prompt toward a token budget, and nothing reacts to the model context window: there is no truncation of old turns, no rolling summarisation, no message dedup, no semantic compression, and no policy accepting a target token budget or a context-limit ratio.

Requested: such a policy, with

  • configurable strategies — drop oldest turns, summarise the middle, dedupe repeated context, strip boilerplate;
  • tokenizer-accurate per-model accounting;
  • a deterministic path that costs no extra model call;
  • metrics for tokens saved and compressions applied.

Why

Token spend is the dominant cost line in production LLM use, and long agent conversations fail outright with context-length errors — a failure the gateway is uniquely placed to prevent, since it already parses and counts every message on the path.

Priority

Medium.


Prior art

Product Has it Reference
LiteLLM Yes litellm.compress(), budget-targeted (Beta)
Kong AI Gateway Yes ai-prompt-compressor (LLMLingua 2; enterprise, separate service)
OpenRouter Partial context-compression plugin, context-reactive
Bifrost Partial /v1/responses/compact — delegates to provider
Helicone Partial token limits, not compression
TrueFoundry Partial /responses/compact — delegates to provider
Portkey No none found
Cloudflare AI Gateway No none found
Envoy AI Gateway No none found

LiteLLM and Kong both ship budget-targeted compression today.

Surveyed 2026-07-15; every claim rests on a fetched docs/source page.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.