What Is a QR Code API — and Do You Need One?
Short answer: a QR code API is a web address that takes some text (usually a URL) and returns a QR code image. You do not have to rent one. Install a free open-source library (qrcode for Node, segno for Python, chillerlan/php-qrcode for PHP), wrap it in one route on your own server, and you have a private QR code API with no key, quota or bill.
Search for “QR code API” and you will find hosted services that turn an HTTP request into a QR image, usually with API keys, monthly quotas and paid tiers. For most developers there is a simpler answer: generating a QR code is a small, deterministic computation that any language can do locally with a free open-source library. The same input always gives the same image, there is no secret sauce, and nothing needs to leave your server — or even the user’s browser.
To be clear up front: GenerateOnlineQR.com does not offer a public API. This guide shows how to get everything a QR API gives you — codes on demand, PNG or SVG, chosen error correction — in your own code, and how to wrap it in your own tiny HTTP endpoint if other services need one.
| Approach | Where the code is made | Good for | Watch out for |
|---|---|---|---|
| Library in the browser | User’s device | Web apps, previews, private data (Wi-Fi passwords, contacts) | Needs JavaScript; set UTF-8 encoding |
| Library on your server | Your backend | Emails, PDFs, tickets, invoices, batch jobs | Nothing beyond normal input validation |
| Your own HTTP endpoint | Your backend, exposed via URL | Several apps or teams sharing one service; <img src> embedding | Auth, rate limits, size caps |
| Native OS APIs | iOS / macOS / Android app | Apps; works offline | Scale the image without smoothing |
| Third-party hosted API | Someone else’s server | Only if you need their extra features | Your data leaves your system; quotas; the service can change or shut down |
If you are sending your data to a remote server only to get a QR image back, you are adding latency, a dependency and a privacy question to a job a 50 KB library can do locally. Self-host unless a hosted service gives you something you genuinely need.
Generate QR Codes in the Browser (Client-Side)
Our own free generator works this way: it uses the open-source qrcode-generator JavaScript library, so the code is built on the visitor’s device and the text is never uploaded. You can do the same in a few lines:
// <script src="https://cdn.jsdelivr.net/npm/qrcode-generator@1.4.4/qrcode.min.js"></script>
qrcode.stringToBytes = qrcode.stringToBytesFuncs['UTF-8']; // correct non-ASCII text
const qr = qrcode(0, 'M'); // 0 = pick the smallest version; M = 15% error correction
qr.addData('https://example.com/order/1234');
qr.make();
// SVG markup with a 4-module quiet zone
document.getElementById('out').innerHTML =
qr.createSvgTag({ cellSize: 8, margin: 4 });
That is the whole “API call”. For styled output, canvas rendering and Node usage, see our full guide to generating QR codes in JavaScript.
Generate QR Codes on the Server
Server-side generation suits anything you send or store: order confirmations, PDF tickets, invoices, labels. Every mainstream language has a mature, free library.
| Language | Open-source library | Output |
|---|---|---|
| Node.js | qrcode (npm) | PNG buffer, SVG string, data URL, terminal |
| Python | segno, qrcode | PNG, SVG, PDF, EPS and more (segno); PNG/SVG (qrcode) |
| PHP | chillerlan/php-qrcode, endroid/qr-code | SVG, PNG and others |
| Java / Kotlin | ZXing (core + javase) | BitMatrix → PNG |
| Swift | Core Image CIQRCodeGenerator (built in) | CIImage → PNG |
Node.js
import QRCode from 'qrcode';
const png = await QRCode.toBuffer('https://example.com', {
errorCorrectionLevel: 'M', margin: 4, width: 512
});
const svg = await QRCode.toString('https://example.com', { type: 'svg' });
Python
import segno
qr = segno.make_qr("https://example.com", error="m")
qr.save("code.svg", scale=10, border=4)
qr.save("code.png", scale=10, border=4)
More options — colours, Pillow styling, the qrcode package — are in generating QR codes in Python.
PHP
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Common\EccLevel;
use chillerlan\QRCode\Output\QROutputInterface;
$options = new QROptions([
'outputType' => QROutputInterface::MARKUP_SVG,
'eccLevel' => EccLevel::M,
'outputBase64' => false, // return raw <svg> markup, not a data: URI
]);
header('Content-Type: image/svg+xml');
echo (new QRCode($options))->render('https://example.com');
The option names above are from version 5 of the library; check the README of the version you install, because option names have changed between major releases. endroid/qr-code is a popular alternative if you prefer a builder-style interface. Both are free.
Java (ZXing)
Map<EncodeHintType, Object> hints = Map.of(
EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M,
EncodeHintType.CHARACTER_SET, "UTF-8",
EncodeHintType.MARGIN, 4);
BitMatrix m = new QRCodeWriter().encode(
"https://example.com", BarcodeFormat.QR_CODE, 512, 512, hints);
MatrixToImageWriter.writeToPath(m, "PNG", Path.of("code.png"));
Swift (iOS and macOS, no dependencies)
import CoreImage.CIFilterBuiltins
let filter = CIFilter.qrCodeGenerator()
filter.message = Data("https://example.com".utf8)
filter.correctionLevel = "M" // L, M, Q or H
let scaled = filter.outputImage!
.transformed(by: CGAffineTransform(scaleX: 10, y: 10)) // crisp, no blur
let cg = CIContext().createCGImage(scaled, from: scaled.extent)
SwiftUI integration, colouring with CIFalseColor and export are covered in CIQRCodeGenerator in Swift.
Build Your Own QR Code API Endpoint
If several apps need QR images, or you want to drop codes into HTML emails with a plain <img src>, wrap one of these libraries in a small HTTP route. Keep the surface area small: one generate endpoint usually covers everything.
import io, segno
from flask import Flask, request, abort, Response
app = Flask(__name__)
@app.get("/qr")
def qr():
data = request.args.get("data", "")
level = request.args.get("ec", "m").lower()
fmt = request.args.get("format", "svg")
if not data or len(data) > 1000 or level not in ("l", "m", "q", "h") or fmt not in ("svg", "png"):
abort(400)
buf = io.BytesIO()
segno.make_qr(data, error=level).save(buf, kind=fmt, scale=10, border=4)
mime = "image/svg+xml" if fmt == "svg" else "image/png"
return Response(buf.getvalue(), mimetype=mime,
headers={"Cache-Control": "public, max-age=31536000, immutable"})
Prefer Node? The same endpoint in Express looks like this:
import express from 'express';
import QRCode from 'qrcode';
const app = express();
app.get('/qr', async (req, res) => {
const { data = '', ec = 'M', format = 'svg' } = req.query;
if (typeof data !== 'string' || !data || data.length > 1000
|| !['L', 'M', 'Q', 'H'].includes(ec)
|| !['svg', 'png'].includes(format)) {
return res.sendStatus(400);
}
res.set('Cache-Control', 'public, max-age=31536000, immutable');
if (format === 'svg') {
res.type('image/svg+xml').send(await QRCode.toString(data, { type: 'svg', errorCorrectionLevel: ec, margin: 4 }));
} else {
res.type('image/png').send(await QRCode.toBuffer(data, { errorCorrectionLevel: ec, margin: 4, width: 512 }));
}
});
app.listen(3000);
Call it like any QR code API: GET /qr?data=https%3A%2F%2Fexample.com%2Fp%3Fid%3D42&ec=M&format=svg. Remember to URL-encode the data value, otherwise characters such as & and # in your own URL will be read as part of the API request. In an HTML email or page you embed it as <img src="https://yourdomain.com/qr?data=..." alt="QR code">.
Design notes that matter in production:
- Cache aggressively. Output depends only on the input and options, so identical requests can be served from a CDN or browser cache for as long as you like.
- Cap the input. A QR code tops out at 2,953 bytes, and anything near that is unscannable in practice. Reject long payloads early (see QR code data capacity).
- Cap the size and allow-list options such as format and error-correction level, so nobody can ask for a 50,000-pixel PNG.
- Prefer SVG for print and documents; it scales without blur and is tiny for simple codes.
- Keep a quiet zone of four modules in every output, or codes embedded in tight layouts will fail to scan.
QR Code Apps for Mac & Safari
Prefer generating codes without opening a browser tab? These two native Apple apps cover both habits — a full generator on the desktop, and a one-click share button inside Safari.
Securing a Public QR Endpoint
An internal endpoint behind your firewall needs little more than validation. If you expose it on the internet, treat it like any other API.
- Authenticate callers with a key in an
AuthorizationorX-API-Keyheader. Query-string keys end up in logs and browser history. (For<img src>use in emails, sign the URL with an HMAC instead of exposing a key.) - Do not become an open QR printer for phishing links. If the endpoint is public, restrict
datato your own domains or to IDs you look up server-side.
- Rate-limit per key or IP and answer with
429 Too Many RequestsplusRetry-After. Image generation is cheap, but not free at scale. - Log sensibly. Payloads may contain personal data (contacts, ticket IDs); avoid writing them to logs in full.
Caching, Signed URLs and Rate Limits
A QR code is a pure function of its input: the same data, error-correction level and format always produce the same image. That makes caching almost free to get right.
- Browser and CDN cache. The
Cache-Control: public, max-age=31536000, immutableheader in the examples lets browsers and any CDN in front of your server keep the image for a year. Because the URL contains the data, a different code means a different URL, so you never serve a stale image. - Application cache. For heavy batch jobs, store generated files under a hash of the input (for example the SHA-256 of
data|ec|format) and reuse them. - Signed URLs. If the endpoint is public but should only draw codes that you asked for, add a signature that only your backend can create. The server recomputes it and rejects mismatches.
import hmac, hashlib
SECRET = b"load-me-from-an-environment-variable"
def sign(data, ec, fmt):
msg = f"{data}|{ec}|{fmt}".encode()
return hmac.new(SECRET, msg, hashlib.sha256).hexdigest()
# in the route, after reading the query string:
if not hmac.compare_digest(request.args.get("sig", ""), sign(data, level, fmt)):
abort(403)
Your backend builds the URL with &sig=... when it renders the page or email; visitors cannot change data without invalidating the signature, so the endpoint cannot be used as a free QR printer for other people’s links.
Rate limits still matter for any endpoint that is not signed. Limit per IP or key in your reverse proxy or framework, and return 429 Too Many Requests with a Retry-After header. Cached responses served by a CDN never reach your server, so they do not count against the limit.
Payload Formats: Wi-Fi, vCard, Email, Phone
A QR library encodes whatever string you give it. The “type” of code is just a text convention that phones recognise, so building these strings correctly is your job:
| Type | String to encode | Gotcha |
|---|---|---|
| URL | https://example.com/p?id=42 | Percent-encode query values |
| Wi-Fi | WIFI:T:WPA;S:name;P:pass;; | Backslash-escape \ ; , : " (Wi-Fi format) |
| Contact | BEGIN:VCARD … END:VCARD | Line breaks matter; no PHOTO (vCard format) |
mailto:hi@example.com?subject=Hello | Encode spaces as %20 | |
| Phone | tel:+15551234567 | Use international format |
“Dynamic QR Code API”: Build the Redirect Yourself
A “dynamic” QR code is a static QR code that points to a short redirect URL; the service behind it lets you change the destination and counts the visits. You can build this with the tools above and your own domain:
- Encode a short URL you control, such as
https://yourdomain.com/r/spring24, as a normal static code. - Add a route that looks up
spring24in your database and returns a302redirect to the current destination. - Append UTM parameters to the destination (or log the hit in the redirect route) to see scans in your own analytics.
You keep the data, there is no subscription, and the printed code works for as long as your domain does. The trade-offs are explained in static vs dynamic QR codes.
Common Integrations
- E-commerce: order-lookup or returns links on packing slips, generated when the PDF is rendered.
- CRM and email: per-contact links (with UTM tags) rendered server-side into campaign emails.
- Ticketing: encode a signed token (for example an HMAC of the ticket ID), not a plain sequential number, and verify it at the door. Guessable IDs are easy to forge — see QR codes for events and ticketing.
What About Hosted QR Code APIs?
Hosted QR code API services exist, and some are worth using for specific reasons. Before you pick one, check what you would actually be paying for, because the core job (turning text into an image) is the part you can do yourself:
- Scan analytics and editable destinations. This is the real reason to use a hosted “dynamic” QR service. If you need only a redirect and a visit count, the self-built route in the section above covers it.
- Privacy. The text you encode is sent to a third party. That is unacceptable for Wi-Fi passwords, tickets or personal data.
- Pricing and quotas. Free tiers are often rate-limited, and printed codes that depend on a vendor’s redirect stop working if the plan lapses.
- Longevity. A static code you generated yourself keeps working as long as its destination does; a code that points at a vendor’s short link depends on that vendor.
If you do use one, prefer a service that can export plain static codes, so you are never locked in. For the full picture of redirect-based codes, read static vs dynamic QR codes.
Troubleshooting Your QR Endpoint
- The code will not scan. Check the quiet zone (four modules), contrast (dark modules on a light background), and that the image was not scaled with smoothing. See error correction levels if a logo covers the centre.
- The URL inside the code is cut off. The query string was not URL-encoded, so
&or#ended yourdatavalue early. - Accented or non-Latin text is garbled. Encode as UTF-8 (set it explicitly in the browser library and ZXing).
- The code is huge and hard to scan. The payload is too long. Shorten the URL or move the data to a page and encode its link; see data capacity.
- The old image keeps appearing. A cache is serving an earlier response for the same URL. Because the output only depends on the input, this should only happen if you changed the rendering options without changing the URL; add a version parameter.
Not a Developer? No Code Needed
If you only need a handful of codes, skip the code entirely. Our free web generator makes URL, Text, Wi-Fi, Email and Phone codes in your browser and downloads PNG or SVG. On a Mac, Gen QR – Code Maker adds colours, a logo overlay, L/M/Q/H error correction and contact-card codes, fully offline, for a one-time purchase. And Tab to QR turns the current Safari tab into a QR code with one click — handy for testing a page on your phone during development.
Need a Code Right Now?
Generate a static QR code in your browser — no API key, no sign-up, no upload.
Frequently Asked Questions
You don't need one. Open-source libraries such as qrcode-generator and qrcode for JavaScript, segno for Python, ZXing for Java and Core Image on Apple platforms generate QR codes free, locally and without rate limits. If other services need an HTTP endpoint, wrap a library in a small route on your own server.
No. GenerateOnlineQR.com offers a free browser-based generator and two Mac apps, but no public API. The generator itself uses the open-source qrcode-generator JavaScript library, which you can use in your own projects.
Install a QR library for your language, pass it the text or URL, choose an error-correction level such as M, and save the result as SVG or PNG with a four-module quiet zone. In Python, for example, segno.make_qr(data).save('code.svg') is enough.
Generate in the browser when the data is private or only shown on screen, because nothing is uploaded. Generate on the server when the code goes into an email, PDF, ticket or label, or when other systems need it.
Encode a short URL on your own domain as a static QR code, and add a server route that looks up the code's ID and returns a 302 redirect to the current destination. Change the destination in your database whenever you like, and track scans with UTM tags or your redirect logs.
Use M for most codes. Use Q or H if the code will carry a logo or be printed on surfaces that get scratched or dirty. Higher levels make the code denser, so keep the encoded data short.
Yes, but you don't need a hosted one: the open-source ZXing library generates QR codes in Java. Use QRCodeWriter to create a BitMatrix and MatrixToImageWriter from the javase module to write it as PNG.
A QR code API is an HTTP endpoint that receives text or a URL and returns a QR code image, usually PNG or SVG. You can use a third-party service or run your own by wrapping an open-source library such as qrcode (Node), segno (Python) or chillerlan/php-qrcode (PHP) in a single route.
Write one route that reads a data parameter, validates it (length, error-correction level, format), generates the code with an open-source library and returns the image with a long Cache-Control header. The Flask and Express examples in this guide are about twenty lines each.
Cap the input length and image size, allow-list the options, rate-limit with 429 responses, and for public use sign the URL with an HMAC so only codes your backend created are rendered.