Back to Articles

Save Costs: How to Use File Slicing in Gemini API

November 25, 2026587

Cutting Costs: How to Work with Specific File Segments in the Gemini API

One of the biggest challenges in working with Large Language Models (LLMs) is managing the Context Window. Until now, when we sent a file to the Gemini API – whether it was a long PDF, a dense presentation, or a complex spreadsheet – the model was required to process the entire file. This not only consumed valuable processing time but also cost us unnecessary tokens for information we didn't always need.

Google recently launched a critical new capability in the Gemini API: File Slicing Controls. This capability is a game changer, allowing developers to define exactly which parts of a file the model will load and process on the server side. This means direct cost savings and a significant improvement in the response speed of your applications.

What does this mean in practice?

Instead of "feeding" the model a 100-page document when you only need information from page 12, you can now instruct the API to focus exclusively on the relevant page range. This capability supports a wide range of formats, including:

  • •Documents and Presentations: PDF, Office files (Word, PowerPoint), and OpenDocument formats. You can select specific page ranges.
  • •Spreadsheets: Control over tabs (Worksheets) and specific cell ranges within the sheet.
  • •Media: Slicing precise time segments from audio and video files, including control over the frame rate (FPS).

Why is this important for developers?

Beyond the obvious financial savings – since you only pay for the tokens the model actually scans – there is a significant architectural advantage here. Previously, to perform such operations, developers had to use external tools (like PDF libraries or word processors) to "deconstruct" files before sending them to the API. This created load on your local servers and complicated the code.

Now, everything happens on Google's server side. You upload the file once to the Files API, and from that moment on, you can perform different "slices" on it in various requests without having to re-upload it.

Real-world example: Smart scanning

Imagine a process where you want to find a revenue graph within a long quarterly report. Instead of sending the entire report, you can perform "skimming" of the text to locate the correct page, and only then ask the model to "zoom in" on that specific page at high resolution to analyze the graph. The result? A workflow that is significantly faster, more efficient, and cheaper.

Summary and Conclusions

The ability to perform slicing is another step by Google to make the Gemini API a more professional and precise tool for developers. If you are building AI agents or RAG systems, this capability is a must-have tool in your toolkit to optimize resource consumption.

For more information on implementing this capability in your code, it is recommended to review the official documentation:

Thanks to Spotlight by Daniel Trabelsi by Daniel Trabelsi for sharing and inspiring this article.

Join the channel
#Gemini API#AI#File Slicing#data processing#cost optimization#LLM#software development#Google AI