Stop Uploading the Whole PDF: Gemini File-Slicing Controls

Use Gemini's file slicing controls to upload a document once, then request exact page ranges, worksheet cells, and video windows from inside function responses. Includes parameter tables, a runnable skim-then-zoom example, and the token numbers Google's own pages disagree on.

November 26, 2026
geminifile-slicingmultimodalragdocumentsfunction-callingtoken-optimization

The short version

You no longer have to choose between dumping a 400-page PDF into context and building a preprocessing pipeline to cut it up first. Gemini now accepts a processing object on document, spreadsheet, video, and audio blocks: you name the page range, worksheet tab and cell range, or time window, pick the resolution, and pick which layers you want back — page_text versus page_image, data versus formulas versus visual, transcript versus frames versus audio. You are billed for the slice you asked for, not the file you uploaded.[1][2]

The part that changes agent architecture: the same options work inside a function_result, so the model can call your tool, get back pages 14–16 of a service manual at high resolution, and then ask for pages 22–24 after reading them. Your harness stops shipping ffmpeg, LibreOffice, and a PDF renderer to every user.[1][5]

This guide covers the request shapes, the parameter semantics, and the failure modes — including two sets of video and audio token rates in Google's docs that do not match, which is why you should measure instead of hard-coding.

Prerequisites

  • A Gemini 4 model (gemini-4-hydrogen in the examples below). Slicing "works across all Gemini 4 models" per the launch post; the documentation says the processing options are supported in both user inputs and tool results on Gemini 3 and Gemini 4.[1][2]
  • The google-genai Python SDK with the Interactions API (client.interactions.create). The REST equivalents live at POST /v1beta/interactions.
  • A file uploaded through the Files API. Files are stored for 48 hours, and uploading is free in all regions where the API is available.[2]
  • Familiarity with multimodal prompt structure. If you are new to it, start with Gemini Multimodal Prompting, then come back — this page assumes you already know how to pass a document or video block.

One thing to check before you design around this: the whole-file limits still apply. 50 MB per file, 1,000 pages per PDF, 2,000 pages or slides per Office or OpenDocument file, and 50,000 cells per spreadsheet sheet. Slicing changes what you are billed for and what the model sees — not what you are allowed to upload.[2]

The request shape: one block, two knobs

Every slice is configured the same way. The media block carries a resolution field at the top level and a processing object whose type is "static":

{
    "type": "document",
    "uri": uploaded_doc.uri,
    "mime_type": "application/pdf",
    "resolution": "high",
    "processing": {
        "type": "static",
        "page_options": {
            "start_page": 3,
            "end_page": 7,
            "content_layers": ["page_image"],
        },
    },
}

The inner object changes by media type: page_options for PDFs, documents, and presentations, spreadsheet_options for workbooks, and start_offset / end_offset / fps / content_layers directly under processing for video and audio. resolution always stays on the outer block.[2][4]

MediaSlice fieldsLayersResolution
PDF, Word, PowerPointstart_page, end_page (1-indexed, inclusive)page_image, page_textlow, medium, high
Spreadsheetssheet_index (1-indexed tab position), visible_cells (A1 notation)data, formulas, visuallow, medium, high
Videostart_offset, end_offset, fpsframes, audio, transcriptlow, high
Audiostart_offset, end_offset—fixed tokenization

Two defaults are worth memorizing, because they decide your bill when you forget to set anything. For documents and slides, omitting processing sends layout-preserving page images at medium resolution — roughly 560 tokens per page on Gemini 4 and Gemini 3. For spreadsheets, omitting it sends evaluated values, formulas, and sheet names across every tab.[1][2]

A 200-page deck at the default is about 112,000 input tokens. The same deck skimmed as page_text is a fraction of that, and you only pay the image rate for the three pages that actually contain charts. That gap is the entire reason the feature exists.

Step 1 — Upload once, reuse the URI

from google import genai

client = genai.Client()
doc = client.files.upload(file="quarterly_report.docx")
print(doc.uri, doc.mime_type)

Expected output: a files/... URI and the MIME type. Keep both — the URI is the handle you will pass on every subsequent turn and inside every tool result. Re-uploading per turn is the most common way to erase the savings you just bought.

The Office and OpenDocument formats are supported natively now, so you can upload .docx, .doc, .dotx, .odt, .pptx, .ppt, .odp, .xlsx, .xls, and .ods without converting to PDF first:[1][2]

