Complete developer documentation for programmatic barcode generation
The Barcodes.dev REST API provides programmatic access to generate high-quality barcodes, QR codes, 2D matrix codes, and postal codes. Perfect for developers who need to integrate barcode generation into their applications, e-commerce platforms, inventory systems, and more.
Simple REST API with JSON requests and responses. Works with any programming language that supports HTTP.
Generate Code128, EAN, UPC, ISBN, QR codes, DataMatrix (with DMRE support), Aztec, postal codes, and more.
Output in PNG, JPEG, or WEBP formats with customizable sizing and colors.
Comprehensive validation with detailed error messages for debugging.
API v1: Free public access. API v2: Free tier (1,000/month) + paid tiers for high volume.
Full OpenAPI specification for code generation and interactive documentation.
https://barcodes.dev
Try this command to generate your first barcode using API v1 (no authentication required):
curl -X POST https://barcodes.dev/api/v1/barcode \ -H "Content-Type: application/json" \ -d '{"text": "Hello World", "barcode_type": "code128"}' \ --output my-first-barcode.png
💡 Pro Tip: All endpoints return PNG images by default. You can request JPEG or WEBP by setting "image_format": "JPEG"
or "image_format": "WEBP"
.
No authentication required • Rate limited for fair use • Perfect for getting started
API v1 provides free public access to basic barcode and QR code generation. No registration or API key required!
https://barcodes.dev/api/v1/
Generate Linear/1D Barcodes
Create traditional 1D barcodes including Code128, Code39, EAN, UPC, ISBN, and more. Now supports 50+ linear symbology types.
code128
, gs1
, gs1_128
, ean14
, nve18
, sscc18
, hibc_128
, dpd
ean
, ean2
, ean5
, ean8
, ean13
, upc
, upca
, upce
, isbn
, isbn10
, isbn13
, sbn
, jan
code39
, excode39
, code32
, hibc_39
, vin
, logmars
code93
, code11
, codabar
c25standard
, c25iata
, c25ind
, c25inter
, itf
, c25logic
, itf14
, dpleit
, dpident
plessey
, msi
, msi_plessey
telepen
, telepen_num
pharma
, pharmacode
, pzn
dbar_omn
, dbar_ltd
, dbar_exp
, databar_omn
, databar_ltd
, databar_exp
, gs1_databar_omn
, gs1_databar_ltd
, gs1_databar_exp
koreapost
, channel
gtin
Parameter | Type | Required | Description |
---|---|---|---|
text |
string | ✅ Yes | Data to encode in the barcode |
barcode_type |
string | ✅ Yes | Type of barcode to generate |
image_format |
string | No | Output format: PNG, JPEG, WEBP (default: PNG) |
output |
string | No | Response type: base64 or file (default: file) |
curl -X POST https://barcodes.dev/api/v1/barcode \\ -H "Content-Type: application/json" \\ -d '{ "text": "123456789012", "barcode_type": "code128", "image_format": "PNG" }' \\ --output barcode.png
200 OK - Returns binary image data with appropriate Content-Type header.
Generate QR Codes
Create QR codes with customizable error correction, colors, and sizing options.
Parameter | Type | Required | Description |
---|---|---|---|
text |
string | ✅ Yes | Data to encode in the QR code |
error_correction |
string | No | Error correction level: L, M, Q, H (default: M) |
box_size |
integer | No | Size of each box in pixels (default: 10) |
border |
integer | No | Border size in boxes (default: 4) |
image_format |
string | No | Output format: PNG, JPEG, WEBP (default: PNG) |
curl -X POST https://barcodes.dev/api/v1/qrcode \\ -H "Content-Type: application/json" \\ -d '{ "text": "https://barcodes.dev", "error_correction": "M", "box_size": 10, "border": 4, "image_format": "PNG" }' \\ --output qrcode.png
200 OK - Returns binary image data with appropriate Content-Type header.
Usage Statistics
Get current usage statistics for the public API.
curl -X GET https://barcodes.dev/api/v1/usage
200 OK
{ "success": true, "usage": { "current_hour": 15, "current_day": 243, "api_version": "v1" } }
Version Information
Get API version information and available features for the public API.
curl -X GET https://barcodes.dev/api/v1/version
200 OK
{ "version": "1.0", "api_version": "1.0", "features": ["barcode", "qrcode", "usage", "version"] }
Enhanced features • Batch processing • Account management • Higher rate limits
API v2 requires authentication but offers enhanced features and higher rate limits.
https://barcodes.dev/api/v2/
X-API-Key
headerGenerate Linear/1D Barcodes (Enhanced)
Create traditional 1D barcodes with enhanced features and both POST and GET support. Now supports 50+ linear symbology types.
code128
, gs1
, gs1_128
, ean14
, nve18
, sscc18
, hibc_128
, dpd
ean
, ean2
, ean5
, ean8
, ean13
, upc
, upca
, upce
, isbn
, isbn10
, isbn13
, sbn
, jan
code39
, excode39
, code32
, hibc_39
, vin
, logmars
code93
, code11
, codabar
c25standard
, c25iata
, c25ind
, c25inter
, itf
, c25logic
, itf14
, dpleit
, dpident
plessey
, msi
, msi_plessey
telepen
, telepen_num
pharma
, pharmacode
, pzn
dbar_omn
, dbar_ltd
, dbar_exp
, databar_omn
, databar_ltd
, databar_exp
, gs1_databar_omn
, gs1_databar_ltd
, gs1_databar_exp
koreapost
, channel
gtin
curl -X POST https://barcodes.dev/api/v2/barcode \\ -H "Content-Type: application/json" \\ -H "X-API-Key: bcd_your_api_key_here" \\ -d '{ "text": "123456789012", "barcode_type": "code128", "image_format": "PNG" }' \\ --output barcode.png
curl -X GET "https://barcodes.dev/api/v2/barcode?text=123456&barcode_type=code128" \\ -H "X-API-Key: bcd_your_api_key_here" \\ --output barcode.png
{ "success": true, "data": "iVBORw0KGgoAAAANSUhEUgAA...", "format": "PNG", "encoding": "base64", "barcode_type": "code128", "text": "123456789012", "user_tier": "free" }
Generate QR Codes (Enhanced)
Create QR codes with enhanced features and both POST and GET support.
curl -X POST https://barcodes.dev/api/v2/qrcode \\ -H "Content-Type: application/json" \\ -H "X-API-Key: bcd_your_api_key_here" \\ -d '{ "text": "https://barcodes.dev", "error_correction": "M", "box_size": 10, "border": 4, "image_format": "PNG" }' \\ --output qrcode.png
curl -X GET "https://barcodes.dev/api/v2/qrcode?text=https://barcodes.dev&error_correction=M" \\ -H "X-API-Key: bcd_your_api_key_here" \\ --output qrcode.png
Generate 2D Matrix Codes
Create 2D matrix codes including DataMatrix (with DMRE support), Aztec, MaxiCode, and more advanced 2D formats.
datamatrix
, aztec
, maxicode
, codeone
, gridmatrix
, dotcode
, hanxin
, microqr
, rmqr
, upnqr
curl -X POST https://barcodes.dev/api/v2/2d \\ -H "Content-Type: application/json" \\ -H "X-API-Key: bcd_your_api_key_here" \\ -d '{ "text": "Sample DataMatrix with DMRE", "twod_type": "datamatrix", "shape": "dmre", "scale_factor": 8, "image_format": "PNG" }' \\ --output datamatrix.png
curl -X GET "https://barcodes.dev/api/v2/2d?text=Sample%20Data&twod_type=datamatrix&shape=dmre" \\ -H "X-API-Key: bcd_your_api_key_here" \\ --output datamatrix.png
Generate Postal Codes
Create postal barcodes for various national postal services including USPS, Royal Mail, Australia Post, and more.
usps_imd
, usps_postnet
, usps_planet
, royal_mail
, ukroyalmail
, australia_post
, auspost
, netherlands_kix
, japan_post
, japanpost
, korea_post
curl -X POST https://barcodes.dev/api/v2/postal \\ -H "Content-Type: application/json" \\ -H "X-API-Key: bcd_your_api_key_here" \\ -d '{ "text": "12345678901", "postal_type": "usps_imd", "height": 50, "image_format": "PNG" }' \\ --output postal.png
curl -X GET "https://barcodes.dev/api/v2/postal?text=12345678901&postal_type=usps_imd" \\ -H "X-API-Key: bcd_your_api_key_here" \\ --output postal.png
Generate Stacked Codes
Create stacked barcode formats including PDF417, MicroPDF417, and other multi-row barcode types.
pdf417
, pdf417comp
, micropdf417
, codablock_f
, code16k
, code49
, gs1_databar_stacked
, gs1_databar_stacked_omni
, gs1_databar_expanded_stacked
curl -X POST https://barcodes.dev/api/v2/stacked \\ -H "Content-Type: application/json" \\ -H "X-API-Key: bcd_your_api_key_here" \\ -d '{ "text": "PDF417 Stacked Data", "stacked_type": "pdf417", "height": 80, "columns": 6, "image_format": "PNG" }' \\ --output stacked.png
curl -X GET "https://barcodes.dev/api/v2/stacked?text=PDF417%20Data&stacked_type=pdf417" \\ -H "X-API-Key: bcd_your_api_key_here" \\ --output stacked.png
Generate Composite Codes
Create composite barcode symbols that combine linear and 2D components for enhanced data encoding.
gs1_128_cc
, eanx_cc
, upca_cc
, upce_cc
, dbar_omn_cc
, dbar_ltd_cc
, dbar_exp_cc
, dbar_stk_cc
, dbar_omnstk_cc
, dbar_expstk_cc
curl -X POST https://barcodes.dev/api/v2/composite \\ -H "Content-Type: application/json" \\ -H "X-API-Key: bcd_your_api_key_here" \\ -d '{ "text": "^010123456789012815170719", "primary_data": "(01)01234567890128(15)170719", "composite_type": "gs1_128_cc", "cc_mode": 2, "image_format": "PNG" }' \\ --output composite.png
curl -X GET "https://barcodes.dev/api/v2/composite?text=^010123456789012815170719&primary_data=(01)01234567890128(15)170719&composite_type=gs1_128_cc" \\ -H "X-API-Key: bcd_your_api_key_here" \\ --output composite.png
Batch Generation (POST Only)
Generate multiple barcodes and QR codes in a single request. Maximum 10 items per batch.
curl -X POST https://barcodes.dev/api/v2/batch \\ -H "Content-Type: application/json" \\ -H "X-API-Key: bcd_your_api_key_here" \\ -d '{ "batch": [ { "type": "barcode", "text": "BATCH-001", "barcode_type": "code128", "image_format": "PNG" }, { "type": "qrcode", "text": "https://example.com", "error_correction": "M" } ] }'
{ "success": true, "batch_results": [ { "index": 0, "success": true, "data": "base64_encoded_barcode", "format": "PNG", "encoding": "base64" }, { "index": 1, "success": true, "data": "base64_encoded_qrcode", "format": "PNG", "encoding": "base64" } ], "total_processed": 2, "user_tier": "free" }
Account Information (GET Only)
Get detailed account information including usage stats and tier details.
curl -X GET https://barcodes.dev/api/v2/account \\ -H "X-API-Key: bcd_your_api_key_here"
{ "success": true, "account": { "id": 123, "email": "user@example.com", "tier": "free", "active": true, "created_at": "2024-01-01T00:00:00", "monthly_limit": 1000, "current_usage": 150, "remaining": 850 } }
Enhanced Usage Statistics (GET Only)
Get detailed usage statistics with account information and tier details.
curl -X GET https://barcodes.dev/api/v2/usage \\ -H "X-API-Key: bcd_your_api_key_here"
{ "success": true, "usage": { "current_hour": 15, "current_day": 243, "current_month": 850, "monthly_limit": 1000, "remaining": 150, "reset_date": "2025-11-01T00:00:00Z" }, "account": { "tier": "free", "api_version": "v2" } }
This section provides structured information optimized for AI assistants and code generation tools:
API Purpose: Generate barcodes programmatically via REST API
Base URL: https://barcodes.dev
Authentication: v1: None required, v2: API key required
Content-Type: application/json
Response: Binary image data (PNG/JPEG/WEBP) or JSON with base64
Prompt: "Generate a function that creates a Code128 barcode using the barcodes.dev API"
Prompt: "Create error handling for barcode API responses"
Prompt: "Build a React component that generates QR codes with custom colors"
Prompt: "Write a Python script to batch generate barcodes from a CSV file"
{ "api_versions": { "v1": { "authentication": "None required", "rate_limiting": "Fair use policy", "features": "Basic generation, public access", "supported_methods": ["POST", "GET"] }, "v2": { "authentication": "API key required (X-API-Key header)", "rate_limiting": "Tier-based limits (1,000/month free)", "features": "Enhanced responses, batch processing, account management, GET/POST support", "supported_methods": ["POST", "GET"] } }, "v1_endpoints": { "/api/v1/barcode": { "methods": ["POST"], "purpose": "Generate 1D barcodes - Public access", "required": ["text", "barcode_type"], "optional": ["image_format", "output"], "authentication": "None" }, "/api/v1/qrcode": { "methods": ["POST"], "purpose": "Generate QR codes - Public access", "required": ["text"], "optional": ["error_correction", "image_format", "fill_color", "back_color", "box_size", "border"], "authentication": "None" }, "/api/v1/usage": { "methods": ["GET"], "purpose": "Get basic usage statistics", "required": [], "optional": [], "authentication": "None" }, "/api/v1/version": { "methods": ["GET"], "purpose": "Get API version information and features", "required": [], "optional": [], "authentication": "None" } }, "v2_endpoints": { "/api/v2/barcode": { "methods": ["POST", "GET"], "purpose": "Generate 1D barcodes with enhanced features", "required": ["text", "barcode_type"], "optional": ["image_format", "output"], "authentication": "API key required" }, "/api/v2/qrcode": { "methods": ["POST", "GET"], "purpose": "Generate QR codes with enhanced features", "required": ["text"], "optional": ["error_correction", "image_format", "fill_color", "back_color", "box_size", "border"], "authentication": "API key required" }, "/api/v2/2d": { "methods": ["POST", "GET"], "purpose": "Generate 2D matrix codes including DataMatrix with DMRE support", "required": ["text"], "optional": ["twod_type", "shape", "scale_factor", "image_format", "output"], "authentication": "API key required" }, "/api/v2/postal": { "methods": ["POST", "GET"], "purpose": "Generate postal barcodes for various national services", "required": ["text"], "optional": ["postal_type", "height", "image_format", "output"], "authentication": "API key required" }, "/api/v2/stacked": { "methods": ["POST", "GET"], "purpose": "Generate stacked barcode formats like PDF417", "required": ["text"], "optional": ["stacked_type", "height", "columns", "rows", "image_format", "output"], "authentication": "API key required" }, "/api/v2/composite": { "methods": ["POST", "GET"], "purpose": "Generate composite barcode symbols with linear and 2D components", "required": ["text", "primary_data"], "optional": ["composite_type", "height", "cc_mode", "cc_columns", "image_format", "output"], "authentication": "API key required" }, "/api/v2/batch": { "methods": ["POST"], "purpose": "Generate multiple barcodes/QR codes in one request (max 10)", "required": ["batch"], "optional": [], "authentication": "API key required" }, "/api/v2/account": { "methods": ["GET"], "purpose": "Get account information and usage statistics", "required": [], "optional": [], "authentication": "API key required" }, "/api/v2/usage": { "methods": ["GET"], "purpose": "Get enhanced usage statistics with account details", "required": [], "optional": [], "authentication": "API key required" } }, "supported_formats": ["PNG", "JPEG", "WEBP"], "output_modes": ["file", "base64"], "error_handling": "HTTP status codes + JSON error messages" }
Use Case: Generate product barcodes for inventory
Best Endpoint: /api/v1/barcode
or /api/v2/barcode
Recommended Types: EAN13, UPC-A, Code128
Use Case: QR codes for document tracking
Best Endpoint: /api/v1/qrcode
or /api/v2/qrcode
Features: Custom colors, error correction
Use Case: Generate multiple codes at once
Best Endpoint: /api/v2/batch
(API key required)
Features: Up to 10 codes per request, mixed types
Use Case: Monitor API usage and limits
Best Endpoint: /api/v2/account
(API key required)
Features: Usage stats, tier information
Complete, production-ready examples with error handling and best practices:
AI Context: Production-ready Python function with comprehensive error handling, logging, and type hints. Suitable for integration into web applications, CLI tools, or automation scripts.
import requests import logging from typing import Optional, Dict, Any from pathlib import Path def generate_barcode( text: str, barcode_type: str = 'code128', image_format: str = 'PNG', output_path: Optional[str] = None, base_url: str = 'https://barcodes.dev' ) -> Dict[str, Any]: """ Generate a barcode using the barcodes.dev API. Args: text: Data to encode in the barcode barcode_type: Type of barcode (code128, ean13, upca, etc.) image_format: Output format (PNG, JPEG, WEBP) output_path: File path to save the barcode (optional) base_url: API base URL Returns: Dict with success status, file path (if saved), and any error info """ try: # Prepare request payload payload = { 'text': text, 'barcode_type': barcode_type, 'image_format': image_format } # Make API request (using v1 for simplicity - no authentication required) response = requests.post( f'{base_url}/api/v1/barcode', json=payload, timeout=30, headers={'User-Agent': 'BarcodeGenerator/1.0'} ) # Handle response if response.status_code == 200: # Save to file if path provided if output_path: file_path = Path(output_path) file_path.parent.mkdir(parents=True, exist_ok=True) with open(file_path, 'wb') as f: f.write(response.content) logging.info(f"Barcode saved to {file_path}") return { 'success': True, 'file_path': str(file_path), 'size_bytes': len(response.content) } else: return { 'success': True, 'data': response.content, 'size_bytes': len(response.content) } else: # Parse error response try: error_data = response.json() error_msg = error_data.get('message', 'Unknown error') except: error_msg = f"HTTP {response.status_code}" logging.error(f"Barcode generation failed: {error_msg}") return { 'success': False, 'error': error_msg, 'status_code': response.status_code } except requests.exceptions.RequestException as e: logging.error(f"Network error: {e}") return { 'success': False, 'error': f"Network error: {e}" } except Exception as e: logging.error(f"Unexpected error: {e}") return { 'success': False, 'error': f"Unexpected error: {e}" } # Example usage if __name__ == "__main__": # Configure logging logging.basicConfig(level=logging.INFO) # Generate and save barcode result = generate_barcode( text='PROD-12345-ABC', barcode_type='code128', output_path='./barcodes/product_12345.png' ) if result['success']: print(f"✅ Barcode generated: {result.get('file_path', 'in memory')}") else: print(f"❌ Error: {result['error']}")
const fs = require('fs'); const fetch = require('node-fetch'); async function generateBarcode() { const response = await fetch('https://barcodes.dev/api/barcode', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text: '123456789012', barcode_type: 'code128', image_format: 'PNG' }) }); if (response.ok) { const buffer = await response.buffer(); fs.writeFileSync('barcode.png', buffer); console.log('Barcode saved successfully!'); } else { const error = await response.json(); console.error('Error:', error); } } generateBarcode();
$data = json_encode([ 'text' => '123456789012', 'barcode_type' => 'code128', 'image_format' => 'PNG' ]); $context = stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => 'Content-Type: application/json', 'content' => $data ] ]); $response = file_get_contents('https://barcodes.dev/api/barcode', false, $context); if ($response !== false) { file_put_contents('barcode.png', $response); echo "Barcode saved successfully!"; } else { echo "Error generating barcode"; }
# Generate QR Code curl -X POST https://barcodes.dev/api/qrcode \\ -H "Content-Type: application/json" \\ -d '{ "text": "https://barcodes.dev", "error_correction": "M", "image_format": "PNG" }' \\ --output qrcode.png # Generate DataMatrix with DMRE support (API v2) curl -X POST https://barcodes.dev/api/v2/2d \\ -H "Content-Type: application/json" \\ -H "X-API-Key: bcd_your_api_key_here" \\ -d '{ "text": "Sample data with DMRE", "twod_type": "datamatrix", "shape": "dmre", "image_format": "PNG" }' \\ --output datamatrix.png # Generate Postal Code curl -X POST https://barcodes.dev/api/v2/postal \\ -H "Content-Type: application/json" \\ -H "X-API-Key: bcd_your_api_key_here" \\ -d '{ "text": "12345678901", "postal_type": "usps_imd", "image_format": "PNG" }' \\ --output postal.png
Get the complete OpenAPI 3.0 specification for automatic code generation and interactive documentation:
📄 Download: swagger.yaml
🛠️ Use Cases:
Use AI chatbots to generate client libraries by providing the OpenAPI specification URL. Here are example prompts:
Create a Python client library for the API defined at https://barcodes.dev/swagger.yaml.
Requirements:
- Support both v1 (public) and v2 (authenticated) endpoints
- Use X-API-Key header for v2 authentication
- Include methods for: barcode generation, QR codes, 2D codes, postal codes, stacked codes, composite codes, and batch processing
- Handle both binary image responses and JSON responses
- Include proper error handling and rate limiting
- Base URL: https://barcodes.dev
Key endpoints to implement:
- POST /api/v1/barcode (public)
- POST /api/v2/barcode (authenticated)
- POST /api/v2/batch (authenticated)
- GET /api/v2/account (authenticated)
Create a JavaScript/Node.js client for the Barcodes.dev API using the OpenAPI spec at https://barcodes.dev/swagger.yaml.
Requirements:
- ES6 class-based client with async/await
- Support for both browser and Node.js environments
- API key authentication for v2 endpoints
- TypeScript type definitions
- Built-in retry logic and error handling
- Examples for all endpoint types
Simply adapt the prompts above for your preferred language (Java, C#, Go, PHP, etc.) and include language-specific requirements.
💡 Pro Tip: The more specific you are about your requirements (error handling, authentication, response parsing), the better client code you'll get!
🎉 Two API Versions Available! Choose between anonymous access (v1) or enhanced authenticated features (v2).
We provide flexible options to support developers and businesses worldwide. To ensure fair access for everyone, please use the API responsibly and follow these guidelines:
While we don't impose hard rate limits, we actively monitor usage patterns. Users who abuse this free service or violate fair use guidelines may face temporary or permanent restrictions, including rate limiting or IP blocking. For high-volume commercial use, please contact us to discuss appropriate solutions that ensure service stability for all users.
We're constantly improving! Send us your feedback to help make the API even better.