Skip to main content

Gemini Multimodal File Inspection

Since v1.80.11

Gemini Multimodal File Inspection allows you to send just a portion of a file to the model: a page range of a PDF or Office document, a slide range of a presentation, a worksheet or cell range of a workbook, or a time segment of an audio or video file. Gemini can also natively read Microsoft Office and OpenDocument files and only charges for the tokens in the slice you send.

Official Gemini document processing documentation

Supported routes​

LiteLLM proxy just passes the slice fields through unchanged on the routes that use Gemini's own request format. Write the request out exactly as Google specify and point it at the proxy.

RouteProxy pathSlicing fields
generateContent/v1beta/models/{model}:generateContent and :streamGenerateContentdocumentMetadata, spreadsheetMetadata, videoMetadata, audioMetadata, mediaResolution on a fileData part
Interactions/v1beta/interactionsprocessing on a document, video or audio input block
Google AI Studio passthrough/gemini/v1beta/...Either of the above, it depends on which Google endpoint you're calling

Each route returns the same input token count as a direct call to Google and LiteLLM calculates spend from that usage. The examples on this page were all run against LiteLLM v1.110.2.

Slicing through the OpenAI compatible /v1/chat/completions route is not covered on this page. Use one of the routes listed above.

Setup​

Add a Gemini model to your proxy config and get the proxy going.

config.yaml
model_list:
- model_name: gemini-4-hydrogen
litellm_params:
model: gemini/gemini-4-hydrogen
api_key: os.environ/GEMINI_API_KEY
litellm --config config.yaml

Upload the file via the Gemini Files API and use the returned file URI in the examples below. Google state that slicing works on Gemini 3 and Gemini 4 models.

Slice pages or slides​

Use these fields for PDFs (.pdf), documents (.docx, .doc, .dotx, .odt) and presentations (.pptx, .ppt, .odp). Pages and slides are 1-indexed and both ends of the range are inclusive.

curl -X POST "http://localhost:4000/v1beta/models/gemini-4-hydrogen:generateContent" \
-H "x-goog-api-key: $LITELLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"role": "user",
"parts": [
{
"fileData": {
"fileUri": "https://generativelanguage.googleapis.com/v1beta/files/FILE_ID",
"mimeType": "application/pdf"
},
"documentMetadata": {
"startPage": 3,
"endPage": 4,
"contentLayers": ["PAGE_IMAGE"]
},
"mediaResolution": {"level": "MEDIA_RESOLUTION_HIGH"}
},
{"text": "Summarize the chart and footnotes on pages 3 and 4."}
]
}]
}'
generateContentInteractionsMeaning
documentMetadata.startPageprocessing.page_options.start_pageFirst page or slide to send
documentMetadata.endPageprocessing.page_options.end_pageLast page or slide to send
documentMetadata.contentLayersprocessing.page_options.content_layersPAGE_IMAGE / page_image (rendered pages), PAGE_TEXT / page_text (extracted text), or both
mediaResolution.levelresolution on the document blockDetail level of the rendered page images

For an Office file, change the MIME type and leave the fields as they are. A .pptx deck uses application/vnd.openxmlformats-officedocument.presentationml.presentation and startPage/endPage select the slides.

Slice a worksheet or cell range​

Use these fields for spreadsheets (.xlsx, .xls, .ods). sheetIndex is the 1-indexed position of the worksheet in tab order and visibleCells is an A1 cell or range.

curl -X POST "http://localhost:4000/v1beta/models/gemini-4-hydrogen:generateContent" \
-H "x-goog-api-key: $LITELLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"role": "user",
"parts": [
{
"fileData": {
"fileUri": "https://generativelanguage.googleapis.com/v1beta/files/WORKBOOK_FILE_ID",
"mimeType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
},
"spreadsheetMetadata": {
"sheetIndex": 2,
"visibleCells": "A1:H50",
"contentLayers": ["DATA", "FORMULAS"]
}
},
{"text": "List the formulas in this range and what each one computes."}
]
}]
}'
generateContentInteractionsMeaning
spreadsheetMetadata.sheetIndexprocessing.spreadsheet_options.sheet_indexWorksheet to send. Omit it to send every sheet
spreadsheetMetadata.visibleCellsprocessing.spreadsheet_options.visible_cellsCell or range to crop to, such as A1:H50
spreadsheetMetadata.contentLayersprocessing.spreadsheet_options.content_layersDATA / data (cell values), FORMULAS / formulas (raw formulas), VISUAL / visual (rendered snapshot)

Slice a video or audio segment​

Offsets are strings of seconds ending in s (e.g. "10s", "10.5s").

curl -X POST "http://localhost:4000/v1beta/models/gemini-4-hydrogen:generateContent" \
-H "x-goog-api-key: $LITELLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"role": "user",
"parts": [
{
"fileData": {
"fileUri": "https://generativelanguage.googleapis.com/v1beta/files/VIDEO_FILE_ID",
"mimeType": "video/mp4"
},
"videoMetadata": {"startOffset": "10s", "endOffset": "20s", "fps": 1}
},
{"text": "Describe what happens in this segment."}
]
}]
}'

For audio: set mimeType to the audio type (e.g. audio/mpeg) and replace videoMetadata with "audioMetadata": {"startOffset": "60s", "endOffset": "90s"}.

Token usage and cost​

Gemini only bills for the slice that it sends to the model and the proxy reports the same input token count as a direct call. The table shows promptTokenCount for the same requests made to Google directly and via LiteLLM v1.110.2 on gemini-4-hydrogen. All three proxy routes returned the same count as the direct call.

FileRequestInput tokensChange
6-page PDFWhole file5840
6-page PDFPages 3 to 4114780% fewer
3-sheet workbookWhole file1008
3-sheet workbookSheet 239161% fewer
3-sheet workbookSheet 1, cells A1:B317383% fewer
3-slide deck (.pptx)Whole file1704
3-slide deck (.pptx)Slide 2, text layer7396% fewer
60-second videoWhole file6159
60-second videoSeconds 10 to 20105983% fewer
120-second audioWhole file3879
120-second audioSeconds 60 to 9099974% fewer

Savings are file dependent. LiteLLM tracks the spend on these calls from the usage that Gemini returns and the proxy then sends the cost back in the x-litellm-response-cost response header.

Limits​

Google apply their file limits to the entire uploaded file (even if you've sliced it up): 50 MB per file, 1,000 pages per PDF, 2,000 pages or slides per Office/OpenDocument file and 50,000 cells per sheet. Full list of formats and options is at Google's documentation.

LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →