Quickstart
Generate your first image in under a minute. Sign up, buy tokens, grab your API key, and make your first request.
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.
# 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.
X-API-Key: YOUR_API_KEY401 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 -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"
}'| Field | Type | Description |
|---|---|---|
| html | string | HTML content to render (max 500 KB) |
| viewport_width | integer | Viewport width used for layout before capture, 1–5000 (default: 1200) |
| viewport_height | integer | Viewport height used for layout before capture, 1–5000 (default: 800) |
| selector | string | Optional CSS selector. If provided, captures that element instead of the full document |
| format | 'png' | 'jpeg' | 'webp' | Output format (default: png) |
| device_scale_factor | number | Device 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 -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
}'| Field | Type | Description |
|---|---|---|
| html | string | HTML 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) |
| margin | object | top/bottom/left/right margins (CSS units) |
| landscape | boolean | Landscape orientation (default: false) |
| print_background | boolean | Render CSS backgrounds (default: true) |
| optimize | boolean | Shrink the final PDF with a post-processing pass (default: true) |
| pages | array | Multi-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 -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 -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
}| Field | Type | Description |
|---|---|---|
| file | binary (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 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.
# 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.pemPOST /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.
# 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 listAvailable tools
| Tool | Cost | Description |
|---|---|---|
| generate_image | 1 token | Render HTML to PNG, JPEG, or WebP. Returns a CDN URL. |
| generate_pdf | 2 tokens/page | Render HTML to a PDF. Supports multi-page documents. |
| upload_file | Free | Upload a base64 image and get a 24-hour CDN URL to use in HTML. |
| get_balance | Free | Check your remaining token balance. |
Tool parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| html | string | Yes | Full HTML to render. Inline CSS and base64 images supported. |
| viewport_width | number | No | Viewport width used for layout before capture (default: 1200) |
| viewport_height | number | No | Viewport height used for layout before capture (default: 800) |
| selector | string | No | Capture a specific element instead of the full rendered document |
| format | png | jpeg | webp | No | Output format (default: png) |
| device_scale_factor | number | No | Device pixel ratio 1–3 (default: 2) |
| Parameter | Type | Required | Description |
|---|---|---|---|
| html | string | No* | HTML for a single-page PDF. Omit if using pages array. |
| page_size_source | css | format | No | Prefer CSS @page size or fallback format (default: css) |
| format | A4 | Letter | A3 | Legal | No | Fallback paper size when CSS does not define one (default: A4) |
| landscape | boolean | No | Landscape orientation (default: false) |
| margin | object | No | { top, bottom, left, right } in CSS units e.g. "20mm" |
| pages | array | No* | Multi-page: array of page objects each with html, page_size_source, format, landscape, margin |
* Either html or pages is required.
| Parameter | Type | Required | Description |
|---|---|---|---|
| base64_content | string | Yes | Base64-encoded file content (no data URI prefix) |
| filename | string | Yes | Filename with extension, e.g. "logo.png" |
| content_type | string | Yes | MIME 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
# 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-cliQuick start
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.pemKey flags
| Command | Common 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> |
Errors
All errors return JSON with a error field.
| Status | Meaning |
|---|---|
| 400 | Bad Request — invalid parameters |
| 401 | Unauthorized — missing or invalid API key |
| 402 | Payment Required — insufficient token balance |
| 429 | Rate Limited — free tier allows 1 req/60s per IP. Add an API key to bypass. |
| 500 | Server Error — something went wrong on our end |
{
"error": "Insufficient tokens.",
"balance": 0,
"required": 2,
"buy_more_url": "https://www.agent-gen.com/dashboard/billing"
}