File typeExtensionMIME type
Word.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.document
Word (legacy).docapplication/msword
Word template.dotxapplication/vnd.openxmlformats-officedocument.wordprocessingml.template
ODT.odtapplication/vnd.oasis.opendocument.text
PowerPoint.pptxapplication/vnd.openxmlformats-officedocument.presentationml.presentation
PowerPoint (legacy).pptapplication/vnd.ms-powerpoint
ODP.odpapplication/vnd.oasis.opendocument.presentation
Excel.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Excel (legacy).xlsapplication/vnd.ms-excel
ODS.odsapplication/vnd.oasis.opendocument.spreadsheet

If a part carries an unsupported MIME type, the API returns 400 INVALID_ARGUMENT naming the field and listing the accepted types — a useful check to run once with your document set before shipping.[5]

Step 2 — Skim cheaply with the text layer

Ask a locating question against the whole document, but pull only page_text:

skim = client.interactions.create(
    model="gemini-4-hydrogen",
    input=[
        {
            "type": "document",
            "uri": doc.uri,
            "mime_type": doc.mime_type,
            "processing": {
                "type": "static",
                "page_options": {"content_layers": ["page_text"]},
            },
        },
        {"type": "text", "text": "Which page has the revenue bridge chart? Answer with a page number and one sentence."},
    ],
)
print(skim.output_text)
print(skim.usage.total_input_tokens)

You get a page number back plus a token count you can log. Two details matter here. First, with page_text set, Gemini extracts text instead of rendering pages — you lose layout, chart geometry, and anything that exists only as a picture, which is fine for a locating pass and wrong for a reading pass. Second, the model is also told the total page count, so it can reason about where in a 300-page file it is even when you only sent it text.[2]

Make your locating prompt demand a page number. A skim that returns "the revenue bridge is discussed in the financial performance section" gives the agent nothing to slice, and you will pay for the whole document again on the next turn.

Step 3 — Zoom one page at high resolution

detail = client.interactions.create(
    model="gemini-4-hydrogen",
    input=[
        {
            "type": "document",
            "uri": doc.uri,
            "mime_type": doc.mime_type,
            "resolution": "high",
            "processing": {
                "type": "static",
                "page_options": {
                    "start_page": 3,
                    "end_page": 3,
                    "content_layers": ["page_image"],
                },
            },
        },
        {"type": "text", "text": "Read the revenue bridge chart on page 3. Give the waterfall values in order and quote any footnotes."},
    ],
)
print(detail.output_text)

Single-page ranges are where the economics land: one page at high is about 1,120 tokens on Gemini 4 and Gemini 3 models, so a three-page zoom is roughly 3,400 tokens against 560 × 200 for the full deck at default settings.[2][3]

The documentation's own advice is the pattern this page is named after: "For large documents or slide decks, scan with page_text first. Then request page_image at high resolution only for pages with charts or dense layouts."[2] Note that resolution for PDFs is genuinely a quality dial, not just a cost dial — Google's own media resolution guide recommends medium for PDFs overall and notes that going to high "rarely improves OCR results for standard documents," while scanning a chart is exactly the case where it does.[3]

You can also ask for both layers in one call (["page_text", "page_image"]) when you want the model to reconcile what the page says with how it looks. It costs the image tokens plus the text.

Slicing workbooks

Spreadsheets get tab and range control instead of page control:

workbook = client.files.upload(file="financial_model.xlsx")

audit = client.interactions.create(
    model="gemini-4-hydrogen",
    input=[
        {
            "type": "document",
            "uri": workbook.uri,
            "mime_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            "resolution": "high",
            "processing": {
                "type": "static",
                "spreadsheet_options": {
                    "sheet_index": 2,
                    "visible_cells": "A1:H50",
                    "content_layers": ["data", "formulas", "visual"],
                },
            },
        },
        {"type": "text", "text": "Audit the EBITDA formulas and chart in Sheet 2 (A1:H50). Flag any hardcoded constants inside the formula range."},
    ],
)
print(audit.output_text)

