PromptShrink

PromptShrink

How I Cut LLM Token Usage by Up to 60% in Production 我是如何将生产环境中的 LLM Token 使用量降低高达 60% 的

If you work with LLM APIs (OpenAI, Anthropic, Gemini), you know the pain: every call costs money, and a big chunk of that cost is pure waste — verbose prompts, code pasted with no filtering, repeated context the model doesn’t even need to understand the task. That’s why I built PromptShrink: a prompt pre-processor that trims the excess before it ever hits the API, without losing what actually matters for the model to understand. 如果你经常使用 LLM API(如 OpenAI、Anthropic、Gemini),你一定深有体会:每一次调用都需要付费,而其中很大一部分成本纯属浪费——冗长的提示词、未经筛选直接粘贴的代码、模型根本不需要的重复上下文。这就是我开发 PromptShrink 的原因:它是一个提示词预处理器,能在请求发送到 API 之前剔除多余内容,同时保留模型理解任务所需的关键信息。

The real problem 真正的问题

Every time you feed a code snippet or a long prompt to an LLM, you’re paying per token, not per character. Comments, whitespace, formatting meant for humans — all of that is dead weight the model doesn’t need to do its job. At scale (thousands of calls per month), that adds up to a real bill. 每次你向 LLM 输入代码片段或长提示词时,你是按 Token 付费,而不是按字符付费。注释、空格、为了人类阅读而设计的格式——这些对于模型完成任务来说都是无用的负担。当调用规模达到每月数千次时,这笔费用会变得非常可观。

What PromptShrink does PromptShrink 的功能

  • Packages entire repositories, minifying code and stripping comments, ready to paste as context into any LLM
  • Simulates real dollar savings, comparing your current spend against the optimized version
  • Visualizes everything on a dashboard — tokens saved, % reduction, active rules
  • Plugs straight into your code via a Python SDK
  • Becomes a browser extension, adding a “Shrink” button directly on ChatGPT, Claude.ai, Google AI Studio, and Poe
  • 打包整个代码库,压缩代码并去除注释,随时准备作为上下文粘贴到任何 LLM 中
  • 模拟实际节省的金额,对比你当前的支出与优化后的版本
  • 通过仪表盘可视化一切数据——节省的 Token 数、缩减百分比、生效的规则
  • 通过 Python SDK 直接集成到你的代码中
  • 作为浏览器扩展程序,直接在 ChatGPT、Claude.ai、Google AI Studio 和 Poe 上添加“压缩 (Shrink)”按钮

In practice 实际操作

bash Package an entire project into optimized context promptshrink repo --path ./src --save-to-file context.txt 将整个项目打包为优化后的上下文

Simulate monthly savings promptshrink calc --calls 100000 --tokens 800 --model gpt-4o 模拟每月节省的费用

Running calc on a scenario of [insert your real number here, e.g. “100k calls/month with gpt-4o”], the estimated savings came out to [$X per month] — just by trimming what’s unnecessary before it reaches the model. 在 [此处填入你的实际数据,例如“每月 10 万次调用,使用 gpt-4o”] 的场景下运行计算,预估节省金额达到了 [每月 $X] ——仅仅通过在数据到达模型前剔除不必要的内容即可实现。

Try it out 立即尝试

The project is open source, with a CLI, a FastAPI backend, and a Python SDK. If you’re running LLMs in production and want to stop paying for tokens that add zero value, check it out: 🔗 github.com/HeloisaPeGarcia/PromptShrink 该项目是开源的,包含 CLI、FastAPI 后端和 Python SDK。如果你正在生产环境中使用 LLM,并且不想再为毫无价值的 Token 付费,请查看:🔗 github.com/HeloisaPeGarcia/PromptShrink

Feedback and PRs are very welcome — this is my first published project like this, so every contribution helps make it better. 非常欢迎反馈和提交 PR——这是我发布的第一个此类项目,每一份贡献都能让它变得更好。