By the Cuelark Team. Feature details come from Google's launch post, the Gemini API docs, and the Vercel AI SDK docs and release notes, all checked on 25 November 2026. We didn't call Gemini. The code ran against a local mock of the Interactions API that records each request, so this is a wiring test. It tells you what your app sends, not how well the model reads your PDF.

On November 23, Google added file slicing controls to the Gemini API. When you pass a PDF, an Office file, a spreadsheet, audio or video, you can now ask for specific pages, cell ranges or time segments, and choose which layer the model gets: extracted text or rendered page images for documents; data, formulas or a visual snapshot for sheets. Google slices the file on its side and bills tokens only for the slice it sends to the model. The same launch added native upload for Word, PowerPoint, Excel and OpenDocument files.

The launch post says slicing works on all Gemini 4 models. The docs say the options work on Gemini 3 and Gemini 4+ models.

The part that matters for a chat app is that slices can go inside a function result. Your tool returns a file URI plus a page range, and the model decides what to look at. According to the docs, the model also gets the file's total page count and worksheet names, so it can ask for more on a later turn.

The Vercel AI SDK added support in @ai-sdk/google 4.0.125 (November 23) and 4.0.126 a day later removed the early-access model IDs from its suggestions, noting that regular IDs like gemini-4-hydrogen work.

Why bother

Per the docs, a page image costs about 280 tokens at low, 560 at medium (the default) and 1,120 at high. Send a 40-page report as images on every turn and that's around 22,400 tokens at the default before anyone asks a question. Google's suggested pattern is to skim as text, then render only the pages with charts or dense layouts at high resolution.

The route

Upload the PDF once with the Files API (ai.files.upload in @google/genai) and pass the URI to the chat. Then give the model one tool:

// app/api/chat/route.ts import { createGoogleGenerativeAI, type GoogleInteractionsFileOptions } from '@ai-sdk/google'; import { streamText, convertToModelMessages, tool, isStepCount, type UIMessage } from 'ai'; import { z } from 'zod'; // GEMINI_BASE_URL is unset in production; our test points it at a local mock. const google = createGoogleGenerativeAI({ baseURL: process.env.GEMINI_BASE_URL }); export async function POST(req: Request) { // fileUri: a Files API URI you got from uploading the PDF once. const { messages, fileUri }: { messages: UIMessage[]; fileUri: string } = await req.json(); const readPages = tool({ description: 'Load pages of the attached PDF. Use detail "text" to skim many pages, ' + 'then "image" for the few pages with charts or tables.', inputSchema: z.object({ startPage: z.number().int().min(1), endPage: z.number().int().min(1), detail: z.enum(['text', 'image']), }), execute: async (input) => { if (input.endPage < input.startPage) throw new Error('endPage must be >= startPage'); if (input.detail === 'image' && input.endPage - input.startPage > 4) { throw new Error('Render at most 5 pages as images per call'); } return input; }, toModelOutput: ({ output }) => ({ type: 'content', value: [ { type: 'file', data: { type: 'url', url: new URL(fileUri) }, mediaType: 'application/pdf', providerOptions: { google: { resolution: output.detail === 'image' ? 'high' : 'low', processing: { type: 'static', pageOptions: { startPage: output.startPage, endPage: output.endPage, contentLayers: [output.detail === 'image' ? 'page_image' : 'page_text'], }, }, } satisfies GoogleInteractionsFileOptions, }, }, ], }), }); const result = streamText({ model: google.interactions('gemini-4-hydrogen'), system: 'Answer from the attached PDF. Skim with text first, then zoom in on specific pages.', messages: await convertToModelMessages(messages), tools: { readPages }, stopWhen: isStepCount(6), }); return result.toUIMessageStreamResponse(); } 

On the client, useChat with new DefaultChatTransport({ api: '/api/chat', body: { fileUri } }) is enough. Each call shows up as a tool-readPages part, so you can render a small "Read pages 12-12 as image" line. It's a handy way to show what the model actually looked at.

What the test showed

We scripted the mock to skim pages 1-40 as text, zoom into page 12 as an image, then answer.

  • The wire format matches the docs. The skim went out as a top-level function_result holding {"type":"document","uri":"…/files/abc123","resolution":"low","processing":{"type":"static","page_options":{"start_page":1,"end_page":40,"content_layers":["page_text"]}}}. The SDK converts camelCase to snake_case for you, and the zoom call carried "resolution":"high" with ["page_image"].
  • Earlier slices are resent. By default the SDK sends the full history on each step and no previous_interaction_id. The three requests carried 0, 1 and 2 document blocks. The skim from step one rides along on every later step. We couldn't measure what that costs without a real key, so check usage on your own account before you assume the skim is a one-time charge.
  • Don't shortcut that with previousInteractionId. We tried passing the last interaction ID in prepareStep to make the SDK trim history. In our mock run, the newest function_result was dropped from the next request, so the model would never see the pages it asked for. Stick with the default unless you've tested your own setup.
  • Bad ranges come back as tool errors. A reversed range, a 40-page image request, or page 0 all went back to the model as function_result with is_error: true, so the request never reached Gemini with bad options. That matters because the docs say a start_page of 0 or less returns 400 INVALID_ARGUMENT.
  • Tools are sent every time. The docs warn that tool declarations aren't stored with the interaction. The SDK included readPages on every request, so that's handled.

Honest limits

  • We didn't run Gemini. Nothing here measures answer quality, latency or real token counts.
  • Text skims aren't free. The docs give per-page numbers for images, not for the page_text layer. Expect it to be cheaper, but check your own usage numbers.
  • File limits still apply to the whole file. That means 50 MB per file, 1,000 pages per PDF, 2,000 pages or slides per Office file and 50,000 cells per sheet, even if you only ask for one page.
  • Edge behavior. Per the docs, a start_page past the end returns an empty slice, while an end_page past the end is clamped. If you get an empty slice back, the model asked for pages that don't exist.
  • Office page numbers follow rendered layout. The AI SDK docs note this, so "page 12" of a Word file may not match what the author sees in their editor.

The same processing object handles spreadsheets (spreadsheetOptions with sheetIndex, visibleCells and data/formulas/visual layers) and audio or video clips, so the tool shape above carries over.

Sources

If you'd rather not build the message list and tool-status rows yourself, Cuelark UI has shadcn-style AI chat components that fit this setup.