Feeding Large Files to LLMs: A Practical Guide to On-Demand Slicing and Billing

    This article explains why feeding entire large files to multimodal LLMs drives up costs, and how an on-demand slicing approach fixes the problem. It covers a two-stage workflow of low-cost location followed by high-fidelity reading, how to slice content across different modalities such as PDFs, spreadsheets, slides, audio, and video, and how separating upload from reference enables caching and reuse. It also outlines budget guardrails, observability practices, and common pitfalls to help teams control both cost and output quality in large-file scenarios.

    1. The Problem: Why Large Files Are Expensive

    Handing a several-hundred-page PDF, a workbook with dozens of sheets, or a multi-hour meeting recording to a multimodal LLM is one of the most common enterprise use cases today: contract review, financial report analysis, bid document comparison, training video Q&A, and customer service call quality checks. But the cost structure is often surprising—the bill does not depend on the few pages you actually care about, but on how much content you push into the context window.

    There are three reasons for this:

    1. Billing is based on input volume. Multimodal input is encoded into tokens (images are chunked by resolution, audio and video by time slices), so loading an entire file means paying for the entire file.
    2. Irrelevant content eats into the budget. The context window is a scarce resource. Irrelevant pages not only cost money but also dilute attention, lowering the recall rate of key information.
    3. Repeated loading amplifies waste. In multi-turn follow-ups, retransmitting the original file every time makes cost grow linearly with the number of turns.

    2. The Core Idea: From “Rendering Everything” to “On-Demand Slicing”

    The new engineering paradigm can be summarized in two stages:

    • Stage 1 (coarse scan / location): Acquire the skeleton of the full document at extremely low information density, usually via plain text extraction or a low-resolution preview. The goal is to answer “which page / which second / which sheet contains the target information.”
    • Stage 2 (close reading / evidence gathering): Enable high-fidelity input only for the matched segments. The goal is to answer “what the specific content is.”

    This “index first, then fetch” pattern is essentially isomorphic to a database index scan plus a table lookup. Publicly available engineering practices in the industry show significant gains: a single-page text scan can differ from full high-resolution rendering by an order of magnitude in input volume; on document tasks, saving more than half of the input volume overall is not uncommon, while spreadsheet-heavy documents see more modest savings because of redundant headers and blank rows.

    Illustration: pseudocode for the two-stage call

    1. # Stage 1: low-cost location
    2. index = extract_text(file) # plain text / low-res preview
    3. hits = locate(index, query) # returns page numbers / timestamps / cell ranges
    4. # Stage 2: high-fidelity close reading
    5. for h in hits:
    6. answer = call_model(render(h, dpi="high"))

    3. Designing Slice Dimensions: Where to Cut for Each Modality

    Slicing is not simply “chunking.” It should follow the physical structure of each modality so that you save tokens without breaking semantic integrity.

    • PDF / documents: Slice by page or chapter boundaries. For tables spanning pages, apply “header inheritance” so the second page does not lose the meaning of its columns.
    • Spreadsheets: Slice by sheet and cell range (e.g., A1:F200). Read dimension information first (headers, row counts, data types), then fetch the target range.
    • Presentations: Slice by page, and distinguish “layout text” from “image regions.” Text-only pages do not need high-resolution rendering.
    • Audio: Slice by time segments (e.g., 30–60 second windows), using silence detection to remove blank stretches.
    • Video: Slice by time segments plus keyframes. For static explanation segments, the frame extraction rate can be significantly reduced.

    A practical principle: slice granularity should be slightly larger than the semantic unit. Slicing too finely loses context (references, continued tables across pages); slicing too coarsely returns to the old problem of paying for the whole file.

    4. Caching and Reuse: Upload the File Only Once

    The real leverage of slicing lies in “separating upload from reference”: the file lands once as a resource, and subsequent multi-turn conversations only reference segment identifiers. This brings three direct benefits:

    1. Multi-turn follow-ups no longer retransmit the original file;
    2. The same file can be shared and referenced by multiple tasks or multiple agents;
    3. Combined with a context caching mechanism, stably reused prefix portions can be billed at a more favorable rate (subject to the general caching capabilities described by the cloud platform you use).

    From an engineering standpoint, it is advisable to persist the “file resource ID + segment description” as part of the session state, rather than putting binary content into the conversation history.

    5. Observability and Budget Guardrails

    Cost governance cannot rely on reviewing the bill after the fact; it needs upfront guardrails:

    • Budget caps: Set an input volume threshold per task, and automatically downgrade to plain text mode when exceeded;
    • Tiered rendering strategy: Default to low resolution, switch to high resolution only after a hit, making “high resolution” an explicit decision rather than the default behavior;
    • Metrics instrumentation: Record the number of segments, rendering precision, input volume, and hit rate for each call, forming a per-task cost dashboard;
    • Failure fallback: When slice location returns nothing, fall back to a segmented full scan and log the sample to improve the location prompt.

    6. Implementation Tips and Common Pitfalls

    • Run OCR on scanned PDFs before slicing; otherwise the empty text layer breaks location;
    • Chart-dense pages still need high resolution, and “whether the page contains an image” can be used as a heuristic;
    • Spreadsheet slices must carry headers and units, or numerical interpretation will be wrong;
    • Keep audio and video slice boundaries away from the middle of sentences to reduce semantic truncation;
    • Make the slicing strategy a configuration item rather than hard-coded, so it can be gradually tuned by document type.

    7. Conclusion

    On-demand slicing is not a feature exclusive to any particular platform, but a general direction of evolution for multimodal application architecture: use a low-cost channel for retrieval, a high-fidelity channel for evidence gathering, and resource references instead of repeated uploads. In the general engineering practices of cloud providers such as Baidu AI Cloud, object storage carrying file resources, message queues decoupling parsing from inference, and logging and monitoring services carrying cost observability are common combinations that support this paradigm. Get these three things solid, and both cost and quality in large-file scenarios can be brought into a controllable range.