Generate QR Codes in Production: The QR Code Generator API
QR codes are everywhere—on invoices, packaging, menus, and marketing materials. But generating them efficiently at scale is harder than it looks. Most QR code APIs are slow, limited in output formats, or charge by the request. We built a different kind of API.
The Problem: Most QR Code APIs Are Slow
Typical free QR APIs take 200–800ms per request. That's noticeable in a user-facing workflow. Meanwhile, proprietary solutions charge $14–50 per month just for the privilege of generating codes.
Our QR Code Generator API runs on Cloudflare Workers, returning results in under 50ms from 300+ edge locations worldwide. You get PNG, SVG, and Base64 outputs—with 500 requests/month free. No credit card. No setup overhead.
Real-World Use Case: Dynamic E-Commerce Checkout Links
Imagine an order confirmation flow. For each order, you need a unique QR code linking to the tracking page:
Order #12345
→ Generate unique tracking URL
→ Encode in QR code
→ Embed in order confirmation email
→ Customer scans → instant shipping status
With a 200ms QR API, you're adding 200ms to each order confirmation. With a 50ms API, it's invisible.
Python Implementation
import requests
import json
# RapidAPI credentials
RAPIDAPI_KEY = "YOUR_RAPIDAPI_KEY"
RAPIDAPI_HOST = "qr-code-generator-api.p.rapidapi.com"
def generate_tracking_qr(order_id: str, tracking_url: str) -> str:
"""Generate a QR code for an order tracking link."""
url = "https://qr-code-generator-api.p.rapidapi.com/generate"
params = {
"text": tracking_url,
"size": 400,
"format": "base64", # Returns JSON with data_uri
"color": "1a73e8", # Brand blue
"bgcolor": "ffffff"
}
headers = {
"X-RapidAPI-Key": RAPIDAPI_KEY,
"X-RapidAPI-Host": RAPIDAPI_HOST
}
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
result = response.json()
return result["data_uri"] # Ready for <img src="">
# Example
qr_data_uri = generate_tracking_qr(
order_id="12345",
tracking_url="https://shop.example.com/track/12345"
)
# Embed directly in HTML email
email_html = f"""
<html>
<body>
<h1>Your order has shipped!</h1>
<p>Scan this code to track your package:</p>
<img src="{qr_data_uri}" alt="Tracking QR Code" />
</body>
</html>
"""
JavaScript/Node.js Implementation
const axios = require("axios");
const generateTrackingQR = async (orderId, trackingUrl) => {
const response = await axios.get(
"https://qr-code-generator-api.p.rapidapi.com/generate",
{
params: {
text: trackingUrl,
size: 400,
format: "base64",
color: "1a73e8", // Brand blue
bgcolor: "ffffff"
},
headers: {
"X-RapidAPI-Key": process.env.RAPIDAPI_KEY,
"X-RapidAPI-Host": "qr-code-generator-api.p.rapidapi.com"
}
}
);
const { data_uri, mime_type } = response.data;
return { dataUri: data_uri, mimeType: mime_type };
};
// Express.js endpoint
app.post("/api/orders/:id/qr", async (req, res) => {
const { id } = req.params;
const trackingUrl = `https://shop.example.com/track/${id}`;
try {
const qr = await generateTrackingQR(id, trackingUrl);
res.json(qr);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
Advanced Features: Color Customization & Error Correction
The API supports full color customization and variable error correction levels. This is crucial for printed QR codes.
Print-Quality QR Code for Marketing Materials
# Generate high-error-correction QR code with brand colors
curl "https://qr-code-generator-api.p.rapidapi.com/generate" \
-H "X-RapidAPI-Key: YOUR_KEY" \
-H "X-RapidAPI-Host: qr-code-generator-api.p.rapidapi.com" \
-d "text=https://marketing.example.com/campaign2024" \
-d "size=1000" \
-d "format=svg" \
-d "color=FF5722" \
-d "bgcolor=FAFAFA" \
-d "error_correction=H" \
-o campaign-qr.svg
Why error correction level H (30% redundancy)? If your QR code is partially covered by a logo or printed on a curved surface, the scanner still works. Perfect for branded merchandise.
API Parameters Reference
| Parameter | Type | Default | Notes |
|---|---|---|---|
text |
string | — | Text/URL to encode (max 4,296 chars) |
size |
integer | 300 | Pixel dimension (10–1000) |
format |
string | png |
png, svg, or base64
|
color |
string | 000000 |
Foreground color (hex, no #) |
bgcolor |
string | ffffff |
Background color (hex, no #) |
error_correction |
string | M |
L (7%), M (15%), Q (25%), H (30%) |
Pricing Tiers
| Plan | Cost | Requests/mo | Rate Limit |
|---|---|---|---|
| Free | $0 | 500 | 1 req/sec |
| Pro | $5.99 | 50,000 | 10 req/sec |
| Ultra | $14.99 | 500,000 | 50 req/sec |
When to Use This API
✅ Perfect for:
- E-commerce order tracking links
- Restaurant contactless menus
- Event tickets & boarding passes
- Invoice embedding
- Marketing campaign URLs
- Mobile app deep links
- CI/CD deployment links
❌ Not ideal for:
- Ultra-high-frequency batch generation (>100K/mo free-tier limit)
- High-security applications (use encrypted QR codes instead)
Monitoring & Error Handling
import time
def generate_with_retry(text: str, max_retries: int = 3) -> str:
"""Generate QR code with exponential backoff."""
for attempt in range(max_retries):
try:
response = requests.get(
"https://qr-code-generator-api.p.rapidapi.com/generate",
params={"text": text, "format": "base64"},
headers={...},
timeout=5
)
response.raise_for_status()
return response.json()["data_uri"]
except requests.RequestException as e:
if attempt == max_retries - 1:
raise
wait_time = 2 ** attempt
print(f"Retry in {wait_time}s... ({e})")
time.sleep(wait_time)
Final Thoughts
QR codes are no longer optional—they're table stakes for modern applications. With sub-50ms generation from the edge and flexible output formats, you can embed them everywhere without worrying about latency.
Get started free at RapidAPI Marketplace.
Have you integrated QR codes in your app? Share your use case in the comments!
Top comments (0)