Google’s new Gemini API file slicing update solves one of the most expensive headaches I’ve hit when building document-heavy AI features. Until now, passing a 90-page vendor contract or a 14-tab Excel budget into a prompt meant paying input tokens for the entire file—or maintaining brittle Node.js and Python pre-parsers just to chop files up yourself.
That changes the billing math overnight. Announced on the Google Developers Blog and rolled out across the official Gemini API documentation, developers can now upload full PDFs, multi-sheet workbooks, audio, and video once, and instruct Google’s servers to load only the exact pages, cell ranges, or timestamps needed for a single turn.
In addition, Google added native upload support for Microsoft Office (.xlsx, .docx, .pptx) and OpenDocument files without forcing you to convert everything to PDF or CSV first. Here’s what shipped, how the new request parameters work in code, and where I’m already swapping out custom parsers.
What Shipped in Gemini API File Slicing
First, let’s separate marketing headlines from what actually changed at the SDK level. Previously, uploading a file via the Files API cached the asset, yet referencing that URI inside a prompt still pulled the whole file into the context window.
Now, however, you attach a processing block directly on the input part:
- Spreadsheet tab and A1 cell crops: Target a specific 1-indexed worksheet (
sheet_index) and crop an exact A1 range like"A1:G40"viavisible_cells. - Selectable spreadsheet layers: Choose whether the model inspects evaluated
"data", raw"formulas", or rendered chart"visuals"—so you don’t burn vision tokens when you only need formula audits. - PDF page ranges & media segments: Load pages 12–15 of a 200-page compliance PDF or a 45-second clip from a recorded meeting without re-encoding files on your own backend.
- Dynamic slicing inside tool responses: An AI agent can inspect a table of contents on turn one, then return slice coordinates inside a
function_resulton turn two to zoom in on a single section.

Code Example: Slicing an Excel Workbook Without CSV Glue Code
In my own full-stack apps—whether I’m wiring a Node.js backend for an Angular Gemini AI workflow or handling file uploads from a type-safe React form—I used to install xlsx or pdf-lib just to trim user uploads before calling the LLM. Now you upload the raw .xlsx file once and slice it per query:
// slice-workbook.ts — TypeScript / Node.js example with @google/genai
import { GoogleGenAI } from '@google/genai';
const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });
export async function auditQuarterlyVariance(localFilePath: string) {
// 1. Upload the raw Excel workbook once (no CSV conversion needed)
const workbook = await ai.files.upload({
file: localFilePath,
config: {
mimeType:
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
},
});
// 2. Load ONLY Sheet 2, cells A1:F35, inspecting values + raw formulas
const interaction = await ai.interactions.create({
model: 'gemini-3.7-flash',
input: [
{
type: 'document',
uri: workbook.uri,
mimeType: workbook.mimeType,
processing: {
type: 'static',
spreadsheetOptions: {
sheetIndex: 2, // 1-indexed worksheet position
visibleCells: 'A1:F35',
contentLayers: ['data', 'formulas'],
},
},
},
{
type: 'text',
text: 'Flag any broken SUM/INDEX formulas or >15% Q3 margin drops in this range.',
},
],
});
return interaction.outputText;
}
Notice what disappeared from our dependency tree. We didn’t install a third-party spreadsheet parser, we didn’t flatten formulas into dead strings, and we didn’t pay for the other thirteen tabs sitting in that workbook.
Before vs. After Gemini API File Slicing
To see why this update matters for production unit economics, compare how a typical 150-page PDF or 10-tab financial model behaved before versus today:
| Workflow Dimension | Legacy Full-File Ingestion | Server-Side File Slicing |
|---|---|---|
| Input Token Billing | Billed for 100% of pages/tabs on first uncached turn | Billed only for the sliced pages, cells, or timestamps |
Office Formats (.xlsx, .docx) | Required custom LibreOffice / SheetJS conversion | Native server-side ingestion out of the box |
| Excel Formula Visibility | Lost during CSV export unless custom-serialized | Preserved via contentLayers: ['formulas'] |
| Time-to-First-Token Latency | Slow on 50+ MB documents | Significantly faster on narrow slices |
Two Caveats Worth Knowing Before You Refactor
Don’t delete every local parser blindly, though. While testing this pattern against real enterprise documents, two practical trade-offs stand out right away.
1. You Still Need a Way to Know Which Slice to Request
If your users upload unpredictable PDFs where the pricing schedule sits on page 4 in one contract and page 67 in the next, hardcoding pages: '1-5' won’t work. Instead, use a two-step agent pattern: grab the first two index pages cheaply on step one, let the model pick the target page numbers, and fetch that exact slice on step two.
2. Context Caching Still Wins When Every Question Needs the Whole File
On the other hand, if an analyst runs twenty cross-document questions that genuinely span every chapter of a legal brief, slicing five pages at a time risks missing cross-references. In that scenario, explicit Gemini Context Caching on the full document remains the safer architectural choice.
Developer FAQ on Gemini API File Slicing
Does file slicing require re-uploading the document for every query?
No. You upload the source PDF, Office file, or video once via the Gemini Files API, store the returned file.uri, and pass different processing slice coordinates on each subsequent API call without re-transmitting the file bytes.
Are sheet_index values zero-based or one-based?
sheet_index is 1-indexed, matching spreadsheet tab order starting at 1 rather than 0. Therefore, double-check off-by-one indexing if your frontend tab picker uses zero-based array indices.


View comments (1)