LiteLLM cut Gemini API input tokens by 67% on one PDF
Edited and reviewed by AI Ping Editorial Team
Key points
- Google documented file slicing on November 18.
- LiteLLM also published token counts for a three-sheet workbook read in full, a single sheet and a six-cell range.
- Upload limits cover the entire source document.
On November 23, Google published results from LiteLLM, which connects applications to AI models. Reading selected parts of files with the Gemini API cut input tokens by 67% on one PDF and 33% on one workbook in LiteLLM’s tests. Input tokens measure what the model takes in, including text and images.
Google had expanded support for PowerPoint and OpenDocument files on November 5. Its November 18 release notes described selecting ranges within those files. An application handling a report can send different parts of the same source as a reader’s questions move from one page to another. Google’s example scans a quarterly report as text to locate a revenue chart, then reads page three at high resolution for the chart and footnotes.
Vercel compared extracting text to skim one page with rendering an entire PDF. The skim used about one fourteenth as many tokens. These comparisons concern the input. Gemini reports the tokens it uses to produce an answer separately.
Reading the values or the formulas
An app can choose what to read from a block of spreadsheet cells. Values give the calculated results. Formulas reveal the calculation. A rendered image preserves the chart or table layout.
LiteLLM’s technical guide gives a worked example on Gemini 4 Hydrogen. A workbook with three tabs took 1,008 input tokens in full. The second sheet alone took 391. Six cells on the first sheet, A1 through B3, took 173. LiteLLM says the counts matched whether it sent those requests to Google directly or through any of three routes in version 1.110.2 of its gateway.
A tool that retrieves files can also identify what to inspect. Google’s developer example retrieves a quarterly sales workbook and a store walkthrough video. When a tool returns a file, the model receives metadata such as page counts and worksheet names. It can use those details to request a narrower range on a later turn.
From a timestamp to the frames that matter
A recording can supply a transcript, frames, audio or a combination. Google’s example locates a diagram in a talk by searching the timestamped transcript. A second request samples frames from 7:00 to 7:45 at two frames a second to read the diagram. The transcript is billed as text. Frame usage depends on the sampling rate and resolution.
For an audio-only file, the start and end times determine how much sound is processed. One example in Google’s guide selects seconds 60 through 150, a 90-second passage. Leaving the end open runs from the chosen start to the end of the recording. Audio tokens are counted for the selected duration. If the requested end falls past the recording, Gemini stops at the actual end. A start point beyond the recording produces an error.
A developer can count the input for a whole-file request and for a narrower one before generating either answer. The count includes the question and its attachments. The response then reports input and output separately, distinguishing a change in file selection from a change in answer length.
The full document must fit within 50 MB. A PDF can have up to 1,000 pages, and an Office or OpenDocument file up to 2,000 pages or slides. A spreadsheet is limited to 50,000 cells per worksheet.
The Files API gives the application a reference it can reuse across requests. The reader can move to another page or revisit a recording while the upload is available. The application can look up the file’s metadata by name during that period. Google automatically deletes the upload after 48 hours. Developers can delete it earlier.
Sources
- Introducing file slicing controls in the Gemini API — Google
- Release notes – Gemini API — Google AI Studio
- Gemini Multimodal File Inspection with LiteLLM — LiteLLM
- Document understanding — Google AI Studio
- Function calling with the Gemini API — Google AI Studio
- Video understanding — Google AI Studio
- Audio understanding — Google AI Studio
- Files API — Google AI Studio
- Understand and count tokens — Google AI Studio