Repository navigation
Capping what one batch of llm_client image captions can cost #2593
domondi1
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
With
llm_clientset, MarkItDown sends one vision request per image: every picture in a PPTX and every image file you convert. Converting a folder of slide decks is one job that can turn into hundreds of image calls, and since MarkItDown doesn't setmax_tokenson those requests, there's no natural ceiling on what one batch costs. If a run goes sideways (a huge deck, a retry loop in your script), you find out on the invoice.llm_clientis just an OpenAI client, so you can put a hard dollar limit on a batch without changing MarkItDown: point the client at an OpenAI-compatible gateway that enforces a per-job budget, and tag every request with the batch's id and budget.Afterwards:
shows how many caption calls the batch made and what they cost.
What happens when the budget runs out depends on the converter, which is worth knowing even if you don't use a gateway:
convert()raisesFileConversionExceptionwrapping the 402, so catch it in your loop if you'd rather keep going without a description.Each request reserves its worst-case cost before it's sent and is refused with HTTP 402 before it reaches OpenAI if the batch can't cover it. Because MarkItDown doesn't pass
max_tokens, the reservation assumes a 4,096-token reply (plus a fixed allowance per image), so the last request or two before the cap may be refused a bit early. Unused reservation is released as each caption comes back, and the batch total is based on real usage. The two headers aren't forwarded to OpenAI.What I tested: markitdown 0.1.8 and inferrail 0.4.12, with a local stub upstream standing in for OpenAI. I converted an 8-image PPTX and a PNG with a generous budget and with a tight one. I haven't done a full real-API run yet. Caveats: chat completions only; the model needs a price in Inferrail (
gpt-4o-mini,gpt-4.1-mini,gpt-4.1are built in,inferrail modelslists others, and you can add your own);inferrail.start()keeps its budget in a local SQLite file, so for several worker processes run one sharedinferrail serveinstead.Setup details: guide. I maintain Inferrail (open source, Apache-2.0), so take the suggestion with that in mind.
All reactions