# `generate_barcode` — Generate Barcode or QR Code (SVG + PNG)

> Part of [Barcode, QR & Logistics Label Sheet Edge API](https://barcode-pass.apikeg.com/llms.txt) (`com.apikeg/barcode-pass`)

Encodes a single QR Code (ISO 18004 v1-v10), Code-128, GS1-128, EAN-13, or UPC-A symbol, validating/computing GS1 check digits and returning both crisp vector SVG and lossless binary base64 PNG.

**Why call instead of DIY:** Avoids 800+ lines of GF(256) Reed-Solomon, BCH format/version masking, GS1 FNC1/Mod-103 tables, and binary PNG DEFLATE+CRC32 framing; executes at the edge in <10ms.

- **REST Endpoint:** `POST https://barcode-pass.apikeg.com/v1/generate-barcode`
- **MCP Server:** `https://barcode-pass.apikeg.com/mcp` (tool: `generate_barcode`)
- **Pricing:** $0.001 USD per generated barcode or QR symbol (SVG + PNG) (x402 instant micropayment)
- **Free Dry-Run:** `POST https://barcode-pass.apikeg.com/v1/generate-barcode?dry_run=true`

## Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "format": {
      "type": "string",
      "enum": [
        "qr",
        "code128",
        "gs1_128",
        "ean13",
        "upca"
      ],
      "description": "Symbology format: 'qr' (ISO 18004 v1-v10 UTF-8), 'code128' (Set B/C auto-packed), 'gs1_128' (GS1 Application Identifiers with FNC1), 'ean13' (GTIN-13), or 'upca' (GTIN-12)."
    },
    "value": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1024,
      "description": "Payload to encode (UTF-8 string/URL for QR; printable ASCII for code128; '(01)...' AI string for gs1_128; 12/13 digits for ean13; 11/12 digits for upca)."
    },
    "scale": {
      "type": "integer",
      "minimum": 1,
      "maximum": 24,
      "description": "Pixels per module (defaults to 4 for QR and 2 for 1D linear barcodes)."
    },
    "barHeight": {
      "type": "integer",
      "minimum": 20,
      "maximum": 400,
      "description": "Bar height in pixels for 1D linear barcodes (defaults to 72)."
    },
    "quietZone": {
      "type": "integer",
      "minimum": 0,
      "maximum": 32,
      "description": "Quiet zone margin in modules (defaults to ISO standard: 4 for QR, 9-11 for 1D)."
    },
    "includeText": {
      "type": "boolean",
      "description": "Render human-readable text beneath symbol (defaults to true for 1D, false for QR)."
    },
    "label": {
      "type": "string",
      "maxLength": 120,
      "description": "Optional custom human-readable caption override beneath the barcode."
    },
    "foreground": {
      "type": "string",
      "maxLength": 16,
      "description": "Foreground bar/module hex color (#RGB or #RRGGBB, default '#000000')."
    },
    "background": {
      "type": "string",
      "maxLength": 16,
      "description": "Background hex color (#RGB or #RRGGBB, default '#FFFFFF')."
    },
    "errorCorrection": {
      "type": "string",
      "enum": [
        "L",
        "M",
        "Q",
        "H"
      ],
      "default": "M",
      "description": "QR Code Reed-Solomon error correction level: L (~7%), M (~15%), Q (~25%), H (~30%)."
    }
  },
  "required": [
    "format",
    "value"
  ],
  "additionalProperties": false
}
```

## Examples
### Generate GS1-128 pallet/carton logistics barcode
```bash
curl -X POST "https://barcode-pass.apikeg.com/v1/generate-barcode" \
  -H "Content-Type: application/json" \
  -d '{"format":"gs1_128","value":"(01)09501101530003(17)271231(10)BATCH42","scale":2,"barHeight":80}'
```
Expected output: Normalized GS1-128 string, dimensions, crisp <svg>, and lossless pngBase64.
### Generate high-resiliency QR Code
```bash
curl -X POST "https://barcode-pass.apikeg.com/v1/generate-barcode" \
  -H "Content-Type: application/json" \
  -d '{"format":"qr","value":"https://barcode-pass.apikeg.com/verify/PASS-9481","errorCorrection":"Q","scale":5}'
```
Expected output: ISO 18004 QR matrix with lowest-penalty mask, <svg>, and lossless pngBase64.
