> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bunny.build/llms.txt
> Use this file to discover all available pages before exploring further.

# POST /qr-code

> Generate QR codes as PNG or SVG from any text or URL.

## Endpoint

```
POST https://api.bunny.build/api/v1/qr-code
```

## Authentication

| Header         | Required | Value                    |
| -------------- | -------- | ------------------------ |
| `X-API-Key`    | Yes      | Your API key (`bun_...`) |
| `Content-Type` | Yes      | `application/json`       |

## Overview

Generate QR codes from any text or URL in PNG or SVG format. Control the output size, error correction level, and foreground/background colors. PNG responses include a base64-encoded image ready to embed directly in your application; SVG responses include the raw SVG string.

## Use cases

* Display QR codes during mobile app onboarding to link devices
* Generate payment links or promo URLs for print and digital campaigns
* Embed product catalog entries with scannable links
* Issue event tickets with encoded check-in data

## Request body

| Field              | Type    | Required | Description                                                           |
| ------------------ | ------- | -------- | --------------------------------------------------------------------- |
| `data`             | string  | Yes      | The text or URL to encode (max 4296 characters)                       |
| `format`           | string  | No       | Output format: `"png"` or `"svg"`. Default: `"png"`                   |
| `size`             | integer | No       | Image width in pixels for PNG output (100–1000). Default: `300`       |
| `error_correction` | string  | No       | Error correction level: `"L"`, `"M"`, `"Q"`, or `"H"`. Default: `"M"` |
| `dark`             | string  | No       | Hex color for dark modules. Default: `"#000000"`                      |
| `light`            | string  | No       | Hex color for light modules. Default: `"#ffffff"`                     |

### Example

```json theme={null}
{
  "data": "https://bunny.build",
  "format": "png",
  "size": 300
}
```

## Response

### 200 OK — PNG format

| Field              | Type    | Description                  |
| ------------------ | ------- | ---------------------------- |
| `format`           | string  | `"png"`                      |
| `data`             | string  | Original input data (echoed) |
| `qr_base64`        | string  | Base64-encoded PNG image     |
| `mime_type`        | string  | `"image/png"`                |
| `size`             | integer | Actual image width in pixels |
| `error_correction` | string  | Error correction level used  |

**Example**

```json theme={null}
{
  "format": "png",
  "data": "https://bunny.build",
  "qr_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
  "mime_type": "image/png",
  "size": 300,
  "error_correction": "M"
}
```

### 200 OK — SVG format

| Field              | Type   | Description                  |
| ------------------ | ------ | ---------------------------- |
| `format`           | string | `"svg"`                      |
| `data`             | string | Original input data (echoed) |
| `qr`               | string | Raw SVG string               |
| `error_correction` | string | Error correction level used  |

**Example**

```json theme={null}
{
  "format": "svg",
  "data": "https://bunny.build",
  "qr": "<svg xmlns=\"http://www.w3.org/2000/svg\" ...>...</svg>",
  "error_correction": "M"
}
```

### 401 Unauthorized

```json theme={null}
{
  "detail": "Missing API key. Include X-API-Key header."
}
```

### 402 Payment Required

```json theme={null}
{
  "detail": "Monthly quota exceeded. Upgrade your plan."
}
```

### 422 Unprocessable Entity

```json theme={null}
{
  "detail": "Field 'data' is required."
}
```

### 429 Too Many Requests

```json theme={null}
{
  "detail": "Rate limit exceeded. Try again in 60 seconds."
}
```

## cURL example

```bash theme={null}
curl -X POST https://api.bunny.build/api/v1/qr-code \
  -H "X-API-Key: bun_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{"data": "https://bunny.build", "format": "png", "size": 300}'
```
