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
| Parameter | Type | Description | Required |
|---|---|---|---|
page_number | int | 1-based page number. For image-type files, must be 1. | Yes |
file_id | str | UUID of the source file. Same value returned in citations[].file_id from ask. | Yes |
max_width | int | None | Pixel width cap. Clamped to 300-1600. Default: 900. | No |
timeout | float | Request timeout in seconds | No |
Supported file types
| Type | Extensions | Notes |
|---|---|---|
| PDFs | pdf | Any 1-based page number. |
| Images | png, jpg, jpeg, webp, gif, etc. | page_number must be 1. |
| Office documents | doc, docx, ppt, pptx, odt | Rendered from the auto-converted PDF. |
NotFoundError.
Response
| Property | Type | Description |
|---|---|---|
file_id | str | UUID of the source file. |
file_name | str | None | Display name of the source file. |
page_number | int | 1-based page number that was rendered. |
mime_type | str | MIME type of the encoded image (always "image/png"). |
width | int | None | Pixel width of the rendered image. |
height | int | None | Pixel height of the rendered image. |
image_base64 | str | Base64-encoded PNG image bytes. |
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
