The page leanprompt report --html writes for yihong0618/bilingual_book_maker at commit 5e40cbc, audited 2026-11-26. Every figure on this page is an estimate from reading the code, not a measurement of the app in use. Corrections and takedown: email info@podwarden.com or open an issue. Back to the audit of yihong0618/bilingual_book_maker

leanprompt audit of yihong0618/bilingual_book_maker

Nothing confirmed yet, and 1 open question to settle

The largest, at book_maker/translator/chatgptapi_translator.py:341, about 35k tokens per 1,000 calls if it holds: the 300-second timeout with one SDK retry (line 341) is wrapped by a 3-attempt tenacity retry on the batch path (line 1807) and, after the batch gives up, by a per-paragraph sweep in which each paragraph has its own 3-attempt retry (line 1513).

Plus 1 other problem the audit found, listed after the findings. Not scored.

What this costs you

Every figure here is an estimate from the code, not a measurement. Findings can overlap (one failed call can show up in two), so the sum may count some tokens twice. Money is not part of the score. The table lists this app's findings first, largest first, then its open questions, then the questions for the server's administrator, then the findings the project already knows about, which are not in the totals.

FindingWhereTokens per 1,000 calls
LP-GE-04 (open question)book_maker/translator/chatgptapi_translator.py:34117k prompt, 18k output

To see this in money, add to leanprompt.yaml:

  • volume: {calls_per_month: N}: how many calls the app makes a month (with targets:, on each entry)
  • prices: per model: input, cached_input and output per 1M tokens (US dollars, or set currency), with source and checked date (or, self-hosted, engine: {prefill_tokens_per_second: N})

leanprompt never guesses a volume or a price. Your coding agent can look up the provider's current price page and add it with the date; how.

What's wrong and what to change

1 open, 1 fixed. Largest first, by the audit's estimate of tokens lost per 1,000 calls.

No confirmed findings.

Open questions

Findings outside this repository, or whose behaviour the code cannot show. They still count in the score. Each says what to confirm.

The 300-second timeout with one SDK retry (line 341) is wrapped by a 3-attempt tenacity retry on the batch path (line 1807) and, after the batch gives up, by a per-paragraph sweep in which each paragraph has its own 3-attempt retry (line 1513).

Finding 1. book_maker/translator/chatgptapi_translator.py:341 high LP-GE-04

A batch that times out is therefore attempted up to 6 times, about 30 minutes, which is the stall the comment above REQUEST_LIMITS set out to prevent, and each abandoned attempt may still be generated and billed.

To confirm
Whether any grouped request on the endpoints people use (reasoning models at high effort, slow local servers, gateways) takes longer than 300 seconds, and whether the endpoint keeps generating and billing after the client gives up. A run log with request durations, or the provider's usage page against the run's own meter, shows it.
Change, if confirmed
Keep one retry layer for timeouts: either set max_retries to 0 on this client and let tenacity own retries, or exclude APITimeoutError from the tenacity retry on the batch path and let the existing one-by-one fallback (or the ladder) handle it. Non-streaming requests can also use streaming so a slow but working answer is not mistaken for a dead one.
Why it matters
A client timeout stops the client waiting; it does not stop the server generating. Each retry after a timeout pays the prompt again while the abandoned answer may still be billed, and the same request times out the same way.
Estimate
about 18k output and 17k prompt tokens per 1,000 calls (estimate, if timeouts happen at all)
What the estimate assumes

0.2% of grouped requests exceed 300 seconds; each produces 5 extra attempts of about 1.7k prompt and 1.8k output tokens, billed although abandoned. If the timeouts come from a gateway that never answers, no tokens are lost and the cost is only wall time.

How to check the fix With a fake client that raises APITimeoutError on a batch, count calls to it: before 3 (the tenacity layer), after 1. In production the SDK's max_retries=1 doubles each attempt, so before is 6 HTTP attempts and after 2.

Other problems the audit found

Problems the audit checked in the code that cost no tokens of their own, such as a spend meter that ignores cache tokens or a cut-off answer accepted as complete. They are not scored. Check each one before you change anything.

A cut-off plain translation is accepted silently

Note 1. book_maker/translator/chatgptapi_translator.py:1366 LP-GE-12 high not scored

_plain_translation returns message.content without looking at finish_reason. After a structured single-paragraph truncation the code retranslates on the plain path (line 1529) with the same output limit, so a paragraph that did not fit can be written into the book half translated, with no warning.

What to change
Check finish_reason == "length" in _plain_translation and print a warning or mark the paragraph, or retry it once with a larger limit.

How to check the fix Translate one paragraph with a deliberately small output limit: the run prints a warning instead of writing a truncated paragraph.

1 fixed finding

When a grouped structured translation is cut off at the output limit, the OpenAI SDK's parse() raises LengthFinishReasonError.

Finding 2. book_maker/translator/chatgptapi_translator.py:1811 high LP-GE-05 fixed how often is assumed

