Skip to main content
Back

Google's Gemini API Cuts Token Costs by 93% With File Slicing

Gemini API now lets you upload a file once and surgically request only the pages, cells, or timestamps you need, billing tokens solely for inspected slices.

  • Gemini API adds native file slicing: request specific pages, cells, timestamps, or frames server-side.
  • Native upload support now covers PDFs plus Microsoft Office and OpenDocument formats (docs, slides, spreadsheets).
  • Upload once via the Files API, reuse the URI across turns, pay only for inspected slices.
  • Vercel saw 14x fewer tokens skimming a PDF as text; LiteLLM cut prompt tokens 67% on a PDF.
  • Removes need for local ffmpeg, LibreOffice, or PDF renderers inside agent harnesses.
  • Live now across all Gemini 4 models in Google AI Studio and Vertex AI.

Google has added native file-slicing controls to the Gemini API, allowing applications to send selected portions of uploaded files to a model. Google’s announcement covers documents, spreadsheets, audio, and video. The release also adds direct uploads for Microsoft Office and OpenDocument formats.

Applications can target specific pages, spreadsheet cells, media intervals, and content layers. Gemini processes the requested slice on Google’s servers, keeping unrelated material out of the context window and billing input tokens for the content the model loads.

How slicing simplifies agent architecture

Document-heavy agents often carry a separate media pipeline alongside the model integration. Whole-file ingestion can require LibreOffice, PDF renderers, ffmpeg, temporary storage, and isolated execution environments to extract a single page or video segment.

Server-side slicing moves that work into Gemini. An application uploads a file through the Files API, reuses its URI, and specifies the required slice with each request. Gemini then renders and tokenizes that material in the format expected by the model.

Skim cheaply, then zoom in

A typical agent can split file analysis into four steps:

  1. Upload the file once and retain its Files API URI.
  2. Request extracted text, transcripts, or low-resolution previews to locate relevant material.
  3. Identify the pages, cells, frames, or time intervals needed for the task.
  4. Load those sections at higher resolution or with additional content layers.

Tool-enabled agents can specify a file slice inside a function response and reuse the same URI across turns. For example, an agent can run a low-cost page_text pass to find a revenue chart, then request page_image at high resolution for that page.

One URI, four media types

Google says native slicing works across all Gemini 4 models. Existing file-size and page limits apply to the complete upload before any slice is selected.

Available controls by media type
Media Slicing controls
Documents and presentations Select pages with start_page and end_page, choose low, medium, or high resolution, and request page_text or page_image.
Spreadsheets Select a tab with sheet_index, set a visible_cells range, choose low, medium, or high resolution, and request data, formulas, or visuals.
Video Set start_offset and end_offset, adjust frame rate and resolution, and request transcripts, frames, or audio.
Audio Set start_offset and end_offset to load a specific interval.

Calls that omit processing options retain broad defaults. Documents and presentations use layout-preserving page images, while spreadsheets include evaluated values, formulas, and sheet names from every tab. Applications seeking token savings must specify the relevant slices or content layers.

One upload, two passes

With an initialized client, a Python workflow can upload a document once, locate the relevant page with extracted text, and reload that page as a high-resolution image:

doc = client.files.upload(file="quarterly_report.docx")

# Extract text to locate the relevant page.
skim = client.interactions.create(
    model="gemini-4-hydrogen",
    input=[
        {
            "type": "document",
            "uri": doc.uri,
            "processing": {
                "type": "static",
                "page_options": {
                    "content_layers": ["page_text"]
                },
            },
        },
        {
            "type": "text",
            "text": "Which page has the revenue bridge chart?",
        },
    ],
)

# Reload page 3 as a high-resolution image.
detail = client.interactions.create(
    model="gemini-4-neon",
    input=[
        {
            "type": "document",
            "uri": doc.uri,
            "resolution": "high",
            "processing": {
                "type": "static",
                "page_options": {
                    "start_page": 3,
                    "end_page": 3,
                    "content_layers": ["page_image"],
                },
            },
        },
        {
            "type": "text",
            "text": "Read the chart and footnotes on page 3.",
        },
    ],
)

Early tests show lower token use

Vercel reported that extracting text from a document page consumed one-fourteenth as many tokens as rendering the complete PDF. LiteLLM reported prompt-token reductions of 67% for a PDF and 33% for a workbook when routing Gemini traffic with slicing enabled.

Those figures come from partner workloads, so savings will vary with file structure, selected layers, resolution, and the proportion of each file loaded.

Launch scope and hard limits

Google says native slicing, content-layer controls, and expanded file-format support are available now through the Gemini API in Google AI Studio and its business offering. Requests use the standard token rate for the content loaded by the model.

The complete file must still satisfy existing Files API size and page caps. Slicing reduces model input and context use after upload. For agents that process long PDFs, multi-tab workbooks, or lengthy recordings, it can also remove client-side conversion jobs and constrain each request to the material required for the task.