QR Code Generator API: The Complete Guide

Need to generate QR codes in your application? This guide covers everything you need to know about QR code generation via API, including different data types, customization options, and implementation examples.

What is a QR Code?

A QR (Quick Response) code is a two-dimensional barcode that can store various types of data including URLs, text, contact information, and more. Invented in 1994 by Denso Wave for tracking automotive parts, QR codes are now ubiquitous in marketing, payments, and authentication.

QR codes can store up to 3KB of data and include built-in error correction for reliable scanning.

QR Code Types

QR codes can encode different types of data:

URL

Link to websites - the most common use case for QR codes.

Text

Plain text messages, notes, or any string data.

vCard

Contact information that can be saved directly to a phone's contacts.

WiFi

Network credentials for easy WiFi connection without typing passwords.

Error Correction: QR codes use Reed-Solomon error correction. Higher levels (L, M, Q, H) allow codes to be read even when partially damaged.

Using the QR Code Generator API

TinyFn provides a simple endpoint to generate QR codes:

API Request
POST https://api.tinyfn.io/v1/generate/qrcode
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "data": "https://tinyfn.io",
  "size": 300,
  "format": "png"
}
Response
{
  "qr_code": "data:image/png;base64,iVBORw0KGgo...",
  "format": "png",
  "size": 300,
  "data_encoded": "https://tinyfn.io"
}

Parameters

Parameter Type Description
data string Data to encode in QR code (required)
size integer Size in pixels (default: 200)
format string "png" or "svg" (default: png)
error_correction string L, M, Q, or H (default: M)

Code Examples

JavaScript / Node.js

const response = await fetch('https://api.tinyfn.io/v1/generate/qrcode', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your-api-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ data: 'https://tinyfn.io', size: 300 })
});
const result = await response.json();
// Use result.qr_code as image src

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/generate/qrcode',
    json={'data': 'https://tinyfn.io', 'size': 300},
    headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
# Save or display result['qr_code']

cURL

curl -X POST "https://api.tinyfn.io/v1/generate/qrcode" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"data": "https://tinyfn.io", "size": 300}'

Common Use Cases

  • Marketing: Link to websites, promotions, or app downloads
  • Payments: Mobile payment systems and invoicing
  • Authentication: Two-factor authentication setup
  • Event Tickets: Digital tickets and check-in systems
  • Product Info: Link to product details or manuals

Best Practices

  1. Test scannability: Always test QR codes with multiple devices
  2. Use appropriate size: Larger QR codes are easier to scan
  3. Add quiet zone: Ensure white space around the QR code
  4. Consider error correction: Use higher levels for printed materials

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-generate": {
      "url": "https://api.tinyfn.io/mcp/generate/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all generator tools available via MCP in our Generator MCP Tools for AI Agents guide.

Try the QR Code Generator API

Get your free API key and start generating QR codes in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key