Generation Economy
ASecurityUse when writing, reviewing or debugging code that calls an LLM and controls how much it generates or how often it calls (sample loops, per-question calls over one document, max_tokens and thinking or effort settings, timeouts, retries, fallbacks to another model, response caching and change checks, bulk or nightly jobs, model choice for small calls, default model ids, file edits, JSON parsing, finish reasons), for Anthropic, OpenAI, Gemini, OpenRouter, DeepInfra or a self-hosted vLLM or SGLa...
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added November 27, 2026
Works with
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add Podwarden/leanprompt --skill generation-economy --agent claude-codeAre you the author of Generation Economy?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/podwarden-generation-economy)---
name: generation-economy
description: Use when writing, reviewing or debugging code that calls an LLM and controls how much it generates or how often it calls (sample loops, per-question calls over one document, max_tokens and thinking or effort settings, timeouts, retries, fallbacks to another model, response caching and change checks, bulk or nightly jobs, model choice for small calls, default model ids, file edits, JSON parsing, finish reasons), for Anthropic, OpenAI, Gemini, OpenRouter, DeepInfra or a self-hosted vLLM or SGLang server, or when usage shows truncated answers (finish_reason length, stop_reason max_tokens), retries, repeated identical calls or parse failures. Stops paying to generate, or to prefill again, what one call could have produced.
license: CC-BY-4.0
---
# generation-economy
Stops paying to generate, or to prefill again, what one call could have produced. Seventeen rules, `LP-GE-01` to `LP-GE-17`, each in its own file under `rules/`, each with a way to detect it in code, the smallest fix, what the fix must not break, and how to verify it.
Six of them are correctness rules (`saves: none`): LP-GE-11 (meter every billed token), LP-GE-12 (read the finish reason before using an answer), LP-GE-13 (default to a model the provider still serves), LP-GE-15 (give each timeout one meaning), LP-GE-16 (fall back only on errors another model can fix) and LP-GE-17 (send the output cap the owner set). They waste no tokens of their own, so they have no token share; the audit records a match as a note that names the rule and its severity. Each says which waste rule takes the token side when there is one (a cut-off answer resent unchanged is also LP-GE-05; a timeout that cuts off generation is also LP-GE-04). LP-GE-14 (both sides of a cache or change key built the same way) is a waste rule: a key that never hits repeats every call.
The `prefill-cache` skill makes each prompt cheaper to read. This skill is about the calls themselves: how many there are, how much each one generates, and how many of them are thrown away (repeated, retried after a truncation or a timeout, or discarded after a parse failure).
## When to use
- You are writing or changing code that decides how many calls to make (sampling, one call per question, loops over a dataset), what each may generate (output limits, thinking or effort), or what happens when a call fails or is slow (timeouts, retries, parsing).
- Usage shows truncated answers, retries, identical repeated calls, parse failures, or output tokens far above what the answers need.
- The `llm-call-audit` skill sends you here for an `LP-GE-*` finding.
## Priority-aware advice
Read `priority` from `leanprompt.yaml` (`cost`, `speed`, `quality`, or weights). Without it, ask, or treat the priorities as equal. Rank findings for the priority, but never drop a finding that wastes tokens without buying anything (LP-GE-04, LP-GE-05, LP-GE-10 remove pure waste under every priority).
- **Cost first:** the batch API for anything that can wait (LP-GE-07), `n` samples instead of repeats (LP-GE-01), exact-response caching (LP-GE-06), batched questions (LP-GE-02), smaller models for small calls (LP-GE-08), cheaper service tiers where the provider offers them, and aggressive prefix caching (the `prefill-cache` skill).
- **Speed first:** streaming and idle timeouts (LP-GE-04), output and thinking budgets that fit the task, with thinking off or low effort where the answer check allows (LP-GE-03), smaller models for small steps (LP-GE-08), predicted outputs or changes-only edits (LP-GE-09).
- **Quality first:** keep thinking on, with budgets that never truncate a correct answer (LP-GE-03); larger models for hard steps; batch, route or shorten only where the answer check passes (LP-GE-02, LP-GE-08). Caching applies under every priority, because it never changes answers (LP-GE-06 for identical deterministic requests, and the `prefill-cache` skill).
Any change that can alter answers (fewer separate calls, a smaller model, less thinking, shorter outputs, a schema in place of prose) ships with an answer check: a fixed set of synthetic inputs, outputs compared before and after, pass/fail. Caching-only changes are exempt.
## Workflow
1. **Know the target and priority.** Read `leanprompt.yaml` if the project has one (`target`, `priority`). Otherwise infer the provider and model from the SDK, `base_url` and model names, and ask if it is unclear. Open that provider's table from the list below; each has a "Generation features" section.
2. **Find the calls.** List every LLM call and, for each, what wraps it: loops and gathers, retry decorators and SDK retry settings, timeouts, parsing, caches, scheduling (interactive, background, nightly), and the model and budget settings.
3. **Check each rule,** in the order of the index below. Each rule's "Detect in code" gives `rg` patterns and code shapes for Python, TS/JS and Go. Open a rule file when its pattern matches.
4. **Propose the fix.** Give the rule id, file and line, and the smallest change from the rule's "Fix", with its "Don't break meaning" check. When you are reviewing existing code, propose and ask before editing. When you are writing the call now, apply the rules directly.
5. **Verify.** Use the rule's "Verify": (a) the provider's usage fields (output tokens, `finish_reason` or `stop_reason`, number of calls), and (b) the leanprompt usage record (`finish: "length"`, `flags.retry_of`, `flags.parse_failed`, repeated ids with equal `params`). The `measure-loop` skill turns these into a before/after run.
## Provider facts, in brief
What each provider supports, with prices, limits and windows, lives only in the dated tables; read it there, not from memory.
- **Anthropic.** No sample count. `max_tokens` includes thinking; truncation is `stop_reason: "max_tokens"`. Message Batches, with prompt caching on a best-effort basis. Structured outputs and strict tools. Streaming advised for long requests; the SDK retries by default. Service tiers are legacy. No predicted outputs. [providers/anthropic.md](../leanprompt/facts/providers/anthropic.md), [models/anthropic-thinking.md](../leanprompt/facts/models/anthropic-thinking.md)
- **OpenAI.** `n` on Chat Completions (newer models reject it; the Responses API has none). Output limits include reasoning; truncation is `finish_reason: "length"` or an `incomplete` response. Batch API and a `flex` tier at batch rates where still offered. Predicted outputs on some Chat Completions models. Structured outputs. The SDK retries timed-out requests by default. [providers/openai.md](../leanprompt/facts/providers/openai.md), [models/openai-reasoning.md](../leanprompt/facts/models/openai-reasoning.md)
- **Gemini.** `candidateCount`; `thinkingBudget` and `thinkingLevel`; truncation is `MAX_TOKENS`. Batch API with context caching. Structured output with values to validate in the app. [providers/gemini.md](../leanprompt/facts/providers/gemini.md)
- **OpenRouter.** A router: features depend on the upstream provider. No `n` listed. Batch endpoint for models with a batch variant. Aborting a stream stops billing only on the providers it lists. [providers/openrouter.md](../leanprompt/facts/providers/openrouter.md)
- **DeepInfra.** `n` with a small maximum; `service_tier` including `flex`; a batch API with a smaller discount; structured output. [providers/deepinfra.md](../leanprompt/facts/providers/deepinfra.md)
- **DeepSeek, Groq, xAI, Together.** OpenAI-compatible hosts with their own cache rules, usage fields, reasoning defaults, error codes and model retirements: [providers/deepseek.md](../leanprompt/facts/providers/deepseek.md), [providers/groq.md](../leanprompt/facts/providers/groq.md), [providers/xai.md](../leanprompt/facts/providers/xai.md), [providers/together.md](../leanprompt/facts/providers/together.md). On xAI the output limit covers visible output only; on most others it includes reasoning.
- **SDKs.** The Claude Agent SDK, the Codex SDK and the Vercel AI SDK: finish reasons, default retries and timeouts, usage fields: [runtimes/llm-sdks.md](../leanprompt/facts/runtimes/llm-sdks.md). LangChain.js and langchaingo defaults: [runtimes/langchain.md](../leanprompt/facts/runtimes/langchain.md). Ollama: [providers/ollama.md](../leanprompt/facts/providers/ollama.md).
- **Model retirements.** Shutdown dates and replacements from the OpenAI, Anthropic and Gemini pages: [models/retirements.md](../leanprompt/facts/models/retirements.md). Tokens per character by language, measured on a sample: [models/tokens-per-character.md](../leanprompt/facts/models/tokens-per-character.md).
- **vLLM and SGLang (self-hosted).** `n`, structured output by constrained decoding; vLLM has a batch endpoint and n-gram speculative decoding set on the server. Savings are throughput and GPU time, not price. [providers/vllm.md](../leanprompt/facts/providers/vllm.md), [providers/sglang.md](../leanprompt/facts/providers/sglang.md), [models/qwen.md](../leanprompt/facts/models/qwen.md)
Evidence rows (E1 to E12) are in [docs/evidence.md](../leanprompt/facts/docs/evidence.md). A rule whose only source is provider documentation says "documented, not yet measured here".
## Frontier generation economy
On hosted frontier models, generation is priced per token and the levers are mostly request options. Choose them per the project's priority:
- **Batch APIs** for non-interactive work: OpenAI, Anthropic, Gemini, OpenRouter and DeepInfra bill batched requests at a discount, with a completion window instead of an immediate answer (LP-GE-07). The discount and window for each are in [providers/openai.md](../leanprompt/facts/providers/openai.md), [providers/anthropic.md](../leanprompt/facts/providers/anthropic.md), [providers/gemini.md](../leanprompt/facts/providers/gemini.md), [providers/openrouter.md](../leanprompt/facts/providers/openrouter.md) and [providers/deepinfra.md](../leanprompt/facts/providers/deepinfra.md).
- **Cheaper service tiers** where offered: OpenAI `flex` at batch rates on models that still have it, and DeepInfra `flex`. Anthropic's tiers are legacy and offer no cheaper interactive tier; Gemini reports a tier in the response, and how to request one is not in its table yet.
- **Reasoning effort and thinking budgets**: the largest lever on output tokens for reasoning models. Set them per kind of task, hold them fixed per session, and check answers when lowering them (LP-GE-03; [models/openai-reasoning.md](../leanprompt/facts/models/openai-reasoning.md), [models/anthropic-thinking.md](../leanprompt/facts/models/anthropic-thinking.md)).
- **Predicted outputs** for edits that repeat most of a file, where the provider supports them (OpenAI Chat Completions on some models); elsewhere ask for the changes only (LP-GE-09).
Prices change: the tables record what each provider documents and when it was checked, and the report shows money separately from the score, with the price card's date.
## Rules
| Id | Rule | Severity | Evidence |
|---|---|---|---|
| [LP-GE-01](rules/LP-GE-01.md) | n samples in one request | medium | E12, provider docs |
| [LP-GE-02](rules/LP-GE-02.md) | Batch independent questions about one context | medium | provider docs |
| [LP-GE-03](rules/LP-GE-03.md) | Output and thinking budgets that fit the task | high | E11, provider docs |
| [LP-GE-04](rules/LP-GE-04.md) | Stream long outputs; timeouts that match generation time | high | provider docs |
| [LP-GE-05](rules/LP-GE-05.md) | Retry only retryable errors; never retry a truncation unchanged | high | provider docs |
| [LP-GE-06](rules/LP-GE-06.md) | Cache exact responses for deterministic requests | medium | provider docs |
| [LP-GE-07](rules/LP-GE-07.md) | Batch API for work that can wait | medium | provider docs |
| [LP-GE-08](rules/LP-GE-08.md) | Route trivially small calls to a small model | medium | provider docs |
| [LP-GE-09](rules/LP-GE-09.md) | Predicted outputs for mostly unchanged text | low | provider docs |
| [LP-GE-10](rules/LP-GE-10.md) | Structured output instead of parse-and-re-ask | high | provider docs |
| [LP-GE-11](rules/LP-GE-11.md) | Meter every billed token, cached and unfinished ones too | medium (a note, not scored) | provider docs |
| [LP-GE-12](rules/LP-GE-12.md) | Read the finish reason before using an answer | high (a note, not scored) | provider docs |
| [LP-GE-13](rules/LP-GE-13.md) | Default to a model the provider still serves | high (a note, not scored) | provider docs, [models/retirements.md](../leanprompt/facts/models/retirements.md) |
| [LP-GE-14](rules/LP-GE-14.md) | Build both sides of a cache or change key the same way | high | provider docs |
| [LP-GE-15](rules/LP-GE-15.md) | Give each timeout one meaning, and set one | medium (a note, not scored) | provider docs |
| [LP-GE-16](rules/LP-GE-16.md) | Fall back to another model only on errors it can fix | medium (a note, not scored) | provider docs |
| [LP-GE-17](rules/LP-GE-17.md) | Send the output cap the owner set, on every path | medium (a note, not scored) | provider docs |
## Reading the usage record
The score's generation waste is output tokens spent on calls that were repeated identically, retried after a truncation, or discarded after a parse failure, over all output tokens. In `.leanprompt/usage.jsonl` those are:
- **Repeated identically:** two records with equal exact `ids.nodes` for the last message and an equal `params` hash (LP-GE-01, LP-GE-06).
- **Retried after a truncation:** a record with `finish: "length"`, and a later record whose `flags.retry_of` points at it (LP-GE-03, LP-GE-05).
- **Discarded after a parse failure:** a record with `flags.parse_failed` (LP-GE-10).
Batch discounts (LP-GE-07) and model choice (LP-GE-08) change money, not tokens, so they do not move the score; the report shows them separately.
## What this skill does not do
It does not make prompts cache better (that is `prefill-cache`), it does not cut dead weight from the prompt (that is `prompt-diet`), it does not tune engine settings or replica routing on a self-hosted server (that is `lmwarden`), and it does not promise a saving for an app it has not measured.
<!-- leanprompt:generated v0.1.0-dev.17: written by npx leanprompt install; npx leanprompt update replaces local edits -->
Files in this skill
- SKILL.md
- rules/LP-GE-01.md
- rules/LP-GE-02.md
- rules/LP-GE-03.md
- rules/LP-GE-04.md
- rules/LP-GE-05.md
- rules/LP-GE-06.md
- rules/LP-GE-07.md
- rules/LP-GE-08.md
- rules/LP-GE-09.md
- rules/LP-GE-10.md
- rules/LP-GE-11.md
- rules/LP-GE-12.md
- rules/LP-GE-13.md
- rules/LP-GE-14.md
- rules/LP-GE-15.md
- rules/LP-GE-16.md
- rules/LP-GE-17.md
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.