LLM API File Slicing: Reduce Token Costs with On-Demand Loading
File slicing lets developers load selected pages, spreadsheet ranges, or media segments into an LLM’s context instead of processing entire files. This article explains slicing dimensions, content-layer selection, a two-stage processing workflow, and the trade-offs between token costs and context completeness. It also covers reported savings and practical considerations for document and multimedia workloads.
1. Why Large Files Create a Token Cost Problem
In document question answering, contract review, and report analysis, developers often need large language models to process PDFs, Office documents, audio, and video. Two approaches are common:
- Load the entire file: Put all its content into the context window. This is straightforward to implement, but token consumption can be substantial. Irrelevant material can also distract the model and increase latency and cost.
- Preprocess on the client: Parse and split files before calling the model, then submit only relevant sections. This reduces token usage, but requires maintaining a parsing pipeline across different formats, layouts, and content layers.
File slicing, also called partial content loading, addresses this trade-off through native server-side controls. Developers specify which portions they need, and the service trims the file content during loading. Token charges then reflect the content actually included in the context.
This moves on-demand loading from client-side preprocessing to the server, combining simpler integration with more precise cost control.
2. File Slicing Capabilities
Alongside native file input support for PDFs, office documents, presentations, spreadsheets, audio, and video, slicing controls allow developers to select content by page, sheet, cell range, time interval, resolution, and content layer.
Documents and Presentations
- Page ranges: Load only selected pages—for example, pages 5–12 of a contract.
- Resolution: Choose low, medium, or high resolution. Low resolution is generally sufficient for text-extraction tasks; higher resolution is useful when inspecting detailed charts, stamps, or scanned pages.
- Content layers: Select page text or page images. Text uses fewer tokens and suits structured question answering. Images preserve visual layout and are useful when the task depends on formatting, table placement, or multi-column structures.
Spreadsheets
- Worksheet tabs: Select one or more worksheets.
- Cell ranges: Load a specific region, such as
A1:H50, rather than the entire workbook. - Content layers: Select data values, formulas, and visual elements separately. Use the data layer for numerical checks, the formula layer for formula audits, or both when the task requires them.
Audio and Video
- Time intervals: Request only relevant segments, such as minutes 10–25 of a meeting recording.
- Frame rate and resolution: Reduce video frame rate or resolution to lower visual token consumption.
- Content layers: Combine transcripts, video frames, and audio tracks as needed. A summary task may need only the transcript, while analyzing an operational demonstration may also require video frames.
Default Behavior
When slicing options are omitted, the system uses conservative defaults:
- Documents and presentations use page images that preserve layout.
- Spreadsheets include calculated values, formulas, and worksheet names across all worksheets.
These defaults allow existing code to continue working without changes; slicing is an optional addition. File size and page-count limits remain unchanged. Slicing affects how much content enters the context, not how large a file can be uploaded.
3. Designing a File Slicing Strategy
Use a Two-Stage Workflow
For long documents with an unfamiliar structure, use an overview first, detailed reading second workflow.
The following example illustrates the approach:
# Stage 1: Get a structural overview using low resolution and text onlyoverview = generate(file=file_ref,pages="1-3", # Alternatively, use the text layer from all pagescontent_layer="text",resolution="low",prompt="List the document structure and the page range for each section")# Stage 2: Load the relevant pages based on the overviewdetail = generate(file=file_ref,pages="12-18",content_layer="image", # Use when layout information is neededresolution="high",prompt="Answer questions about this section...")
The overview stage uses relatively few tokens while helping locate the sections that deserve closer inspection. The second stage then loads those sections at the appropriate level of detail, avoiding unnecessary full-file processing.
Match Content Layers to the Task
| Task | Recommended Slicing and Content Layers |
|---|---|
| Key information extraction | Text only, low resolution, relevant pages |
| Layout or chart interpretation | Page images at medium or high resolution |
| Spreadsheet value verification | Data layer, selected worksheets and cell ranges |
| Formula compliance checks | Formula layer, selected worksheets |
| Meeting minutes | Transcript layer, selected time interval |
| Operational demonstration analysis | Video frames at a reduced frame rate, plus transcript |
Balance Cost and Quality
Slicing too narrowly can remove necessary context. A spreadsheet may reference cells in another worksheet, for example. Loading only one sheet can leave the model without the information needed to understand those dependencies. Include the referenced regions or explain the dependencies in the prompt.
Higher resolution is not always better. For text-only tasks, high-resolution page images can substantially increase visual token usage without meaningfully improving quality.
Use coarse-to-fine processing for audio and video. First locate relevant segments using a transcript alone or low-frame-rate, low-resolution video. Then load video frames for the target interval when closer visual inspection is necessary.
4. Benefits and Reported Savings
The reported tests show substantial reductions in token usage:
- Extracting text by page used roughly 14 times fewer tokens than rendering an entire PDF.
- PDF slicing reduced prompt tokens by approximately 67%.
- Spreadsheet workbook slicing reduced prompt tokens by approximately 33%.
These figures illustrate the potential savings rather than a uniform result for every workload. The underlying principle is straightforward: token charges apply to the content actually loaded for inspection, rather than portions that were not requested.
For enterprise applications, the benefits fall into three areas:
- More controllable costs: The marginal cost of processing a large file shifts from its total size toward the scope actually inspected, making batch processing of long documents more economically practical.
- Better-focused context: Keeping the context relevant reduces interference from unrelated information and can improve answer accuracy and consistency.
- Simpler engineering: Developers can declare slicing requirements through API parameters instead of building complex parsing and splitting pipelines. Format-specific handling moves to the service side.
5. Practical Considerations
- Align slice boundaries with the task. Broad slices waste tokens; narrow slices may omit essential context. Log slicing parameters and results for each request, then refine configurations over time.
- Account for combined multimodal costs. Loading multiple content layers adds to token consumption. Pay particular attention to frame rate when combining video frames with audio.
- Respect existing upload limits. Slicing does not increase the maximum supported file size. Files that exceed upload limits still require splitting or preprocessing.
- Preserve coverage for whole-document tasks. For summaries that require understanding the entire file, consider processing successive slices and maintaining a rolling summary to balance cost with completeness.
6. Conclusion
File slicing brings the familiar principle of on-demand loading to LLM APIs: developers specify the content they need, the system loads that content, and token usage reflects what enters the context.
Across documents, presentations, spreadsheets, audio, and video, selective loading can make large-file processing more efficient without requiring a separate client-side parsing pipeline. A two-stage workflow, task-specific content-layer selection, and ongoing measurement of token savings provide a practical foundation for controlling costs while retaining the context needed for reliable results.
