API Documentation

REST API base URL: https://www.agent-gen.com/apiReplace YOUR_API_KEY with a dashboard key

Quickstart

Generate your first image in under a minute. Sign up, buy tokens, grab your API key, and make your first request.

curl
curl -X POST https://www.agent-gen.com/api/v1/generate/image \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1 style=\"font-family:sans-serif;color:#4f46e5\">Hello!</h1>",
    "viewport_width": 1200,
    "format": "png"
  }'

Response

{
  "url": "https://cdn.agent-gen.com/output/abc123.png",
  "width": 1200,
  "height": 84,
  "format": "png",
  "tokens_used": 1,
  "request_id": "v7k9x2..."
}

Free Tier

The generate/image and generate/pdf endpoints work without an API key — no sign-up required. This lets you demo generation to your users or admins instantly.

Watermark

A small agent-gen.com badge is overlaid on all free-tier output.

Rate limit

1 request per 60 seconds per IP. Exceeding returns 429.

PDF limit

Single-page PDFs only. Multi-page requires an API key.

curl
# No API key required — a watermark is added automatically
curl -X POST https://www.agent-gen.com/api/v1/generate/image \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1 style=\"font-family:sans-serif;color:#4f46e5\">Hello!</h1>",
    "viewport_width": 1200,
    "format": "png"
  }'

Response

{
  "url": "https://cdn.agent-gen.com/output/abc123.png",
  "watermarked": true,
  "format": "png",
  "width": 1200,
  "height": 84,
  "request_id": "v7k9x2..."
}

To remove the watermark and get higher throughput, create an API key.

Authentication

Authenticated requests use an X-API-Key header. This is required for /v1/balance, /v1/upload/temp, and multi-page PDFs. For generate endpoints it is optional — omitting it uses the free tier (watermarked, rate-limited). Generate keys from the dashboard.

HTTP Header
X-API-Key: YOUR_API_KEY

401 Unauthorized

Missing or invalid API key.

402 Payment Required

Insufficient token balance.

Generate Image

POST /v1/generate/image — costs 1 token

Render any HTML string to PNG, JPEG, or WebP using headless Chrome. AgentGen infers output dimensions from the rendered HTML. Use viewport hints to control layout, or pass a selector to capture a specific element.

curl
curl -X POST https://www.agent-gen.com/api/v1/generate/image \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1 style=\"font-family:sans-serif;color:#4f46e5\">Hello!</h1>",
    "viewport_width": 1200,
    "format": "png"
  }'
Request body
FieldTypeDescription
htmlstringHTML content to render (max 500 KB)
viewport_widthintegerViewport width used for layout before capture, 1–5000 (default: 1200)
viewport_heightintegerViewport height used for layout before capture, 1–5000 (default: 800)
selectorstringOptional CSS selector. If provided, captures that element instead of the full document
format'png' | 'jpeg' | 'webp'Output format (default: png)
device_scale_factornumberDevice pixel ratio, 1–3 (default: 2)

Generate PDF

POST /v1/generate/pdf — costs 2 tokens per page

Generate pixel-perfect PDFs from HTML. By default AgentGen prefers CSS @page size from the document and falls back to a named format when CSS does not define one.

curl
curl -X POST https://www.agent-gen.com/api/v1/generate/pdf \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "html": "<h1>Invoice #001</h1><p>Amount due: $99.00</p>",
    "page_size_source": "css",
    "format": "A4",
    "margin": { "top": "20mm", "bottom": "20mm", "left": "15mm", "right": "15mm" },
    "optimize": true
  }'
Request body
FieldTypeDescription
htmlstringHTML content to render (max 500 KB)
page_size_source'css' | 'format'Prefer CSS @page size or fallback format (default: css)
format'A4' | 'Letter' | 'A3' | 'Legal'Fallback paper size when CSS does not define one (default: A4)
marginobjecttop/bottom/left/right margins (CSS units)
landscapebooleanLandscape orientation (default: false)
print_backgroundbooleanRender CSS backgrounds (default: true)
optimizebooleanShrink the final PDF with a post-processing pass (default: true)
pagesarrayMulti-page: array of page objects (requires API key, max 100)

Upload Temp File

POST /v1/upload/temp — free

Upload images or assets to use inside your HTML templates. Files are stored on Cloudflare R2 and auto-expire after 24 hours. Max 10 MB.

curl
curl -X POST https://www.agent-gen.com/api/v1/upload/temp \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "[email protected]"

Compress Image

POST /v1/compress/image — costs 1 token

Compress an uploaded image using Sharp. Accepts JPEG, PNG, WebP, AVIF, GIF, or TIFF. Choose an output format and a quality preset — the response includes the CDN URL plus before/after size stats. Requires an API key; no free tier.

curl
curl -X POST https://www.agent-gen.com/api/v1/compress/image \
  -H "X-API-Key: YOUR_API_KEY" \
  -F "[email protected]" \
  -F "format=webp" \
  -F "mode=balanced"

Response

{
  "url": "https://cdn.agent-gen.com/out/abc123.webp",
  "format": "webp",
  "mode": "balanced",
  "original_size": 450000,
  "compressed_size": 87000,
  "savings_percent": 80.7,
  "width": 1920,
  "height": 1080,
  "tokens_used": 1
}
Form fields
FieldTypeDescription
filebinary (required)Image to compress. Max 20 MB. Accepted: JPEG, PNG, WebP, AVIF, GIF, TIFF.
format'jpeg' | 'png' | 'webp' | 'avif' | 'tiff'Output format. Defaults to the input format. GIF always converts to WebP.
mode'lossless' | 'balanced' | 'aggressive'Quality preset. balanced is the default. aggressive maximises savings; lossless maximises quality.

lossless