Field semantics, from the documentation:[2]

  • sheet_index is the 1-indexed position in tab order, not the sheet name. Omitting it includes all sheets. 0 or a number above the sheet count returns INVALID_ARGUMENT.
  • visible_cells takes A1 notation — A1:H50, or a single cell like B5 — and crops every selected layer to that region.
  • content_layers defaults to ["data", "formulas"]. data is evaluated values, formulas is the raw formula text, visual is a rendered snapshot of charts and layout. Only include visual when you need the rendered layer, and set resolution when you do.
  • Default without processing on Gemini 4 is all tabs with values, formulas, and sheet names.

The formula layer is the one people miss. If you ask "why does this cell say 4.2M?" against data only, the model sees the value and has to guess at the provenance. Sending formulas for the region lets it see the reference chain. For a deeper treatment of using model output to drive spreadsheet work, see Gemini Code Execution.

Slicing video and audio

Video uses the same processing object with time offsets as second strings and an explicit frame rate:

transcript_turn = client.interactions.create(
    model="gemini-4-hydrogen",
    input=[
        {
            "type": "video",
            "uri": video_file.uri,
            "mime_type": video_file.mime_type,
            "processing": {"type": "static", "content_layers": ["transcript"]},
        },
        {"type": "text", "text": "Find the timestamps where the speaker demos the architecture diagram."},
    ],
)

detail_turn = client.interactions.create(
    model="gemini-4-hydrogen",
    input=[
        {
            "type": "video",
            "uri": video_file.uri,
            "mime_type": video_file.mime_type,
            "processing": {
                "type": "static",
                "start_offset": "420s",
                "end_offset": "465s",
                "fps": 2.0,
                "content_layers": ["frames"],
            },
        },
        {"type": "text", "text": "Describe the architecture diagram in this clip and summarize the explanation."},
    ],
)

The rules that bite:[4]

  • Offsets are strings ending in s — "1200s", "10.5s". An end_offset past the video length clamps to the end; a start_offset past the video length returns 400 INVALID_ARGUMENT.
  • fps must be in the open interval (0, 24]. 0.5 means one frame every two seconds.
  • Default content_layers in static mode is ["frames", "audio"]. Pass ["transcript"] alone to pay text rates for a locating pass, then ["frames"] for the clip you actually care about.
  • resolution is low or high for video, and it is independent of the processing mode — you can run low resolution with static slicing or high resolution with agentic navigation.[3]
  • Audio clipping uses the identical shape on an audio block: {"type": "static", "start_offset": "60s", "end_offset": "150s"}, defaults "0s" to end of file, and bills only the clipped duration.[7]

For prompting patterns on the content itself — timestamps, scene descriptions, meeting extraction — see Gemini Video Processing and Gemini Audio & Speech.

The alternative: let the model navigate

Static slicing is you deciding what to send. Gemini 4 Carbon, 4 Argon, 4 Neon, 4 Hydrogen, 3.8 Flash, 3.6 Flash, and 3.5 Flash Lite also offer agentic video understanding — set "processing": "agentic" and the model navigates the timeline itself, loading transcript, frames, and audio on demand. Google reports it as "up to 88% more token-efficient and ~7% higher quality on long-form content," supported by processing_call and processing_result steps in interaction.steps that interleave with thought steps.[4]

Pick between them on query shape, not on the headline number. Agentic wins for long-form recordings and needle-in-a-haystack retrieval, but Google's own guidance says it can increase time to first token and total tokens on clips under five minutes because navigation adds reasoning and tool round-trips. Static slicing wins when you already know the window, when you need the same slice reproduced byte-for-byte across runs, or when your agent's own tool calls are doing the deciding — which is the next section.[4]

Handing the knife to the agent

The feature that removes preprocessing from your harness is that processing and resolution are legal inside a function_result. Your tool declares the slice parameters; the model fills them; you return a document block instead of text.

from google import genai

client = genai.Client()
manual_file = client.files.upload(file="service_manual.pdf")

tools = [
    {
        "type": "function",
        "name": "inspect_document_pages",
        "description": "Load specific pages of service_manual.pdf as page images.",
        "parameters": {
            "type": "object",
            "properties": {
                "start_page": {"type": "integer", "description": "1-indexed start page."},
                "end_page": {"type": "integer", "description": "1-indexed end page."},
            },
            "required": ["start_page", "end_page"],
        },
    }
]

turn1 = client.interactions.create(
    model="gemini-4-hydrogen",
    tools=tools,
    input="Use inspect_document_pages to read pages 14-16 of service_manual.pdf.",
)

call = next(s for s in turn1.steps if s.type == "function_call")