The retry decorator on _execute_structured_batch_translate retries every exception except three, and this one is not among them, so the same cut-off request is sent twice more unchanged, each time paying the full prompt and a full output limit, before the code falls back to translating the paragraphs one by one.

What to change
Fixed after this audit by pull request #590, merged 2026-11-27: a truncated batch is treated as a mismatch, not a transport failure. LengthFinishReasonError and ContentFilterFinishReasonError are caught around the parse call, e.completion is metered as on the single-paragraph path, and BatchMismatch is raised, which the retry skips and the plan-mode ladder answers by halving the chunk.
Why it matters
A request cut off at the output limit will be cut off again: the prompt, the model and the limit are the same. The two identical retries add cost without a usable answer, and they are the most expensive calls of the run, because each one generates up to the output limit.
How often it happens
The code shows the problem; how often it happens is assumed. To measure it: how often a grouped request stops with finish_reason length, from a run log of one book
Estimate
about 41k output and 17k prompt tokens per 1,000 calls (estimate)
What the estimate assumes

1 in 200 grouped requests truncates (endpoints with a low default output limit, or reasoning models whose thinking counts toward it); each repeated retry costs about 1.7k prompt tokens and about 4.1k output tokens (a 4,096-token limit); 2 repeated retries per truncation; grouped requests of 1,200-1,600 source tokens (SESSION_BUDGET_FLOOR/CEILING) with about 1.8k output on average. The first truncated call is not counted: it is how the truncation is found.

How to check the fix In tests/test_chatgptapi_translator.py, a fake client whose parse() raises LengthFinishReasonError on a batch: before, parse is called 3 times; after, once, and BatchMismatch reaches the caller (plan mode then sends two half-size requests).

Fix it with your coding agent

Paste this into Claude Code, Codex, Cursor or any coding assistant. It will check each finding against your code and propose fixes one at a time, asking before it changes anything.

Please check and fix the LLM-call findings from a leanprompt audit of this repository.

1. If the leanprompt skills are not installed for you here, install them: npx leanprompt@0.1.0-dev.15 install
2. Read .leanprompt/findings.json and leanprompt-report.md. If they are missing, use the list below.
3. Check each finding against the code before you change anything. The audit can be wrong: if a finding does not hold, tell me why and leave that code alone.
4. Fix one finding at a time. Show me the change as a small diff and apply it only after I say yes.
5. Prove each fix with the measure-loop skill: a before and after on the same scenario. Ask me before running anything that sends real, billed requests.
6. When a fix is proved, set "fixed": true on its finding in .leanprompt/findings.json and run npx leanprompt@0.1.0-dev.15 score.

Open questions (confirm before fixing):
- LP-GE-04 (book_maker/translator/chatgptapi_translator.py:341): The 300-second timeout with one SDK retry (line 341) is wrapped by a 3-attempt tenacity retry on the batch path (line 1807) and, after the batch gives up, by a per-paragraph sweep in which each paragraph has its own 3-attempt retry (line 1513). A batch that times out is therefore attempted up to 6 times, about 30 minutes, which is the stall the comment above REQUEST_LIMITS set out to prevent, and each abandoned attempt may still be generated and billed. To confirm: Whether any grouped request on the endpoints people use (reasoning models at high effort, slow local servers, gateways) takes longer than 300 seconds, and whether the endpoint keeps generating and billing after the client gives up. A run log with request durations, or the provider's usage page against the run's own meter, shows it.

Other problems found (check each against the code first; not scored):
- A cut-off plain translation is accepted silently (book_maker/translator/chatgptapi_translator.py:1366) [LP-GE-12]: _plain_translation returns message.content without looking at finish_reason. After a structured single-paragraph truncation the code retranslates on the plain path (line 1529) with the same output limit, so a paragraph that did not fit can be written into the book half translated, with no warning. Change: Check finish_reason == "length" in _plain_translation and print a warning or mark the paragraph, or retry it once with a larger limit.

Score

One number from 0 to 100 for how well this app avoids paying for the same tokens twice; higher is better. It is computed from the findings above (static) or from your usage log (measured).

99static
E, prefill reuse
0.99
S, prefix stability
1.00
G, generation waste
0.01
Default shares
0 of 1

Findings scored with severity defaults, not estimates. The fewer, the more the static score says about this app.

A static score is an estimate from the audit's findings, not a measurement.

Scored 2026-11-26 (the date on the machine that ran it).

Questions for the owner

These were not answered during the audit. Until they are, the page shows tokens only and ranks the advice without a priority.

  • Priority: which matters most for this app, cost, speed or quality (or weights)? Not set, so the advice uses equal weights. Answer with priority: in leanprompt.yaml.
  • Volume: how many calls does the app make a month? Answer with volume: {calls_per_month: N, source: "..."} in leanprompt.yaml.
  • Prices: what does each model cost (input, cached input, output per 1M tokens, with the source and the date it was read, and the currency if not US dollars)? Answer with prices: in leanprompt.yaml.