Multimodal LLM APIs: Reducing Token Costs with File Slicing

    File slicing lets applications control which pages, spreadsheet ranges, media segments, and content layers a multimodal LLM processes. This article explains how selective loading can reduce token usage, outlines a four-step slicing strategy, and covers production workflows, quality fallbacks, monitoring, and common pitfalls. It also shows how slicing complements retrieval-augmented generation and tool calling without replacing either.

    Passing an entire file to a multimodal LLM API may seem like the simplest approach, but it often creates two problems.

    First, irrelevant content occupies the context window, leaving the model to find the important material on its own. Second, processing the whole file can incur token costs even when the task needs only a few pages, a small spreadsheet range, or a short audio or video segment.

    File slicing moves decisions about what to read, how much detail to load, and which content layers to use from the model to the calling application. With server-side, on-demand loading, the application can focus the context on relevant material and align processing costs more closely with the selected scope.

    1. Capability Boundaries: Slicing Is More Than Truncation

    File slicing is not simply a matter of breaking a file into smaller chunks. It typically provides two kinds of control: selecting a range appropriate to the file type and selecting the content layers to load.

    The main dimensions fall into four categories.

    Documents and presentations

    Applications can select page ranges, page resolution, and content layers. Typical layers include page text and page images.

    • Page text is suitable for summarization, retrieval, and field extraction, and generally costs less to process.
    • Page images are useful for layout understanding, chart interpretation, stamp recognition, and complex formatting.

    Low, medium, and high image resolutions affect visual token usage. Higher resolution preserves more detail but also increases cost.

    Spreadsheets

    Applications can select worksheet names and cell ranges, along with layers such as data, formulas, and visual elements.

    The key distinction is between calculated values and formulas:

    • If the task needs only results, load the data layer.
    • If it audits calculation logic, include the formula layer.
    • If it examines chart trends, load the relevant visual elements.

    Reading a specific range is more focused than loading the entire workbook. It also prevents unrelated worksheets from diluting the context.

    Video

    Video slicing can select time intervals, frame rates, resolutions, and layers such as transcripts, video frames, or audio.

    Video processing costs are strongly related to duration, frame rate, and resolution.

    • For a question such as “What does this video discuss?”, the transcript is often sufficient.
    • For actions, demonstrations, or visual details, video frames are necessary.
    • For vocal emotion or background sounds, the audio layer is more appropriate.

    Audio

    Audio slicing supports time-window selection. For long meeting recordings, customer support calls, and podcasts, selecting a time interval and then using its transcript is generally more controllable than loading the entire recording.

    Defaults and file limits still matter

    A service may support slicing across its model versions while retaining its existing file-size and page-count limits. Slicing optimizes the loading scope and content layers; it does not bypass file limits.

    When processing options are omitted, the service may use compatibility-oriented defaults. For example, documents and presentations may default to layout-preserving page images, while spreadsheets may include calculated values, formulas, and worksheet names from every worksheet.

    These defaults simplify initial integration, but they are not necessarily cost-efficient. Production applications should explicitly declare slicing options rather than risk loading an entire document as page images when the task needs only one page of text. Check the relevant API documentation for the service’s supported options and defaults.

    2. Why Slicing Reduces Token Usage

    A rough cost model adds the text, visual, and audio tokens processed within the selected scope, each multiplied by its applicable unit price.

    The factors differ by modality:

    • Text tokens depend on the amount of text.
    • Visual tokens are typically related to page area, image resolution, and frame count.
    • Audio tokens are related to duration, sampling, and encoding.

    Slicing reduces the amount of irrelevant content entering the context and allows applications to choose a less expensive layer where appropriate. Actual billing behavior depends on the API.

    Consider a document containing several dozen pages when the task is to extract clauses from pages 3–5. Loading the entire document as high-resolution page images introduces many irrelevant pages and substantially increases visual token usage. Requesting only the text from pages 3–5 produces a smaller context, lower costs, and potentially more consistent results.

    The same principle applies to spreadsheets. If a task concerns one range on one worksheet, loading the entire workbook can introduce unrelated worksheets, blank regions, and charts. Selecting the worksheet and cell range limits the context to the necessary material.

    Public implementation discussions report substantial reductions in prompt tokens when selected page text replaces full-document rendering. Range-based spreadsheet loading can also reduce usage compared with whole-workbook loading. However, there is no universal savings percentage: results depend on layout complexity, resolution, layer selection, and file structure.

    Establish a baseline for your own workload. For each request, record:

    • File type
    • Selected range
    • Content layers
    • Resolution
    • Input and output tokens
    • Task quality

    Use these measurements to tune the strategy rather than relying on a fixed reduction estimate.

    Slicing has its own overhead

    Slicing is not a cost-free optimization. Very small slices increase request counts, scheduling overhead, and the complexity of merging results. Very large slices lose much of the cost advantage.

    A practical pattern is locate first, slice precisely, then fall back:

    1. Use low-cost metadata, text indexes, or summaries to locate the relevant scope.
    2. Load that scope with precise slicing.
    3. If text is insufficient, fall back to images or higher resolution.

    3. A Four-Step Strategy for Task-Aware Slicing

    Step 1: Route by task

    Identify whether the task involves summarization, extraction, question answering, auditing, or visual understanding.

    Summarization can usually start with page text or transcripts. If page images are needed, begin with a lower resolution where appropriate. Field extraction should target specific pages or cell ranges. Formula auditing requires formulas, while visual-operation analysis requires frames or sufficiently detailed images.

    Step 2: Prefer text before vision

    Except for purely visual tasks, start with page text, spreadsheet data, video transcripts, or audio transcripts.

    Text layers are generally cheaper and easier to search. Escalate to images only when text is missing, the layout is complex, or charts and visual content are essential to the answer.

    Step 3: Select meaningful windows

    Use page ranges for documents, worksheet and cell ranges for spreadsheets, and time intervals for audio and video.

    Avoid both oversized windows and a separate request for every page. Where possible, slice at semantic boundaries such as chapters, clauses, meeting sections, or video shots. This reduces the risk of splitting related information across requests.

    Step 4: Add quality-based fallbacks

    Define quality checks for each task, such as field completeness, citation traceability, or manual review results.

    If the text layer fails the quality threshold, switch to images or increase image resolution. If the slice lacks sufficient context, expand the neighboring window rather than immediately loading the entire file.

    The following illustrative pseudocode expresses the decision logic. It does not represent actual API fields or a real interface.

    1. # Illustrative pseudocode, not a real API
    2. def build_slice_plan(task, file_type, question):
    3. if file_type in ("doc", "slides"):
    4. if task == "summary":
    5. return {range: "all", layer: ["text"], resolution: "low"}
    6. if task == "clause_extract":
    7. pages = locate_pages_by_index(question)
    8. return {range: pages, layer: ["text"], resolution: "low"}
    9. if task == "layout_understanding":
    10. pages = locate_pages_by_index(question)
    11. return {range: pages, layer: ["image"], resolution: "medium"}
    12. if file_type == "sheet":
    13. if task == "value_lookup":
    14. return {sheet: locate_sheet(question), range: locate_cells(question), layer: ["data"]}
    15. if task == "formula_audit":
    16. return {sheet: locate_sheet(question), range: locate_cells(question), layer: ["formula", "data"]}
    17. if task == "chart_trend":
    18. return {sheet: locate_sheet(question), range: locate_cells(question), layer: ["visual"]}
    19. if file_type == "video":
    20. if task == "content_summary":
    21. return {time: locate_segment(question), layer: ["transcript"], fps: "low"}
    22. if task == "visual_action":
    23. return {time: locate_segment(question), layer: ["frames"], fps: "medium", resolution: "medium"}
    24. if file_type == "audio":
    25. return {time: locate_segment(question), layer: ["transcript"]}

    The important part is the decision order, not the parameter names:

    • The file type determines the available selection dimensions.
    • The task determines the content layer.
    • The location step determines the range.
    • Quality requirements determine whether to escalate.

    Resolution and frame-rate settings apply to visual processing; they should not be treated as controls for text or transcript token usage.

    4. Production Implementation: Build an Observable File-Processing Pipeline

    In production, slicing should be a defined stage in the file-processing pipeline, not a collection of temporary options scattered through application code.

    A practical workflow has four stages.

    File ingestion and metadata extraction

    Store the original file in object storage and record metadata such as file type, page count, worksheet names, duration, and size.

    This metadata provides the starting point for deciding which selection dimensions are available and whether the file meets the service’s limits.

    Slice-plan generation

    Use the task and metadata to select page ranges, cell ranges, or time intervals. Explicitly specify the content layers and any applicable resolution settings.

    API invocation and source references

    Submit the slicing configuration together with the question. Ask the model to return source references, such as page numbers, worksheet names, cell ranges, or timestamps, so results can be traced back to the selected material.

    Cost and quality monitoring

    Record input and output tokens, slice counts, fallback counts, latency, and sampled quality-review results.

    In a Baidu AI Cloud deployment, object storage, message queues, and logging services can support this workflow: object storage holds the files, queues smooth traffic spikes, and logs capture token usage and processing time. These are general cloud-service categories, not assumptions about worldwide product availability.

    For high-concurrency workloads, design slice requests to be idempotent to avoid duplicate processing and charges. Frequently accessed files can benefit from cached metadata and text indexes, but cache entries must be tied to file versions to prevent stale results.

    Track the following:

    • Token cost per task
    • Average tokens per page or selected region
    • Percentage of tasks completed using text alone
    • Image-layer fallback rate
    • Number of slice requests
    • End-to-end latency
    • Citation traceability rate
    • Manual review pass rate

    Compare the slicing strategy against a whole-file-loading baseline. This makes savings measurable and helps identify overly fragmented requests or unnecessarily high resolutions.

    5. Common Pitfalls and How to Avoid Them

    1. Relying on default image loading

    When options are omitted, documents and presentations may load as layout-preserving page images.

    If the task needs only text, explicitly select the text layer. If images are required, choose the lowest resolution that meets the task’s quality requirements.

    2. Using high resolution for every task

    High resolution is useful for complex layouts, but it is not necessary for every request.

    Summarization, retrieval, and field extraction should start with text or, where appropriate, lower-resolution images. Increase resolution when visual details are needed.

    3. Confusing spreadsheet values with formulas

    The data layer may not expose calculation logic, while the formula layer alone may omit the results needed for verification.

    For auditing, select both formulas and data, or use separate requests to cross-check them.

    4. Splitting tables or paragraphs across pages

    Page-based slicing can cut through tables and paragraphs that continue onto the next page.

    Include overlapping neighboring pages in the slice plan, or restore the missing context when merging results.

    5. Sampling video at an unnecessarily high frame rate

    Start video summaries with transcripts. Use frames for actions, demonstrations, and visual details.

    Match frame rate and resolution to the task rather than setting both to their maximum values by default.

    6. Cropping audio without considering the content layer

    Time slicing alone may not be enough: a long transcript within the selected interval can still be expensive.

    For long recordings, first summarize segments, then request precise transcripts for the important sections.

    7. Creating too many small slices

    One request per page increases scheduling and result-merging overhead.

    Group windows by semantic boundaries, and define both a maximum slice count and a minimum window size.

    8. Ignoring file limits

    Slicing does not change the service’s file-size or page-count limits.

    Files that exceed those limits still need to be split, compressed, or transcoded before entering the slicing workflow.

    6. How Slicing Works with RAG and Tool Calling

    File slicing does not replace retrieval-augmented generation, or RAG.

    Retrieval identifies candidate material within a large collection. Slicing controls how precisely the application reads that material.

    A combined workflow can index page text, spreadsheet regions, or transcript segments, retrieve candidate page numbers, cell ranges, or time intervals, and then load the corresponding source text or images through slicing.

    This avoids loading entire files while also avoiding the detail loss that can occur when an answer relies only on summaries.

    Dynamic slicing through tool calls

    In a tool-calling workflow, the model can determine the next range to read:

    1. Read a table of contents or a low-cost text view to identify relevant sections.
    2. Request specific pages and content layers.
    3. If quality is insufficient, request images or neighboring pages.

    Set a budget ceiling and a maximum number of fallback attempts. Without these limits, repeated tool calls can turn selective loading into an unbounded sequence of slice requests.

    7. Conclusion: Make Reading Scope a Controllable Cost Variable

    File slicing shifts large-file processing from whole-file ingestion toward on-demand loading and, where supported by the API’s billing model, costs that better reflect the selected processing scope.

    The implementation goal is not to memorize a particular interface. It is to establish a repeatable method:

    • Choose selection dimensions by file type.
    • Choose content layers by task.
    • Choose ranges around semantic boundaries.
    • Trigger fallbacks according to quality thresholds.
    • Continuously tune the strategy using monitoring data.

    Cost-sensitive applications should explicitly configure slicing rather than rely on potentially expensive defaults. Quality-sensitive applications should preserve source references and fallback paths so that results remain traceable and verifiable.

    With these controls in place, token costs become less of an opaque whole-file expense and more of a measurable, configurable engineering variable.