Large Files in LLM APIs: A Practical Guide to On-Demand Slicing and Usage-Based Billing
Learn how on-demand file slicing can reduce LLM processing costs by separating low-cost scanning from detailed analysis. This guide covers the two-pass workflow, slicing options for documents and media, illustrative code, and practical considerations for file reuse, structured results, and token-cost monitoring.
1. Why Whole-File Billing Is a Problem
When processing non-text inputs, LLM APIs typically need to convert files into representations the model can understand. For a PDF containing hundreds of pages, a traditional workflow may render and encode every page, convert the resulting input into tokens, and bill for the full amount—even if the model only needs a few pages to answer the question.
This approach creates three practical problems:
- Costs do not match the value delivered. Users often need answers about only a few pages, a particular worksheet, or several minutes of audio, yet pay to process the entire file. The larger the file, the greater the potential waste.
- Context-window pressure. Passing an entire large file to the model can quickly approach or exceed its context limit, forcing developers to add preprocessing and increasing pipeline complexity.
- Repeated costs across conversation turns. If the same file is fully encoded each time it is referenced, processing costs accumulate with every request.
File-slicing controls address this problem by allowing developers to specify which parts of a file the model should read. Where supported by the platform’s billing model, token charges can then reflect the selected portions rather than the entire file.
2. The Core Strategy: Scan First, Read in Detail Second
File slicing lets the model consume the same file at different levels of detail:
- Text-only extraction: Retrieves text at relatively low cost, making it suitable for search, navigation, and overviews.
- Low-resolution previews: Renders pages or frames at lower resolution to identify layouts and locate charts or other visual elements.
- High-resolution reading: Renders selected pages or segments at higher fidelity for detailed analysis.
A typical implementation uses two passes:
Pass 1: Scan the file using text-only extraction or low-resolution previews→ Return relevant page numbers, cells, or time rangesPass 2: Read only the selected portions at high resolution→ Bill for the selected portions
This scan-then-read workflow applies the retrieval principle of broad candidate selection followed by detailed evaluation to multimodal file processing.
Community-reported tests suggest that text-only page scanning can use more than an order of magnitude fewer tokens than full high-resolution rendering. Selective reading of structured documents such as PDFs has also been reported to reduce token usage by more than 60%, with savings of roughly one-third for spreadsheets.
These figures are indicative, not guaranteed. Actual savings depend on file structure, the proportion of content selected, and scanning granularity. Developers should validate the results against their own workloads.
3. File Types and Slicing Options
File-slicing capabilities span common office documents and multimedia formats. The available selection controls generally follow the structure of each file type, although exact support varies by platform.
| File type | Slicing dimension | Typical use case |
|---|---|---|
| Page ranges | Locating relevant pages in long reports, papers, or contracts | |
| Word document | Pages or sections | Answering questions about part of a large document |
| Presentation | Individual slides | Reading a specific chart and its notes |
| Spreadsheet | Cells or ranges | Querying a particular sheet or region in a multi-sheet workbook |
| Audio | Time segments | Transcribing and analyzing a few minutes of a conversation |
| Video | Time segments or visual layers | Understanding visual content in selected clips |
Another important feature is file reuse. A file can be uploaded once and assigned a persistent reference. Subsequent conversation turns and slicing requests can use that reference without uploading the file again.
When the platform supports reuse of the processed file, this can also avoid repeated full-file encoding overhead. Upload reuse and processing charges should be checked against the relevant API documentation.
4. An Illustrative Two-Pass Workflow
The following pseudocode demonstrates the approach for a large PDF. It is illustrative rather than a platform-specific API example.
# Step 1: Upload once and obtain a file referencefile = client.files.upload(path="annual_report.pdf")# Step 2: Scan the full document in text-only mode to locate relevant pagesscan_result = client.generate_content(file=file,mode="text", # Text-only extraction with low token usageprompt="List the page numbers that discuss 'risk factors'.")# Step 3: Render only the matching pages at high resolutionpages = parse_pages(scan_result.text) # For example: [42, 43, 107]answer = client.generate_content(file=file,mode="high", # High-resolution renderingpage_range=pages, # Billing based on selected portionsprompt="Summarize the key risks discussed on these pages in detail.")
The same workflow applies to spreadsheets, audio, and video. Instead of selecting pages with page_range, the request selects cell ranges or time intervals using the controls supported by the platform.
Use the official documentation for actual method names, parameters, and billing behavior. Platform-provided examples can serve as implementation starting points.
5. Practical Implementation Recommendations
Estimate Costs Before Choosing a Strategy
For smaller files, the orchestration overhead of two passes may outweigh the token savings. Reading the entire file directly can be more economical.
The proportion of the file needed for the final answer is a useful decision factor: the more content the model must read in detail, the less benefit slicing provides.
Make Scan Results Easy to Parse
Ask the model to return structured location data, such as a JSON array of page numbers. This reduces the risk of parsing failures between the scanning and detailed-reading stages.
Cache File References
In conversational applications, associate the uploaded file reference with the session and reuse it across turns rather than uploading the same file for every request.
Combine Slicing with Retrieval
For very long documents, vector retrieval or keyword matching can narrow the candidate content before the scanning stage. This can further reduce the cost of the first pass.
Monitor Actual Token Usage
Compare token consumption and billing before and after introducing slicing. Use production measurements to adjust scanning granularity and the thresholds for detailed reading.
6. Conclusion
On-demand slicing shifts LLM file processing from whole-file ingestion toward selective consumption. It is more than a billing optimization: it gives developers explicit control over which parts of a multimodal file receive detailed processing.
For workloads built around large files and narrowly scoped questions—such as document Q&A, contract review, and audio or video analysis—this approach can reduce costs and improve response times.
Introduce a two-pass workflow where it fits your workload, then validate the savings with actual usage data. Combine it with file storage and model services supported by your chosen platform to build a lower-cost, scalable document-processing pipeline.
