matrixx0070/sudo-skills/ai-cost-latency
Claude Code and agent skill by matrixx0070/sudo-skills
- community
Checking that the SKILL.md file is still in the repository.
Optimize an LLM app for cost and latency via model routing, caching, batching, and token budgets without losing quality.
Install
npx vskill@latest install matrixx0070/sudo-skills/ai-cost-latencySKILL.md
The same SKILL.md was published earlier as matrixx0070/sudo-skills/ai-cost-latency.
When to use
Use this when an LLM feature works but is too slow or too expensive at real volume, and you need to cut cost/latency while holding quality on a measured eval set.
Not for: a feature that is not yet correct (fix quality first, see ai-eval-harness), or picking whether to fine-tune (see ai-fine-tune-plan).
Method
- Measure before cutting: log per-request input tokens, output tokens, cost, and p50/p95 latency. Optimize the biggest driver, not the loudest complaint.
- Trim tokens: shorten the prompt, cap
max_tokens, drop dead few-shot examples, and compress retrieved context to the top few passages. - Cache aggressively. Decision point: stable prefix (system prompt, tools, long context) → prompt caching; identical repeated requests → exact-response cache; near-duplicate queries → semantic cache with a similarity threshold.
- Route by difficulty: send easy cases to a small/fast model, hard cases to the large one, using a cheap classifier or a confidence check. Decision point: if the router misroutes hard cases, raise the escalation threshold.
- Batch and parallelize: group offline work into batch API calls; fan out independent sub-tasks concurrently to cut wall-clock latency.
- Stream tokens to the user to cut PERCEIVED latency even when total time is unchanged.
- Re-run the eval set after each change. A cheaper pipeline that drops quality below the gate is not a win.
Example
Chat feature: $0.011/req, p95 2.9s. Profiling shows a 1,800-token static system prompt resent every call and all traffic on the large model.
Result: $0.004/req, p95 1.4s, eval pass-rate unchanged (91% → 90%, within gate). Routing verified: 0 hard cases misrouted on the holdout.
Pitfalls
- Optimizing before measuring. Guessing the bottleneck. Profile tokens and latency first.
- Caching volatile output. Serving a stale answer for a time-sensitive or personalized query. Scope caches by what is actually stable.
- Router quality blindness. Cheaper model silently tanks hard cases. Re-run the eval after routing, every time.
- Chasing total when perceived matters. Ignoring streaming. For interactive UIs, time-to-first-token often beats total time.
Output format
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingdocs/skills/ai-cost-latency/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/matrixx0070/sudo-skills/ai-cost-latency)