Skip to content

Generate QR Code

Generate a QR code from any text, URL, or data.

Endpoint

GET /api/generate

Authentication

Requires API key via Authorization header, X-API-Key header, or api_key query parameter.

Parameters

ParameterTypeRequiredDefaultDescription
datastring-Content to encode. Max 2,953 characters.
sizenumber-300Image size in pixels. Range: 50-2000.
formatstring-pngOutput format: png or svg.
colorstring-000000QR code color (hex, without #).
backgroundstring-ffffffBackground color (hex, without #).
errorCorrectionstring-MError correction: L, M, Q, or H.
marginnumber-4Quiet zone margin in modules. Range: 0-10.
logostring--URL to logo image (Pro plan).
logoSizenumber-20Logo size as percentage of QR code.

Response

Returns the QR code image directly with appropriate Content-Type:

  • image/png for PNG format
  • image/svg+xml for SVG format

Examples

Basic QR Code

bash
curl "https://www.qrcodeapi.io/api/generate?data=https://example.com" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -o qr.png

Custom Colors

bash
curl "https://www.qrcodeapi.io/api/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -G \
  --data-urlencode "data=https://example.com" \
  --data "color=4F46E5" \
  --data "background=F3F4F6" \
  -o purple-qr.png

SVG Output

bash
curl "https://www.qrcodeapi.io/api/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -G \
  --data-urlencode "data=https://example.com" \
  --data "format=svg" \
  -o qr.svg

Large Size with High Error Correction

bash
curl "https://www.qrcodeapi.io/api/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -G \
  --data-urlencode "data=https://example.com" \
  --data "size=1000" \
  --data "errorCorrection=H" \
  -o large-qr.png

With Logo Overlay (Pro Plan)

bash
curl "https://www.qrcodeapi.io/api/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -G \
  --data-urlencode "data=https://example.com" \
  --data-urlencode "logo=https://example.com/logo.png" \
  --data "logoSize=25" \
  --data "errorCorrection=H" \
  -o branded-qr.png

Logo Best Practices

When using logo overlay, always set errorCorrection=H to ensure the QR code remains scannable even with the logo covering part of the code.

Error Correction Levels

LevelRecoveryUse Case
L~7%High density data, clean environment
M~15%Standard use (default)
Q~25%Outdoor use, some damage expected
H~30%Logo overlay, harsh conditions

Code Examples

JavaScript

javascript
async function generateQR(data, options = {}) {
  const params = new URLSearchParams({
    data,
    size: options.size || 300,
    format: options.format || 'png',
    color: options.color || '000000',
    background: options.background || 'ffffff',
    errorCorrection: options.errorCorrection || 'M'
  });

  const response = await fetch(
    `https://www.qrcodeapi.io/api/generate?${params}`,
    {
      headers: {
        'Authorization': `Bearer ${API_KEY}`
      }
    }
  );

  if (!response.ok) {
    const error = await response.json();
    throw new Error(error.message);
  }

  return response.blob();
}

// Usage
const qrBlob = await generateQR('https://example.com', {
  size: 500,
  color: '22c55e'
});

Python

python
import requests

def generate_qr(data, **options):
    params = {
        'data': data,
        'size': options.get('size', 300),
        'format': options.get('format', 'png'),
        'color': options.get('color', '000000'),
        'background': options.get('background', 'ffffff'),
        'errorCorrection': options.get('error_correction', 'M')
    }
    
    response = requests.get(
        'https://www.qrcodeapi.io/api/generate',
        params=params,
        headers={'Authorization': f'Bearer {API_KEY}'}
    )
    
    response.raise_for_status()
    return response.content

# Usage
qr_image = generate_qr('https://example.com', size=500, color='22c55e')
with open('qr.png', 'wb') as f:
    f.write(qr_image)

PHP

php
<?php
function generateQR($data, $options = []) {
    $params = http_build_query([
        'data' => $data,
        'size' => $options['size'] ?? 300,
        'format' => $options['format'] ?? 'png',
        'color' => $options['color'] ?? '000000',
        'background' => $options['background'] ?? 'ffffff',
        'errorCorrection' => $options['errorCorrection'] ?? 'M'
    ]);
    
    $context = stream_context_create([
        'http' => [
            'header' => "Authorization: Bearer " . API_KEY
        ]
    ]);
    
    return file_get_contents(
        "https://www.qrcodeapi.io/api/generate?{$params}",
        false,
        $context
    );
}

// Usage
$qr = generateQR('https://example.com', ['size' => 500]);
file_put_contents('qr.png', $qr);
?>

Error Responses

StatusMessageDescription
400data parameter requiredMissing required data parameter
400Invalid sizeSize not in range 50-2000
400Invalid formatFormat not png or svg
401Invalid API keyAuthentication failed
429Rate limit exceededToo many requests

See Error Codes for complete error documentation.