Reducing LLM API Token Costs with File Slicing Controls

    This article explains how file slicing controls in multimodal LLM APIs reduce input token costs, latency, and irrelevant context. It covers slicing dimensions for documents, spreadsheets, videos, and audio; default behavior and explicit configuration; a token cost model; and engineering best practices such as two-stage locate-then-read workflows, quality evaluation sets, caching, and budget monitoring. Developers will learn how to specify page ranges, cell ranges, time intervals, content layers, and resolution to load only what the model needs while preserving file integrity.

    From “Upload Everything” to “Inspect on Demand”: What File Slicing Solves

    Multimodal LLM services increasingly support uploading formatted documents, office documents, audio, and video directly. Developers no longer need to convert everything to plain text first or build complex parsing pipelines themselves. However, “can upload” does not mean “should load in full.” Sending an entire hundred-page document, a workbook with multiple sheets, or hours of audio/video into the model context leads to three typical problems: input token inflation, irrelevant content interfering with answers, and increased first-token latency and processing time. For scanned or mixed text-and-image documents, rendering everything as page images further amplifies visual token consumption.

    The core idea of file slicing control is to decouple file transfer from context loading: files can still be uploaded and stored in full on the server side, but during inference the model loads only the pages, spreadsheet regions, media segments, and content layers the developer specifies. This preserves the original file’s integrity while keeping the context focused on the parts relevant to the question, and tokens are billed according to the actual range inspected. For developers, this is not only a cost optimization technique but also an engineering capability that improves answer accuracy, controls latency, and enforces the principle of least-privilege data access.

    Key Capabilities: Four File Types and Three Selection Dimensions

    1. Documents and presentations: page ranges, resolution, and content layers

    For formatted documents and presentation files, slicing control typically revolves around three dimensions: page range, resolution, and content layer. Page ranges allow loading only pages 1–3, page 5, or a set of discrete pages. Resolution is usually offered in low, medium, and high tiers, letting you trade off recognition accuracy against token cost. The content layer can be page text or page image. Page text suits documents with an extractable text layer—it costs less and preserves structure clearly. Page images retain layout, charts, stamps, and scanned content, but consume more tokens.

    In practice, first determine the document type. If the text layer is complete, prefer it. For scanned documents or complex tables and layouts where the text layer may be missing or out of order, fall back to page images, using lower resolution to locate content and higher resolution for careful reading. Higher resolution is not always better: high resolution for key pages and lower resolution for non-critical pages is often more economical than uniformly high resolution across the whole document.

    2. Spreadsheets: sheet tabs, cell ranges, and calculation layers

    The value of slicing is especially clear for spreadsheets. A workbook may contain dozens of sheets, numerous formulas, and visualization elements, while a user’s question often concerns only a specific region of one sheet. By specifying sheet tabs and cell ranges, the model inspects only the target data. Content layers can cover values, formulas, and visualization elements, allowing you to distinguish “current computed values” from “calculation logic.”

    Pay special attention to cross-sheet references and formula dependencies. If target cells depend on other sheets, simply slicing the target region may lose the calculation context. In that case, explicitly include the dependent sheets or key regions in the slice, or generate a dependency summary before the request. For formula questions, choose the formula layer; for result interpretation, choose the values layer; for chart trends, visualization elements may be needed. The more precise the slice, the more the developer needs a basic understanding of the spreadsheet’s structure.

    3. Video: time intervals, frame rate, resolution, and content layers

    Video processing can be cropped by time interval, with adjustable frame rate and resolution. Content layers include the transcript, video frames, or audio. If the question is about “what was said,” use the transcript layer, which typically costs less than frame-by-frame visual understanding. If the question concerns actions on screen, presentation slide transitions, or product appearance, use video frames, balancing cost by sampling at a lower frame rate overall and raising it only in key intervals. If the question is about tone, ambient sound, or audio events, choose the audio layer.

    The key strategy for video is “locate first, then read closely.” First use a low frame rate, low resolution, or the transcript to locate relevant time segments, then increase frame rate or resolution only for the target interval. Leave a small amount of padding at time interval boundaries to avoid cutting off a sentence or an action.

    4. Audio: time interval cropping

    Audio slicing is relatively straightforward: crop by time interval. It suits use cases such as meeting minutes, customer service recordings, and interview segments. If the question concerns only ten minutes of a recording, there is no need to load the entire audio. In practice, preserve timestamps and speaker information so the model can cite them and so subsequent audits are possible.

    Default Behavior vs. Explicit Configuration: Don’t Overlook the Cost of Omitted Options

    When slicing options are omitted, the system applies default strategies. For example, documents and presentations may default to page images that preserve layout, and spreadsheets may default to including computed values, formulas, and sheet names for all sheets. Default strategies favor “information completeness,” but they are not necessarily economical for large files. Treat default behavior as a baseline, and explicitly specify page ranges, spreadsheet regions, media intervals, resolution, and layers in cost-sensitive or large-file scenarios.

    This capability is available on mainstream multimodal model services, and existing file size and page limits generally remain unchanged. In other words, slicing control optimizes “loading scope and metering”—it does not bypass file specification limits. Developers still need to plan file splitting, asynchronous processing, and failure retries within those limits.

    Illustrative Configuration: Expressing Slicing Intent Clearly

    The following are conceptual configuration examples. They are not real API definitions; they only illustrate how a request should express slicing intent:

    1. {
    2. "file_id": "file_xxx",
    3. "document": {
    4. "pages": "1-3,5",
    5. "resolution": "medium",
    6. "layer": "page_text"
    7. }
    8. }
    1. {
    2. "file_id": "file_xxx",
    3. "spreadsheet": {
    4. "sheets": [
    5. {
    6. "name": "Summary",
    7. "range": "A1:F20",
    8. "layer": ["values", "formulas"]
    9. }
    10. ]
    11. }
    12. }
    1. {
    2. "file_id": "file_xxx",
    3. "video": {
    4. "interval": "00:10:00-00:12:30",
    5. "fps": 1,
    6. "resolution": "low",
    7. "layer": ["transcript"]
    8. }
    9. }

    Follow three principles when configuring: keep the range as small as possible while retaining necessary context; prefer low-cost content layers that still satisfy the task; and set resolution in tiers—low for locating, high for close reading.

    Token Cost Model and Optimization Strategies

    Input tokens can be roughly understood as: sliced range area × layer coefficient × resolution coefficient + metadata overhead. Page images are generally more expensive than page text; high resolution costs more than low resolution; video frames cost more than transcripts. Billing based on the portion actually inspected means that shrinking the range, choosing lighter layers, and lowering resolution for non-critical content all translate directly into cost savings.

    Public practitioner feedback indicates that extracting text by page, compared with rendering the entire document, can reduce tokens by several times to roughly an order of magnitude; loading spreadsheet regions instead of entire workbooks also yields significant reductions. The exact multiplier depends on document structure, resolution, layers, and slicing granularity, so treat these figures as order-of-magnitude references rather than fixed guarantees.

    A recommended engineering approach is a two-stage “locate first, then read closely” workflow: in stage one, use the table of contents, metadata, low-resolution thumbnails, or transcripts to locate candidate ranges; in stage two, issue close-reading requests only for the target pages, cell regions, or media segments. For repeated questions, cache results keyed by “file fingerprint + slice range + layer + resolution” to avoid paying for the same content twice.

    At the same time, monitor request scope, actual token usage, cache hit rate, answer quality, and fallback frequency. Slicing too finely can fragment the context and hurt answers; slicing too coarsely raises costs. Use small-scale A/B testing to find the optimal granularity for your business.

    Engineering Implementation and Risk Control

    When implementing this, start with three things: make slicing configuration explicit, build a quality evaluation set, and set up cost budgets and alerts. Explicit configuration avoids unexpected costs from default behavior. A quality evaluation set should cover difficult cases such as cross-page references, scanned documents, merged cells, formula dependencies, and video timestamp boundary handling. Budget alerts protect against sudden cost spikes from large files.

    For documents with a missing text layer, automatically fall back to page images. For cross-sheet dependencies, expand the region or supplement a dependency summary. For video and audio, keep padding at interval boundaries and validate timestamps.

    On the platform side, you can combine common services such as object storage and log services—for example, those available from Baidu AI Cloud—to build a pipeline for file caching, request auditing, and cost monitoring; document parsing and multimodal preprocessing can be composed as general-purpose capabilities. Overall, file slicing control is not simply “uploading less”—it is about making context loading more precise. Developers should integrate slicing strategy into prompt engineering, retrieval-augmented generation, and observability to achieve a stable balance between cost, latency, and answer quality.