TellWorldAI World Archive

Home›Practice›Practice

Practice

Gemini API file slicing: sending only the pages, sheets and ranges you need

The Gemini API's processing field sends only the PDF pages, content layers, spreadsheet tabs or cell ranges you choose, and bills only what is sent. This guide shows how to set each option.

Who this is for and what you will get

This guide is for developers who want to send PDFs, Office files or spreadsheets to Gemini without uploading the whole file every time. After reading it you can use the processing field to pick the pages, content layers, worksheet tabs and cell ranges you need, understand how each choice is billed, and know which parameter to check when a request returns 400 INVALID_ARGUMENT.

What slicing solves

Gemini reads PDFs with native vision, so text, images, diagrams, charts and tables are understood together, and the docs say this works for documents up to 1,000 pages[1]. Many real jobs need only a few pages of a long file. For example, a question about one revenue chart on pages 3 to 7 of a 100-page quarterly report does not need the other 95 pages. Slicing sends only the pages you select, and billing counts only those pages.

Which files can be sliced

PDFs and Word, PowerPoint and OpenDocument presentation or text files are sliced with page_options. Spreadsheets (.xlsx, .xls and .ods) are sliced with spreadsheet_options, by worksheet and cell range[1]. Plain-text formats such as TXT, Markdown and HTML are processed as plain text, so charts and formatting are not kept[1].

Slicing pages with page_options

start_page and end_page are 1-indexed and inclusive. If you set only start_page, end_page defaults to the last page. If end_page is larger than the page count, it is clamped to the last page, and it must not be smaller than start_page[1]. A start_page of zero or less returns 400 INVALID_ARGUMENT, while a value past the last page returns an empty slice[1]. The content_layers field takes page_image for rendered pages, page_text for extracted text, or both. When processing is set, it defaults to page_image only[1].

The request below sends pages 3 to 7 of a PDF, with the page images, and asks one question about them[1]:

uploaded_doc = client.files.upload(file="quarterly_report.pdf")

interaction = client.interactions.create(
    model="gemini-4-hydrogen",
    input=[
        {
            "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"],
                },
            },
        },

Set resolution on the outer document block. It accepts low, medium or high, and medium is the default[1].

Slicing spreadsheets with spreadsheet_options

sheet_index is the position of the worksheet in tab order, counted from 1. If you leave it out, every sheet is ingested, up to 50,000 cells per sheet. visible_cells takes an A1 cell or range such as A1:G40 and crops all selected layers to that region. content_layers takes data for evaluated values, formulas for the raw formulas and visual for a rendered snapshot that shows charts and layout. The default is data and formulas[1]. The outer resolution matters only when visual is enabled, and its default is medium[1].

The request below reads sheet 2, limited to cells A1 to H50, with all three layers, to check formulas and a chart[1]:

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

interaction = 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"],
                },
            },
        },

Token counts and resolution

Gemini renders PDF and Office pages to 2-megapixel images at 288 DPI while preserving the aspect ratio. Input pixel size does not change the cost, and resolution is the setting that controls the token budget[1]. For Gemini 3 and Gemini 4+ models the approximate cost is 280 tokens per page at low, 560 at medium and 1,120 at high[1]. Gemini 2.5 models use a flat 258 tokens per page[1].

Without processing options, embedded PDF text is extracted along with the page images at no extra token charge[1]. With processing options, Gemini bills only the selected pages, sheets and content layers that it receives[1].

Limits

Each file can be up to 50 MB. A PDF can have up to 1,000 pages, and an Office or OpenDocument file up to 2,000 pages or slides. These limits apply to the full uploaded file, even when you slice it[1]. Spreadsheets are limited to 50,000 cells per sheet[1].

Common problems

  • A 400 INVALID_ARGUMENT error: check that start_page is greater than zero, that sheet_index is within the number of sheets, and that end_page is not smaller than start_page[1].
  • Answers are wrong on a large file: the docs suggest scanning a large Office file with page_text first, then requesting page_image at high resolution only for pages with charts or dense layouts[1].
  • The same file is used across many turns: upload it with the Files API instead of passing it inline each time, which reduces latency and bandwidth[1].
  • Poor scans: rotate pages upright, and avoid blurry or low-contrast pages. When you send a single page, put the text prompt after the document[1].

Next step

The full parameter reference and the Files API details are on Google's document understanding page[1].

Sources

  1. 1
    Document understandingGoogle AI for Developers

Cite this page: Gemini API file slicing: sending only the pages, sheets and ranges you need. TellWorld, https://www.tellworld.net/practice/practice-gemini-file-slicing. Updated 2026-11-24

Related news

View all