Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.graphorlm.com/llms.txt

Use this file to discover all available pages before exploring further.

The 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

Sync Method

client.sources.get_page_screenshot()

Async Method

await client.sources.get_page_screenshot() (using AsyncGraphor)

Method signature

client.sources.get_page_screenshot(
    page_number: int,                     # Required (path)
    file_id: str,                         # Required
    max_width: int | None = None,
    timeout: float | None = None
) -> SourceGetPageScreenshotResponse

Parameters

ParameterTypeDescriptionRequired
page_numberint1-based page number. For image-type files, must be 1.Yes
file_idstrUUID of the source file. Same value returned in citations[].file_id from ask.Yes
max_widthint | NonePixel width cap. Clamped to 300-1600. Default: 900.No
timeoutfloatRequest timeout in secondsNo

Supported file types

TypeExtensionsNotes
PDFspdfAny 1-based page number.
Imagespng, jpg, jpeg, webp, gif, etc.page_number must be 1.
Office documentsdoc, docx, ppt, pptx, odtRendered from the auto-converted PDF.
Plain-text and other non-visual formats are not supported and will raise NotFoundError.

Response

PropertyTypeDescription
file_idstrUUID of the source file.
file_namestr | NoneDisplay name of the source file.
page_numberint1-based page number that was rendered.
mime_typestrMIME type of the encoded image (always "image/png").
widthint | NonePixel width of the rendered image.
heightint | NonePixel height of the rendered image.
image_base64strBase64-encoded PNG image bytes.

Code examples

Basic — render and save a page

import base64
from graphor import Graphor

client = Graphor()

screenshot = client.sources.get_page_screenshot(
    page_number=42,
    file_id="a1b2c3d4-e5f6-7890-abcd-ef1234567890",
)

png_bytes = base64.b64decode(screenshot.image_base64)
with open("page-42.png", "wb") as f:
    f.write(png_bytes)

print(f"Rendered {screenshot.width}x{screenshot.height} PNG")

Lazy-loading citations from ask

The recommended pattern: call ask, render only the pages the user inspects.
from graphor import Graphor

client = Graphor()

response = client.sources.ask(
    question="What was the revenue in 2025?",
    file_ids=["file_abc123"],
)

print(response.answer)

# When the user hovers/clicks on a [N] marker, fetch the screenshot
def fetch_citation_image(citation):
    return client.sources.get_page_screenshot(
        page_number=citation.page_number,
        file_id=citation.file_id,
        max_width=500,  # smaller for tooltip/popover
    )

# Example: render only the first cited page
if response.citations:
    screenshot = fetch_citation_image(response.citations[0])
    # screenshot.image_base64 → display in <img src="data:image/png;base64,...">

Async usage

import asyncio
from graphor import AsyncGraphor

async def render_pages(file_id: str, pages: list[int]):
    client = AsyncGraphor()
    results = await asyncio.gather(*[
        client.sources.get_page_screenshot(page_number=p, file_id=file_id)
        for p in pages
    ])
    return [r.image_base64 for r in results]

asyncio.run(render_pages("file_abc123", [1, 2, 3]))

Best practices

  1. Lazy-load on user interaction — call this method only when the user hovers, clicks, or expands a citation. Most citations are never inspected.
  2. 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.
  3. Pick max_width for the surface you’re rendering500 for tooltips/popovers, 900 (default) for inline cards, 1200+ only when the user opens a full preview.
  4. Prefer this over include_citation_images=True in ask — 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 use include_citation_images.

Error handling

import graphor
from graphor import Graphor

client = Graphor()

try:
    screenshot = client.sources.get_page_screenshot(
        page_number=42,
        file_id="file_abc123",
    )
except graphor.NotFoundError:
    # File not found, unsupported file type, or invalid page number
    screenshot = None
except graphor.AuthenticationError as e:
    print(f"Invalid API key: {e}")
except graphor.APIStatusError as e:
    print(f"API error (status {e.status_code}): {e}")

Chat

Ask questions and receive grounded answers with citations

List Sources

Discover the file_id values you can pass here