get_page_screenshot method renders one page of a source file (PDF, image, or Office document) as a base64-encoded PNG. It is the recommended way to display visual previews for citations returned by ask — call it lazily, only when the user actually wants to inspect a citation.
Method overview
- Python
- TypeScript
Sync Method
client.sources.get_page_screenshot()Async Method
await client.sources.get_page_screenshot() (using AsyncGraphor)Method signature
- Python
- TypeScript
Parameters
- Python
- TypeScript
Supported file types
Plain-text and other non-visual formats are not supported and will raise
NotFoundError.
Response
Code examples
Basic — render and save a page
- Python
- TypeScript
Lazy-loading citations from ask
The recommended pattern: call ask, render only the pages the user inspects.
- Python
- TypeScript
Async usage
- Python
- TypeScript
Best practices
- Lazy-load on user interaction — call this method only when the user hovers, clicks, or expands a citation. Most citations are never inspected.
- Cache by
(file_id, page_number)— the response is deterministic for a given key. Cache the base64 string in memory for the duration of the session to avoid re-rendering. - Pick
max_widthfor the surface you’re rendering —500for tooltips/popovers,900(default) for inline cards,1200+ only when the user opens a full preview. - Prefer this over
include_citation_images=Trueinask— embedding base64 inline bloats the JSON payload by hundreds of KB per cited page and runs all renders synchronously before the answer returns. See When to useinclude_citation_images.
Error handling
- Python
- TypeScript
Related
Chat
Ask questions and receive grounded answers with citations
List Sources
Discover the
file_id values you can pass here
