Referência da API

PDF generation

HTML in — yours, or written by the model from an instruction — rendered PDF out.

POST/v1/documents/generate

Two mutually exclusive modes. Sending both fields, or neither, returns 400.

htmlstringOpcional

Direct mode. You already have finished HTML (from an earlier chat response, for example) and just want it rendered. No inference involved — this call doesn't touch a model, works even while your stack's infrastructure is paused for inactivity, and doesn't count against your token quota.

userstringOpcional

Instruction mode. Describe what the document should contain; the gateway asks the model for HTML and renders the result — one request instead of two.

systemstringOpcional

Only with user. Replaces your stack's configured system prompt for this request.

max_tokensintegerOpcionalPadrão: 8000

Only with user. Ceiling on the model's response, up to 16000.

Direct mode

curl -X POST "https://api.trystac.com/v1/documents/generate" \
  -H "Authorization: Bearer $STAC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"html": "<h1>Report</h1><p>already-rendered content</p>"}' \
  -o report.pdf

Instruction mode

curl -X POST "https://api.trystac.com/v1/documents/generate" \
  -H "Authorization: Bearer $STAC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"user": "A sales report for August, with one table per region."}' \
  -o report.pdf

The response, in both modes, is the PDF as bytes (Content-Type: application/pdf) — not JSON, save it directly to a file.

HTML must be self-contained

Embed images and fonts as data: URIs instead:

html
<img src="data:image/png;base64,iVBORw0KG...">

In instruction mode this rule is already built into the prompt the gateway sends the model. In direct mode, if your HTML came from a separate chat response with a real image URL, either ask the model (via your prompt) to inline it as a data URI, or convert it yourself before calling this endpoint.

Errors

StatusMeaning
400html and user both sent (or neither), HTML couldn't be rendered, or (instruction mode) the model's response was truncated
413HTML (sent, or model-generated) or resulting PDF page count over the plan's limit
422max_tokens outside the accepted range (instruction mode only)
429Too many generations in flight right now — the server fails fast rather than queuing; retry shortly
502(instruction mode) failed to call the model

Limits

LimitGoProMaxEnterprise
HTML size (sent, or model-generated)2 MB5 MB8 MBCustom
Pages in the resulting PDF205075Custom

The page ceiling is checked after layout but before the final PDF bytes are produced, so an attempt to exceed it fails without extra render cost. In instruction mode, HTML returned by the model passes through the same size check as direct mode — nothing guarantees the model respected the instruction.