turn2 = client.interactions.create(
    model="gemini-4-hydrogen",
    previous_interaction_id=turn1.id,
    tools=tools,
    input=[
        {
            "type": "function_result",
            "call_id": call.id,
            "name": call.name,
            "result": [
                {
                    "type": "document",
                    "uri": manual_file.uri,
                    "mime_type": "application/pdf",
                    "resolution": "high",
                    "processing": {
                        "type": "static",
                        "page_options": {
                            "start_page": call.arguments["start_page"],
                            "end_page": call.arguments["end_page"],
                            "content_layers": ["page_image"],
                        },
                    },
                }
            ],
        }
    ],
)

print(turn2.output_text)

That structure is Google's own documented example for "slice and inspect files in function responses," which states that tools can return sliced pages, spreadsheet ranges, or media clips inside a top-level function_result using the same processing and resolution fields, and that the model receives page counts and worksheet names automatically so it can request narrower ranges on later turns.[5] The result array accepts multiple content blocks, so a tool can return a text status line plus the sliced document, or two page ranges from different files, in one response.

Two implementation notes for this pattern:

  1. Validate the arguments in your tool, not in the prompt. The model will happily ask for start_page: 0 or an end_page below start_page. 0 or less returns INVALID_ARGUMENT, end_page below start_page is rejected, and a range past the end of the file returns an empty slice — which looks like a model failure but is a silent empty result. Clamp in the tool and return a text block explaining the correction.[2]
  2. Cap the range size. A model that asks for pages 1–400 has reconstructed the problem you were trying to solve. Enforce a maximum page count per call in the tool and return {"error": "range too large, max 8 pages"} as text.

A prompt that produces cheap slices

The tool gives you the mechanics; the system prompt gives you the policy. Here is a starting template built around the documented rules (not run-tested against a live API):

You are answering questions about service_manual.pdf using the inspect_document_pages tool.

Rules:
1. First, skim with content_layers ["page_text"] across the whole document to locate relevant pages.
2. Then call inspect_document_pages with at most 4 pages at a time, using page_image only when the answer depends on a diagram, chart, or layout.
3. If a skim returns no match, say so and name the pages you checked. Do not request the full document.
4. Never request a page range you have already read in this conversation.
5. When you cite a figure, name the page number you read it from.

Rule 2 is what keeps token spend down without a cost model in the loop; rule 4 is what prevents the loop where an agent re-reads page 1 on every turn.

Token arithmetic you can trust

Google's documentation is consistent on PDF page rates, but publishes two different sets of per-frame video and per-second audio rates across pages:

SourcePDF pageVideo frame (per frame)Audio (per second)Video + audio (1 FPS combined)
Document understanding, "Tokens and billing"280 low / 560 medium / 1,120 high———
Media resolution, token-count table (Gemini 4/3)280 / 560 / 1,120 (+ native text)70 (low/medium), 280 (high)25—
Video understanding, technical details—66 (low), 258 (otherwise)32~100 (low) / ~300 (high)
Token counting guide——32~100 (default) / ~300 (high); overview also lists 263/s

The ~100/s and ~300/s figures in the video and token guides are frame + audio combined at 1 FPS (66 + 32 ≈ 100, 258 + 32 ≈ 300), not frame-only rates. The genuine disagreement is between Media Resolution (70/280 per frame, 25/s audio) and Video Understanding / Tokens (66/258 per frame, 32/s audio).[3][4][6]

Practical consequences:

  • Treat per-frame and per-second constants as estimates and do not hard-code them into a customer-facing cost calculator without measuring.
  • Measure slices with interaction.usage after the call (and usage.input_tokens_by_modality for modality breakdown). The usage object reports total_input_tokens, total_output_tokens, total_thought_tokens, total_cached_tokens, and total_tool_use_tokens; for agentic video, loaded content lands in total_tool_use_tokens and navigation reasoning in total_thought_tokens. (client.models.count_tokens uses the GenerateContent contents shape for whole-file estimates rather than Interactions processing slice blocks.)[2][6]
  • The percentages you actually care about — slice versus whole file — come out of your own two measurements, not out of this table.

The partner numbers, labeled

