Prompt
How do I reduce per-request LLM cost before launch?
Latest observation
To reduce per-request LLM cost before launch, focus on the biggest cost drivers first: tokens, model choice, retries, and unnecessary calls. Here’s a practical checklist.
1) Measure the cost drivers
Before optimizing, instrument:
- Input tokens / output tokens per request
- Requests per user action
- Retry rate
- Tool/function call count
- Cache hit rate
- Latency by step
If you can’t see token usage by endpoint, you’ll end up optimizing the wrong thing.
2) Cut tokens aggressively
This is usually the fastest win.
Reduce prompt size
- Remove redundant instructions
- Move static instructions into a shorter system prompt
- Avoid repeating the same context in every request
- Keep examples to 1–2 high-signal examples, not many
Send only relevant context
- Use retrieval or filtering instead of dumping full documents
- Truncate long histories
- Summarize conversation state instead of replaying full chat logs
- Pass structured fields instead of prose where possible
Shorten outputs
- Set explicit output limits
- Ask for concise responses
- Use schemas/JSON only when needed
- Avoid “explain your reasoning” unless necessary
3) Use the cheapest model that works
A common pattern:
- Use a small/cheap model for:
- classification
- routing
- extraction
- drafting
- summarization
- Reserve a larger model for:
- complex reasoning
- final high-stakes responses
- ambiguous cases
A two-stage pipeline often cuts cost a lot:
- cheap model handles 80–95% of requests
- larger model only handles edge cases
4) Reduce number of LLM calls
Each extra call multiplies cost.
Ways to do that:
- Combine steps into one prompt when possible
- Avoid “draft then critique then rewrite” loops unless necessary
- Merge classification + extraction into one call
- Batch independent work
- Don’t call the LLM for deterministic logic you can code directly
5) Add caching
Great for repeated or near-repeated requests.
Cache at multiple levels
- Exact prompt cache for identical queries
- Semantic cache for similar queries
- Retrieval cache for repeated document fetches
- Response cache for common templated answers
Even a small cache hit rate can materially reduce cost in production.
6) Constrain generation
Output cost can balloon unexpectedly.
Use:
- lower
max_tokens - stop sequences
- structured outputs
- narrow instructions
- deterministic settings when appropriate
If the task is extraction, don’t let the model write essays.
7) Minimize tool usage
Tool calls add both latency and cost indirectly.
Optimize by:
- making tools return only necessary fields
- reducing round trips
- using a single tool that can fetch multiple needed items
- avoiding tool calls for obvious answers
- precomputing data offline when possible
8) Use routing and fallbacks
Not every request deserves the same model.
Example routing:
- simple FAQ → cheap model or rules
- moderate complexity → mid-tier model
- high confidence needed → premium model
You can also:
- estimate difficulty before calling the main model
- route low-value traffic to cheaper answers
- escalate only when confidence is low
9) Design for shorter conversations
Chatty UX can become expensive fast.
Consider:
- keeping session state outside the prompt
- summarizing older turns
- limiting how much history is included
- asking users clarifying questions only when necessary
10) Benchmark before launch
Create a test set of real requests and measure:
- quality
- token usage
- cost per successful task
- failure rate
- escalation rate
Then compare:
- current prompt vs shorter prompt
- big model vs small model
- one-call vs multi-call workflow
The best cost reduction usually comes from workflow changes, not just prompt editing.
Quick pre-launch action plan
If you want the fastest impact, do these in order:
- Instrument token usage and number of calls
- Trim prompts and limit output length
- Switch easy tasks to a cheaper model
- Add caching
- Remove unnecessary multi-step LLM workflows
- Benchmark quality/cost tradeoffs on real examples
A useful rule of thumb
If you need to cut cost quickly:
- First optimize tokens
- Then optimize model selection
- Then optimize call count
- Then add caching/routing
If you want, I can help you build a pre-launch LLM cost reduction checklist or review your current prompt/workflow and point out specific savings.