Lossless compression. JPEG input auto-converts to PNG (JPEG has no lossless mode).

balanced

Good quality with meaningful size reduction. Recommended for most use cases.

aggressive

Maximum compression. PNG without an explicit format auto-converts to WebP for lossy savings.

Check Balance

GET /v1/balance — free

Returns your current token balance.

curl
curl https://www.agent-gen.com/api/v1/balance \
  -H "X-API-Key: YOUR_API_KEY"

Response

{ "tokens": 499 }

Origin Hosting

POST /v1/origin and POST /v1/origin/{id}/public-key — free

Provision a dedicated public subdomain (<id>.agent-gen.com) for hosting files. Use this to get a stable origin URL for third-party integrations that require a specific allowed origin — for example, uploading a Tesla virtual key.

curl
# 1. Provision a new origin subdomain
curl -X POST https://www.agent-gen.com/api/v1/origin \
  -H "X-API-Key: YOUR_API_KEY"
# → { "id": "abc123xyz", "origin": "https://abc123xyz.agent-gen.com" }

# 2. Upload your EC public key (PEM) to the origin
curl -X POST https://www.agent-gen.com/api/v1/origin/abc123xyz/public-key \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: text/plain" \
  --data-binary @public-key.pem

POST /v1/origin

Creates a new origin. Returns id and origin URL. Requires API key.

POST /v1/origin/{id}/public-key

Uploads a PEM public key. Body must be raw PEM text with Content-Type: text/plain. Max 10 KB.

MCP Server

POST https://www.agent-gen.com/api/mcp — JSON-RPC 2.0

AgentGen has a built-in Model Context Protocol (MCP) server. Add it to Claude once and your AI can generate PDFs and images without any code — just describe what you need.

bash
# Claude Code — add AgentGen as an MCP server (one-time setup)
claude mcp add --transport http agentgen https://www.agent-gen.com/api/mcp \
  --header "x-api-key: YOUR_API_KEY"

# Verify it was added
claude mcp list

Available tools

ToolCostDescription
generate_image1 tokenRender HTML to PNG, JPEG, or WebP. Returns a CDN URL.
generate_pdf2 tokens/pageRender HTML to a PDF. Supports multi-page documents.
upload_fileFreeUpload a base64 image and get a 24-hour CDN URL to use in HTML.
get_balanceFreeCheck your remaining token balance.

Tool parameters

generate_image
ParameterTypeRequiredDescription
htmlstringYesFull HTML to render. Inline CSS and base64 images supported.
viewport_widthnumberNoViewport width used for layout before capture (default: 1200)
viewport_heightnumberNoViewport height used for layout before capture (default: 800)
selectorstringNoCapture a specific element instead of the full rendered document
formatpng | jpeg | webpNoOutput format (default: png)
device_scale_factornumberNoDevice pixel ratio 1–3 (default: 2)
generate_pdf
ParameterTypeRequiredDescription
htmlstringNo*HTML for a single-page PDF. Omit if using pages array.
page_size_sourcecss | formatNoPrefer CSS @page size or fallback format (default: css)
formatA4 | Letter | A3 | LegalNoFallback paper size when CSS does not define one (default: A4)
landscapebooleanNoLandscape orientation (default: false)
marginobjectNo{ top, bottom, left, right } in CSS units e.g. "20mm"
pagesarrayNo*Multi-page: array of page objects each with html, page_size_source, format, landscape, margin

* Either html or pages is required.

upload_file
ParameterTypeRequiredDescription
base64_contentstringYesBase64-encoded file content (no data URI prefix)
filenamestringYesFilename with extension, e.g. "logo.png"
content_typestringYesMIME type: image/png, image/jpeg, image/webp, image/gif, image/svg+xml

Authentication

Pass your API key as the x-api-key header when registering the server. All tool calls inherit it automatically — no per-call auth needed.

Discovery

MCP metadata is also available at GET /api/mcp and /.well-known/mcp.json.

CLI

The agentgen CLI lets you generate PDFs and images from your terminal, shell scripts, and CI pipelines — no code required. See the full CLI guide →

Install

bash
# One-liner (Linux & macOS)
curl -fsSL https://raw.githubusercontent.com/Agent-Gen-com/agent-gen-lib/main/install.sh | sh

# Homebrew
brew tap Agent-Gen-com/agentgen && brew install agentgen

# Cargo
cargo install agentgen-cli

Quick start

bash
export AGENTGEN_API_KEY="agk_..."

# Generate an image
agentgen image --html "<h1>Hello!</h1>" --output hello.png

# Generate a PDF
agentgen pdf --html "<h1>Invoice #42</h1>" --output invoice.pdf

# Upload a file for 24h CDN access
agentgen upload ./logo.png

# Check token balance
agentgen balance

# Provision a public origin subdomain
agentgen origin

# Upload a public key to an origin
agentgen public-key <origin-id> public-key.pem

Key flags

CommandCommon flags
agentgen image--html --viewport-width --selector --format --output
agentgen pdf--html --page-size-source --format --landscape --margin-top/bottom/left/right --output
agentgen upload<file-path>
agentgen balance(no flags needed)
agentgen origin(no flags needed — returns id and URL)
agentgen public-key<origin-id> <pem-file>

Full CLI reference with all flags and CI examples →

Errors

All errors return JSON with a error field.

StatusMeaning
400Bad Request — invalid parameters
401Unauthorized — missing or invalid API key
402Payment Required — insufficient token balance
429Rate Limited — free tier allows 1 req/60s per IP. Add an API key to bypass.
500Server Error — something went wrong on our end
JSON
{
  "error": "Insufficient tokens.",
  "balance": 0,
  "required": 2,
  "buy_more_url": "https://www.agent-gen.com/dashboard/billing"
}