The launch post cites two partners. Both are quoted from the partners themselves, in a vendor announcement, with no published methodology — document size, page count, resolution, and model are not stated.[1]

  • Vercel: "Skimming a document page for text extraction used 14x fewer tokens than rendering the whole PDF — focusing on what is relevant and reducing token spend for users."
  • LiteLLM: slicing "cut prompt tokens by 67% for a PDF and 33% for a workbook," and the controls work "through LiteLLM's Gemini routes with no extra setup."

Treat these as directional and partner-reported, not as benchmarks. The 14x figure is a text-versus-image comparison on one document shape — a text layer at 280ish tokens per page against a page image at 560–1,120 — so the direction is exactly what the billing model predicts. The 67% PDF reduction is in the same family. The 33% workbook number is smaller because the default spreadsheet path already sends values and formulas rather than rendered pages, which leaves less room to cut.

Your own ratio depends on how dense your documents are and how many pages you actually need to look at. In a locating-then-reading workflow the win usually comes from the ratio of skimmed pages to zoomed pages, not from the per-page rate.

Failure modes and defaults that cost you

SymptomCauseFix
Token bill looks like a full-document renderprocessing omitted on a document or slide deck; Gemini 4 defaults to page_image at medium, ~560 tokens/pageSet content_layers: ["page_text"] for skims
Spreadsheet request pulls every tabspreadsheet_options omitted; default is all sheets, values + formulas + sheet namesSet sheet_index and visible_cells
400 INVALID_ARGUMENT on pagesstart_page of 0 or negative, or end_page below start_pageClamp to 1 and to start_page
Empty answer, no errorPage range starts past the end of the file → empty sliceCompare against the page count the model reports, or clamp to your known total
Video clip fails or misses the windowstart_offset past video length (400 INVALID_ARGUMENT), end_offset clamped silently, or fps outside (0, 24]Use second strings ("1200s"), clamp offsets to duration, and assert 0 < fps <= 24
Chart description is vaguepage_text only on a page whose content is a rendered imageRe-request that page with page_image at high
Model ignores the tool resultDocument block sent outside a top-level function_result, or call_id mismatchMatch call_id to the function_call step ID exactly
48-hour surpriseUploaded file expired between turnsFiles API storage is 48 hours; re-upload and rebuild the URI

The default-behavior rows are the expensive ones. Nothing errors when you forget processing — you just pay for page images at medium resolution across the whole file, which is the pattern this feature was built to replace.[1][2]

When not to slice

Slicing is a retrieval strategy, and retrieval is the wrong answer when the question genuinely needs the whole corpus in view. If you are doing one long comparative pass over a document set — the patterns in Large Document Analysis — a single full-context request with context caching can be cheaper and simpler than orchestrating sixty tool calls, because the cache absorbs the repeated prefix.

Slice when the answer lives in a small number of pages and you can cheaply find out which. Don't slice when the task is "summarize everything" or when the retrieval step costs more reasoning than the reading step would have.

What I verified

The request shapes, field semantics, defaults, limits, and error behavior on this page come from Google's published documentation, read on 2026-11-27: the launch post, the document understanding page, the media resolution and token counting pages, the video understanding page, and the function calling page's "slice and inspect files in function responses" section. I did not execute the requests against a live API key in this environment, so the snippets are documentation-faithful rather than run-tested here.

Two things to check yourself before adopting:

  1. Run one skim and one zoom on your own document and read interaction.usage. That settles the actual token ratio for your media mix, especially for video and audio where the docs list two different rates.
  2. Confirm your installed google-genai SDK version exposes client.interactions.create and accepts the documented processing block shapes.

Sources

[1] https://blog.google/innovation-and-ai/technology/developers-tools/file-slicing-controls/ — Introducing file slicing controls in the Gemini API. Launch post, partner quotes. [2] https://aistudio.google.com/docs/document-processing — Document understanding. Page and spreadsheet options, Office MIME types, defaults, limits, billing. [3] https://aistudio.google.com/docs/media-resolution — Media resolution. Per-content-item resolution, token-count table, PDF recommendation. [4] https://aistudio.google.com/docs/video-understanding — Video understanding. Clipping, fps, content layers, agentic mode, token details. [5] https://aistudio.google.com/docs/function-calling — Function calling with the Gemini API. Multimodal function responses and "slice and inspect files in function responses." [6] https://aistudio.google.com/docs/tokens — Understand and count tokens. Usage fields, video tokens by processing mode, audio rate. [7] https://aistudio.google.com/docs/audio — Audio understanding. Clipping intervals, audio technical details.