LLM API File Slicing: Reduce Token Costs with On-Demand Loading
Native file slicing lets developers limit LLM input to selected pages, spreadsheet ranges, or media segments and choose the content layers a task requires. This article explains slicing controls, default behavior, reported token savings, and practical workflows for document Q&A, spreadsheet auditing, and audio and video analysis.
1. Why Large Files Are Expensive to Process
When sending unstructured files such as PDFs, Office documents, audio, and video to a large language model, a common approach is to load the entire file into the context window. This creates three problems:
- Wasted tokens: A PDF with hundreds of pages may contain only a few relevant conclusions, tables, or images. Processing the entire document incurs token costs for unrelated content.
- Context window pressure: Large files can approach or exceed context limits, forcing developers to balance chunking, summarization, and truncation.
- Reduced response quality: Irrelevant material adds noise, making it harder for the model to locate and reason about the information that matters.
Native file slicing addresses these issues by letting developers explicitly specify which parts of a file the model should inspect. The server loads only those portions, keeping the context focused and limiting token charges to the content actually processed.
2. Core Concepts: Declarative Slicing and Content Layers
File slicing typically works alongside native file uploads. Its controls fall into two dimensions:
- Spatial or temporal selection: Page ranges, worksheets, cell ranges, and media time intervals determine where to look.
- Content layers: Page text or images, spreadsheet values or formulas, and transcripts or audio determine what to inspect.
This declarative approach moves file parsing from client-side preprocessing to the server. Instead of splitting PDFs, extracting spreadsheet data, or trimming video locally, developers express their requirements through request parameters.
The following JSON illustrates the concept; it is not a specification for a particular API:
{"file": {"file_uri": "oss://bucket/reports/annual.pdf"},"slicing": {"page_range": "12-18","resolution": "medium","layer": "page_text"}}
In this example, only the text from pages 12 through 18 enters the model’s context, regardless of the document’s total length. The remaining pages do not consume input tokens.
3. Slicing Controls by File Type
PDFs and Slide Decks
Typical controls include:
- Page range: Load only selected pages, such as a conclusion section or a specific chapter.
- Resolution: Low, medium, or high. Lower resolution suits broad layout interpretation, while higher resolution supports recognition of chart details.
- Content layer: Choose extracted page text or rendered page images. Text generally has a lower token cost and suits retrieval-oriented Q&A. Images preserve layout, charts, and information in scanned pages, making them useful for visual understanding.
Spreadsheets
Spreadsheet slicing can select:
- Worksheets and cell ranges: Load a range such as
A1:F200from a specific worksheet instead of the entire workbook. - Content layers:
- Data, represented as calculated values
- Formulas
- Visual elements, such as charts
A typical workflow first requests data and worksheet names to understand the workbook, then retrieves formulas from key regions for auditing.
Video and Audio
Media slicing can use:
- Time intervals: Select only a relevant segment, such as three minutes of a meeting recording.
- Video controls: Adjust frame rate and resolution to reduce the token consumption of video frames.
- Content layers: Combine transcripts, video frames, and audio as needed. When the task requires only semantic information, using the transcript avoids visual processing costs.
4. Default Behavior and Compatibility
When slicing options are omitted, the server uses defaults intended to keep behavior predictable:
- Documents and slide decks: Render pages as images that preserve layout to maximize information fidelity.
- Spreadsheets: Include calculated values, formulas, and worksheet names across all worksheets so the model can understand the workbook’s structure.
File slicing typically supports the provider’s latest model families without changing existing file-size or page-count limits. It adds control rather than reducing supported input capacity.
For existing integrations, omitting the new parameters preserves the previous behavior, keeping migration effort minimal.
5. Reported Token Savings
Early adopter measurements indicate substantial potential savings:
- Page-level text extraction used roughly 14 times fewer tokens than rendering an entire PDF.
- Enabling PDF slicing reduced prompt tokens by approximately 67%.
- Enabling workbook slicing reduced prompt tokens by approximately 33%.
These figures are reference points rather than guaranteed results. Actual savings depend on the file structure and the task. Longer documents with narrowly concentrated relevant content offer greater opportunities for savings. If a task genuinely requires the entire file, slicing provides limited benefit.
6. Practical Implementation Recommendations
- Start broad, then focus. For long documents, request the table of contents or a low-resolution overview first. Then retrieve high-resolution slices of relevant sections to create a two-stage workflow.
- Choose layers according to the task. Prefer text for Q&A and information extraction. Use images when charts, document seals, or scanned pages contain essential information.
- Audit spreadsheets in stages. Use calculated values and worksheet names to identify the relevant sheet, then retrieve formulas and visual layers for validation.
- Use transcripts to locate media segments. Find relevant timestamps through the transcript first, then request video frames from those intervals instead of visually processing the entire recording.
- Track costs. Record input tokens, output tokens, and slicing parameters for each request. Establish cost baselines by file type and refine slicing strategies over time.
7. Conclusion
Native file slicing brings the engineering principle of on-demand loading to multimodal LLM file processing. Declarative controls for pages, regions, time intervals, and content layers keep the model’s context focused on what the task requires, with token charges limited to the content actually inspected.
For document Q&A, spreadsheet auditing, and audio and video analysis, slicing can deliver several-fold token savings with minimal integration changes. It is worth considering early in the architecture design process.
