Base URL
https://<your-worker>.workers.dev
Endpoints
GET /api/qr
Generate a QR code image from the supplied data.
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
data | string | Yes | — | The text or URL to encode in the QR code (max 4 296 chars) |
size | integer | No | 256 | Width & height in pixels (32 – 2 048) |
format | string | No | png |
Output format: png or svg |
errorCorrectionLevel | string | No | M |
Error correction: L, M, Q, or H |
colorDark | string | No | #000000ff |
Foreground colour as hex (#RGB, #RGBA, #RRGGBB, or #RRGGBBAA) |
colorLight | string | No | #ffffffff |
Background colour as hex. Use #00000000 for transparent. |
margin | integer | No | 2 |
Quiet zone in modules (0–10) |
Response
- Content-Type:
image/pngorimage/svg+xml - Body: Binary image data (PNG) or SVG markup
- Cache: Responses include
Cache-Control: public, max-age=86400
Error Response
{
"error": "Missing required parameter: data"
}
Errors return a JSON body with an appropriate HTTP status code (400 or 500).
Examples
cURL – PNG
curl "https://<your-worker>.workers.dev/api/qr?data=https://example.com&size=512" \
-o qrcode.png
cURL – SVG
curl "https://<your-worker>.workers.dev/api/qr?data=Hello+World&format=svg" \
-o qrcode.svg
cURL – Custom colours & margin
curl "https://<your-worker>.workers.dev/api/qr?data=hello&colorDark=%233b82f6ff&colorLight=%2300000000&margin=0" \
-o qrcode-blue-transparent.png
JavaScript (Fetch)
const url = new URL('https://<your-worker>.workers.dev/api/qr');
url.searchParams.set('data', 'https://example.com');
url.searchParams.set('size', '300');
const img = document.createElement('img');
img.src = url.toString();
document.body.appendChild(img);
Python (requests)
import requests
resp = requests.get(
"https://<your-worker>.workers.dev/api/qr",
params={"data": "https://example.com", "size": 256, "format": "png"},
)
with open("qrcode.png", "wb") as f:
f.write(resp.content)
CORS
All API responses include permissive CORS headers, allowing requests from any origin:
Access-Control-Allow-Origin: *Access-Control-Allow-Methods: GET, OPTIONS