# Barcode, QR & Logistics Label Sheet Edge API (v1.0.0)

> Generate scan-verified QR Codes, GS1-128, EAN-13, UPC-A (SVG + lossless PNG) and Avery/Zebra label sheets in <15ms.

Deterministic ISO/IEC 18004 QR Code (v1-v10 GF(256) Reed-Solomon), GS1-128 (FNC1 Application Identifiers), Code-128 (auto Set B/C), EAN-13, and UPC-A encoder returning crisp SVG, lossless binary PNG, and print-ready Avery 5160 / Zebra 4x6 & 2x1 label sheets.

## Why Agents Use This API Instead of DIY
Eliminates fragile canvas/native image binaries, broken QR Reed-Solomon/mask implementations, wrong GS1 Modulo-10/103 check digits, and misaligned Avery 5160 or Zebra thermal @page CSS.

## Connection & Payment (x402 Default + Optional Bearer API Key)
- **MCP Server (Streamable HTTP):** `https://barcode-pass.apikeg.com/mcp` (Registry ID: `com.apikeg/barcode-pass` — `initialize`, `tools/list`, `resources/*`, and `prompts/*` are free)
- **OpenAPI 3.1 Spec:** [openapi.json](https://barcode-pass.apikeg.com/openapi.json)
- **Full Schema & Examples:** [llms-full.txt](https://barcode-pass.apikeg.com/llms-full.txt)
- **RFC 9727 API Catalog:** [.well-known/api-catalog](https://barcode-pass.apikeg.com/.well-known/api-catalog)
- **x402 Bazaar Manifest:** [.well-known/x402.json](https://barcode-pass.apikeg.com/.well-known/x402.json)
- **MCP Discovery Manifest:** [.well-known/mcp.json](https://barcode-pass.apikeg.com/.well-known/mcp.json)
- **A2A Agent Card:** [.well-known/agent-card.json](https://barcode-pass.apikeg.com/.well-known/agent-card.json)
- **Primary Payment (Zero Signup):** Cloudflare Monetization Gateway (`HTTP 402` / `x402` v2 with USDC on Base).
- **Optional Monthly API Key:** Pass `Authorization: Bearer ak_live_...` ($5 / $20 / $50 monthly per-product Stripe plans at [apikeg.com/account](https://apikeg.com/account)).
- **Free Preflight:** Append `?dry_run=true` (or header `X-Dry-Run: true`) to validate any request payload at `$0.00` cost.

## Tools & REST Endpoints
- [`generate_barcode`](https://barcode-pass.apikeg.com/tools/generate-barcode.md) (`POST https://barcode-pass.apikeg.com/v1/generate-barcode`) — $0.001 USD per generated barcode or QR symbol (SVG + PNG) (x402 instant micropayment): 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.
- [`generate_label_sheet`](https://barcode-pass.apikeg.com/tools/generate-label-sheet.md) (`POST https://barcode-pass.apikeg.com/v1/generate-label-sheet`) — $0.002 base (up to $0.008 max ($0.002 base + $0.002 per 50 rendered labels, capped at $0.008 for up to 200 labels), x402 variable settlement): Batch-encodes up to 200 QR or 1D barcodes into print-ready @page HTML/SVG label sheets formatted for Avery 5160 (30-up US Letter), Zebra 4x6 shipping thermal, or Zebra 2x1 retail/bin tags.
- [`validate_gtin_check_digit`](https://barcode-pass.apikeg.com/tools/validate-gtin-check-digit.md) (`POST https://barcode-pass.apikeg.com/v1/validate-gtin-check-digit`) — $0.0005 USD per GTIN/SSCC validation request (up to 100 codes) (x402 instant micropayment): Validates or computes official GS1 Modulo-10 check digits for GTIN-8, GTIN-12 (UPC-A), GTIN-13 (EAN-13), GTIN-14, GSIN-17, and SSCC-18 identifiers (single value or batch up to 100).

## Instant MCP Configuration
```json
{
  "mcpServers": {
    "barcode-pass": {
      "type": "streamable-http",
      "url": "https://barcode-pass.apikeg.com/mcp"
    }
  }
}
```

## Common Agent Use Cases
- generate QR code PNG SVG API without dependencies
- GS1-128 barcode generator FNC1 application identifiers
- EAN-13 UPC-A check digit validator and barcode SVG
- Avery 5160 printable barcode label sheet HTML API
- Zebra 4x6 2x1 thermal shipping barcode label MCP

---

## Detailed Tool Specifications

### `generate_barcode` — Generate Barcode or QR Code (SVG + PNG)
- **REST Endpoint:** `POST https://barcode-pass.apikeg.com/v1/generate-barcode`
- **Tool Doc Page:** https://barcode-pass.apikeg.com/tools/generate-barcode
- **MCP Tool Name:** `generate_barcode`
- **Pricing:** $0.001 USD per generated barcode or QR symbol (SVG + PNG) (x402 instant micropayment)
- **Side Effects:** readOnly=true, idempotent=true, destructive=false
- **Build vs. Buy ROI:** 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.

#### 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** — Encodes GTIN-14 (01), expiry date (17), and lot/batch (10) with FNC1 and Code Set C compression.
```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 result: 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 result: ISO 18004 QR matrix with lowest-penalty mask, <svg>, and lossless pngBase64.

### `generate_label_sheet` — Generate Printable Barcode / QR Label Sheet
- **REST Endpoint:** `POST https://barcode-pass.apikeg.com/v1/generate-label-sheet`
- **Tool Doc Page:** https://barcode-pass.apikeg.com/tools/generate-label-sheet
- **MCP Tool Name:** `generate_label_sheet`
- **Pricing:** $0.002 base (up to $0.008 max ($0.002 base + $0.002 per 50 rendered labels, capped at $0.008 for up to 200 labels), x402 variable settlement)
- **Side Effects:** readOnly=true, idempotent=true, destructive=false
- **Build vs. Buy ROI:** Replaces brittle PDF/headless-Chrome pipelines with zero-margin print-accurate @page CSS + inline crisp vector SVGs for up to 200 warehouse or retail labels in a single call.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "template": {
      "type": "string",
      "enum": [
        "avery_5160",
        "zebra_4x6",
        "zebra_2x1"
      ],
      "default": "avery_5160",
      "description": "Print stock layout: 'avery_5160' (3x10 US Letter 8.5x11in, 30/page), 'zebra_4x6' (4x6in shipping/pallet thermal), or 'zebra_2x1' (2x1in retail/shelf thermal)."
    },
    "items": {
      "type": "array",
      "items": {
        "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": "Barcode or QR payload for this label."
          },
          "title": {
            "type": "string",
            "maxLength": 120,
            "description": "Primary product, bin, pallet, or attendee title printed on the label."
          },
          "subtitle": {
            "type": "string",
            "maxLength": 120,
            "description": "Secondary line (e.g. price '$24.99', lot/expiry, or warehouse location)."
          },
          "sku": {
            "type": "string",
            "maxLength": 64,
            "description": "Optional SKU or internal item code."
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 200,
            "default": 1,
            "description": "Number of identical copies of this label to emit (total sheet labels <= 200)."
          },
          "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,
        "description": "Single barcode/QR label entry within a print sheet batch."
      },
      "minItems": 1,
      "maxItems": 200,
      "description": "1 to 200 barcode/QR label definitions to render onto print-ready sheets."
    },
    "startOffset": {
      "type": "integer",
      "minimum": 0,
      "maximum": 29,
      "default": 0,
      "description": "Blank cells to skip on page 1 for partially used Avery 5160 sheets."
    },
    "includeBarcodeText": {
      "type": "boolean",
      "description": "Render human-readable text inside each barcode SVG (defaults to true for 1D, false for QR)."
    },
    "includePng": {
      "type": "boolean",
      "default": false,
      "description": "Also include lossless base64 PNGs alongside each label's inline SVG."
    },
    "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')."
    }
  },
  "required": [
    "items"
  ],
  "additionalProperties": false
}
```

#### Examples
**Avery 5160 retail SKU barcode sheet**
```bash
curl -X POST "https://barcode-pass.apikeg.com/v1/generate-label-sheet" \
  -H "Content-Type: application/json" \
  -d '{"template":"avery_5160","startOffset":0,"items":[{"format":"ean13","value":"4006381333931","title":"Neon Highlighter Yellow","subtitle":"$3.49","sku":"HL-YLW-01","quantity":15},{"format":"upca","value":"036000291452","title":"Cotton Tissue Pack","subtitle":"$5.99","sku":"CT-PK-12","quantity":15}]}'
```
Expected result: 1 US Letter page (30 labels) with inline EAN-13/UPC-A SVGs and print-ready @page HTML.

### `validate_gtin_check_digit` — Validate or Compute GS1 GTIN / SSCC Check Digit
- **REST Endpoint:** `POST https://barcode-pass.apikeg.com/v1/validate-gtin-check-digit`
- **Tool Doc Page:** https://barcode-pass.apikeg.com/tools/validate-gtin-check-digit
- **MCP Tool Name:** `validate_gtin_check_digit`
- **Pricing:** $0.0005 USD per GTIN/SSCC validation request (up to 100 codes) (x402 instant micropayment)
- **Side Effects:** readOnly=true, idempotent=true, destructive=false
- **Build vs. Buy ROI:** Prevents costly retailer/Amazon GTIN check-digit rejections and off-by-one right-to-left 3x/1x weighting bugs.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "value": {
      "type": "string",
      "minLength": 1,
      "maxLength": 64,
      "description": "Single GTIN-8, GTIN-12 (UPC-A), GTIN-13 (EAN-13), GTIN-14, GSIN-17, or SSCC-18 string to validate or complete."
    },
    "values": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 64
      },
      "minItems": 1,
      "maxItems": 100,
      "description": "Optional batch of 1 to 100 GTIN/SSCC strings to validate in a single call."
    }
  },
  "additionalProperties": false
}
```

#### Examples
**Validate EAN-13 check digit**
```bash
curl -X POST "https://barcode-pass.apikeg.com/v1/validate-gtin-check-digit" \
  -H "Content-Type: application/json" \
  -d '{"value":"4006381333931"}'
```
Expected result: valid=true, gtinType='GTIN-13', expectedCheckDigit='1'.
