On-Demand File Slicing for Large Files: A Practical Guide to Lowering Token Costs

    This article explains how on-demand file slicing reduces token consumption and response latency when processing large documents, spreadsheets, videos, and audio with multimodal LLMs. It covers the core mechanism of range, layer, and fidelity selection, slicing dimensions across modalities, illustrative pseudocode, measured cost savings, validation methodology, common pitfalls, and rollout recommendations for building controllable and governable context engineering.

    1. Why Large Files Are Expensive

    In enterprise applications, handing PDF contracts, presentations, spreadsheets, and audio or video files to multimodal LLMs has become a common requirement. A long-standing engineering tension is that file size correlates with context length, and context length directly determines token consumption and response latency. A tender document hundreds of pages long, a business analysis workbook with dozens of worksheets and many formulas, or a meeting recording several hours long will spend most of its tokens on content unrelated to the current question if injected into the context in full.

    The traditional approach is to preprocess on the application side: split the PDF, export worksheets to text, extract audio transcripts, and then concatenate the prompt. The problem with this path is that parsing results often lose layout, chart, and formula semantics, and the preprocessing logic is scattered across business code, making unified governance difficult. More critically, billing is based on “the amount of content sent to the model,” not “the amount of content the user actually cares about,” so cost is structurally amplified.

    A capability direction that has recently emerged in the industry is “native file slicing control”: returning the decision of “which part to look at” to the caller, loading only the specified range on demand on the server side, and metering only the portion actually inspected. This article treats this general technical approach as its subject and discusses its capability boundaries, parameterization, and engineering practices.

    2. Core Mechanism: From Full Injection to On-Demand Loading

    On-demand slicing can be abstracted as a combination of three actions:

    1. Range selection: determine which pages, worksheet areas, or time intervals to load;
    2. Layer selection: determine which representation enters the context, such as page text, page image, formulas, transcript text, video frames, or audio;
    3. Fidelity selection: determine precision parameters such as resolution and frame rate, balancing information completeness against token volume.

    Together these form an explicit control surface for the “context budget.” The engineering value is not only saving money but also controllability: the caller can construct a different minimal sufficient context for the same file and different questions, making prompt structures stable, reproducible, and testable.

    3. Slicing Dimensions by Modality

    Documents and presentations: selection by page number or page range; fidelity in three tiers (low, medium, high); layers can be page text or page image that preserves layout. The former suits retrieval and summarization with the fewest tokens; the latter suits judgments involving layout, seals, and chart placement.

    Spreadsheets: selection by worksheet name and cell range (such as A1:F200); layers cover calculated values, formulas, and visualization elements. Use calculated values to reconcile data, formulas for audit scope and error troubleshooting, and the chart layer for trend judgment.

    Video: time intervals can be cropped, and frame rate and resolution adjusted; layers can be transcript text, video frames, or audio. Meeting notes scenarios prioritize transcript text; quality inspection and action recognition scenarios require video frames.

    Audio: supports time interval cropping, suitable for locating key segments in long recordings.

    It should be emphasized that these capabilities typically cover current mainstream multimodal model families, and existing per-file size and page limits generally remain unchanged; when processing options are omitted, the server applies a default strategy, for example presenting documents as page images that preserve layout, and returning calculated values, formulas, and worksheet names for all worksheets in a spreadsheet by default. This means “default behavior” and “explicit slicing” may differ by an order of magnitude in cost.

    4. Illustrative Call Structure (Pseudocode)

    The following only expresses how parameters are organized and does not point to any specific API:

    1. response = model.generate(
    2. file=file_ref, # reference to an uploaded file
    3. question="Compare gross margin differences across regions in Q3",
    4. slice_spec={
    5. "type": "spreadsheet",
    6. "sheets": ["Q3_Summary"],
    7. "range": "B2:H40",
    8. "layers": ["values"], # values / formulas / charts
    9. },
    10. )
    1. response = model.generate(
    2. file=contract_ref,
    3. question="Is the wording of the breach liability in Article 7 consistent with the attachment",
    4. slice_spec={
    5. "type": "document",
    6. "pages": "12-15",
    7. "resolution": "medium",
    8. "layers": ["page_image"], # page_text / page_image
    9. },
    10. )

    Engineering practice suggests treating slice_spec as a first-class citizen: let it enter the configuration center along with business parameters, and bring it into version management and canary releases, avoiding situations where “the same question yields different conclusions in different environments.”

    5. Quantifying Benefits and Validation Methods

    Public measurements from early adopters show that extracting text by page can differ by about an order of magnitude in token usage compared with rendering an entire PDF; in tests of general gateway projects, slicing reduced PDF prompt tokens by about two-thirds and workbook tokens by about one-third. These numbers show that benefits are strongly correlated with file structure: files with many pages and low per-page information density benefit most, while files that are already short and highly information-dense benefit little.

    For self-built validation, a three-step method is recommended:

    • Baseline group: full injection, recording prompt tokens, total latency, and answer accuracy;
    • Slicing group: change only slice_spec while keeping other prompts and model parameters unchanged;
    • Attribution analysis: measure the token reduction ratio and quality fluctuation, and locate recall loss caused by “slicing too much.”

    The criterion should be “cost per correct answer,” not simply the magnitude of token reduction.

    6. Common Pitfalls and How to Avoid Them

    First, overly fine slicing granularity triggers multiple calls, and network and scheduling overhead may offset token savings, so a minimum batch threshold should be set. Second, cross-page and cross-sheet reasoning tasks require explicitly adding adjacent ranges, for example leaving one page before and after the interval as a context buffer. Third, wrong layer selection is a hidden source of failures: taking only calculated values when formula auditing is needed leads the model to give plausible but untraceable conclusions. Fourth, permissions and compliance: slicing is not redaction, and sensitive pages or time intervals containing personal information still need compliance processing before upload, along with call auditing supported by enterprise-side logging services and monitoring alerts. Fifth, cost observability: slice_spec and usage details should be persisted together to form a cost dashboard by business line and file type.

    7. Implementation Recommendations

    If you are building a document intelligence application, enable slicing first in read-only question answering scenarios and keep full injection as a fallback channel; then build a slicing template library by file type, distilling reusable configurations such as “contracts focus on clause pages, financial reports focus on main statements and notes, meetings focus on transcripts.” For teams using AI coding tools to generate call code, slicing parameters should be included in the code review checklist to avoid cost regressions caused by default values. Overall, on-demand loading advances context engineering from “tuning by experience” to a stage that is “declarative, measurable, and governable,” which is also a key step for long-document and multimodal applications to scale.