PDF Citations through the API

,

I noticed that on the Gemini web UI (2.5 flash and pro), if you load in a PDF and asking some questions about it, you get back an answer that includes reference links to pages from the PDF.

I’d like to access this feature through the API but cannot find the relevant metadata in the API response. I inspected response.candidates but it seems to only reference external web links, not the uploaded PDF links. Can anyone help point me in the right direction on this?

You need to prompt it to return the page numbers as part of the response, or a tool call. With those, you can easily link to the page within the PDF file via the likes of pdf.js or named destinations (anchors created within the pdf accessible via the query string)

I have tried this but Gemini gets confused and mixes ups logical and displayed page numbers. I don’t think your response highlights what Gemini’s web UI is doing.

You can’t find it in the API because it doesn’t exist on an API level. It’s all done with system instructions (temperature / topP/K influence) and quite likely some server-side pre-processing via pdfplumber or pdf.js, so it can feed the model accurate page mappings as part of the context.