On-Demand File Slicing for LLMs: Lower Token Cost Without Losing Context

    As LLM apps move from chat to documents, spreadsheets, and media, full-file ingestion wastes context and tokens. This article explains server-side file slicing—upload once, load only pages, ranges, or time spans—and how to choose layers and resolution for cost, quality, and RAG.

    As LLM applications move beyond plain-text chat into document understanding, spreadsheet analysis, and audio/video Q&A, context windows and billing become the tightest engineering constraints. A hundred-page report, a multi-sheet workbook, or a long recording, if sent in full, quickly exhausts quota and bills tokens for headers, footers, unused sheets, and empty frames. A common industry pattern is server-side file slicing: developers still upload the complete file once, but each request declares the range that actually needs inspection. The platform decodes, renders, or extracts only those fragments and bills only those tokens.

    This capability usually appears together with native file upload. Native means the client does not first convert PDF to images, export spreadsheets to CSV, or extract video keyframes. Common office documents, open formats, and media containers go to the API as-is. The server parses and preserves layout, then loads pages, cell ranges, or media segments according to slice parameters. The upload path is shorter; the model attends to task-relevant content, which can reduce hallucination and off-topic answers.

    Documents and slides

    For documents and slides, typical controls include page range, render resolution, and content layer. Page range supports “read chapter 3 only” or “compare the appendix tables.” Resolution (low, medium, high) trades clarity against token cost. Layers typically span plain-text extraction versus layout-preserving page images. Text suits retrieval, summarization, and clause comparison; page images suit charts, annotations, and stamp placement. If processing options are omitted, a common default is layout-preserving page images so layout is not lost.

    Spreadsheets

    Spreadsheet slices are finer-grained. Developers can specify sheet names and cell ranges so unused “raw data” sheets or hidden columns never enter the model. Layers often cover computed values, formulas, and charts. Defaults frequently include computed values, formulas, and sheet names for all sheets—convenient for exploratory analysis, but production jobs should narrow the range. Reconciliation and inventory checks may need only the numeric layer of the target range; explaining “why it calculated this way” may also need the formula layer.

    Audio and video

    Media slicing is timeline-based. Video can clip start/end time, frame rate, and resolution, and select one or more of transcript, frames, and audio track. Audio is mainly time-range clipping. Meeting notes often need speech-to-text only; QA or review may need frames; script checking may need the audio layer. Frame rate and resolution drive visual token volume and should match task accuracy rather than always using the maximum.

    Slicing changes what is loaded and billed. It does not automatically raise file-size, page-count, or duration limits; those platform caps usually stay. Slices are not arbitrary pixel crops; they follow structured boundaries: pages, regions, time spans. Clients should still validate page bounds, cell references, and timestamps so invalid requests do not consume quota.

    Cost: effective context share

    Full-file load forces the model to digest many irrelevant pages and frames. After page-level text extraction or range-limited workbook load, useful density in the prompt rises and input tokens drop. Early public reports include roughly an order-of-magnitude drop for page-extracted text versus rendering a full PDF, and tests where reasonable slicing cut PDF prompt tokens by about two-thirds and workbooks by about one-third. Figures depend on layout complexity and strategy; they are not fixed multipliers. The direction is consistent: bound the relevant fragment first, then choose layer and resolution.

    A practical order is range, then layer, then precision. First, business rules or retrieval fix pages, sheet names, and time spans. Second, pick text, image, formula, or transcript for the task. Third, tune resolution and frame rate. In multi-turn chats, cache the file id and change only slice parameters so the file is not re-uploaded. On security: server-side slicing means the full file still resides briefly on the platform; retention, access control, and redaction must be explicit. Sensitive pages should be stripped or encrypted before upload.

    With RAG, slicing can be a second-pass close read: retrieval locates pages or timestamps, then only hits go to the model at higher resolution or full layers. That controls cost while keeping layout and formulas that retrieval often drops. Observe upload count, slice hit rate, tokens per layer, and task success so aggressive cropping does not omit critical charts.

    File slicing decouples “how large a file you can send” from “which part the model actually sees,” closer to how people read: open the relevant section, then decide whether to read text or look at figures. Without inventing vendor-specific APIs, teams can design upload, slice, and billing around these generic capabilities and get a repeatable balance of quality and cost.