---
title: "Generate a QR code asset via Netlify Function"
method: POST
path: "/.netlify/functions/generate-qr"
---

# Generate a QR code asset via Netlify Function

`POST /.netlify/functions/generate-qr`

## Request

- Base URL: `https://qrcodecrafter.com`
- URL: `https://qrcodecrafter.com/.netlify/functions/generate-qr`
- Auth: one of:
  - API key in header `X-Agent-Api-Key`
  - none
- TypeScript: <https://skmtc.dev/qrcodecrafter/apis/qrcodecrafter-api/docs/.netlify/functions/generate-qr/post.ts> (a function with typed inputs; its response is checked against the schema)

## Request body

- GenerateQrRequest
  - `value` string, required: Data encoded in the QR code
  - `format` 'svg' | 'png' | 'jpg' | 'webp' | 'pdf' | 'eps': Output format for the QR code asset
  - `size` integer: Pixel width/height of the generated asset
  - `margin` integer: Quiet-zone margin around the QR code modules
  - `fgColor` string: Hex foreground color, for example #000000
  - `bgColor` string: Hex background color, for example #FFFFFF
  - `errorCorrectionLevel` 'L' | 'M' | 'Q' | 'H': QR error correction level
  - `logo` string, nullable: Optional base64 data URL for a logo (PNG, JPG, or WEBP) to composite at the center. Files larger than 1MB are rejected.

## Response `200`

Generated QR code asset encoded as base64

- GenerateQrResponse
  - `success` boolean
  - `data` string: Base64 encoded asset bytes
  - `dataUrl` string: Ready-to-embed data URL built from contentType and base64 data
  - `downloadUrl` string: Relative GET URL for retrieving the generated asset without embedding base64 bytes. Emitted only for no-logo public HTTP(S) URL payloads that do not include obvious credential-style query parameters.
  - `contentType` string
  - `extension` string
  - `suggestedFilename` string
  - `byteLength` integer: Exact number of decoded bytes in the base64 data field
  - `dimensions` GeneratedAssetDimensions: Rendered asset dimensions. Raster and SVG assets use pixels; PDF and EPS use points.
    - `width` number, required
    - `height` number, required
    - `unit` 'px' | 'pt', required
  - `qrOptions` object: Normalized QR options used to generate the asset
    - `size` integer
    - `margin` integer
    - `errorCorrectionLevel` 'L' | 'M' | 'Q' | 'H'

## Other responses

- `400`: Invalid request
- `401`: Missing or invalid API key when key enforcement is enabled
- `405`: Method not allowed
- `429`: Too many requests. QR generation uses a cost-weighted per-client budget; honor the retry and rate-limit headers before resubmitting work.
- `500`: Server error

## Changes

- **2026-10-26** `347f94b614ee`: 1 info
  - added the media type `application/x-www-form-urlencoded` to the request body

[Operation history](https://skmtc.dev/qrcodecrafter/apis/qrcodecrafter-api/changes/.netlify/functions/generate-qr/post.md)

---

[API](https://skmtc.dev/qrcodecrafter/apis/qrcodecrafter-api.md) - [All operations](https://skmtc.dev/qrcodecrafter/apis/qrcodecrafter-api/llms.txt) - [OpenAPI document](https://skmtc.dev/qrcodecrafter/apis/qrcodecrafter-api/revisions/347f94b614ee?raw)
