# Executive SVG Chart & KPI Card Compiler Edge API (v1.0.0)

> Compile board-ready SVG charts (waterfall, funnel, gantt, bar, line) and KPI sparkline cards with zero overlapping labels in <10ms.

Deterministic publication-grade standalone SVG chart compiler (bar, stacked_bar, horizontal_bar, line, area, waterfall, funnel, gantt) and multi-metric KPI sparkline snapshot cards with mathematically verified zero-overlap text layout.

## Why Agents Use This API Instead of DIY
Eliminates clipped axes, overlapping x-axis text, broken floating-point tick steps, heavyweight headless-browser Chart.js/Playwright containers, and thousands of wasted LLM tokens generating raw SVG coordinates.

## Connection & Payment (x402 Default + Optional Bearer API Key)
- **MCP Server (Streamable HTTP):** `https://chart-viz.apikeg.com/mcp` (Registry ID: `com.apikeg/chart-viz` — `initialize`, `tools/list`, `resources/*`, and `prompts/*` are free)
- **OpenAPI 3.1 Spec:** [openapi.json](https://chart-viz.apikeg.com/openapi.json)
- **Full Schema & Examples:** [llms-full.txt](https://chart-viz.apikeg.com/llms-full.txt)
- **RFC 9727 API Catalog:** [.well-known/api-catalog](https://chart-viz.apikeg.com/.well-known/api-catalog)
- **x402 Bazaar Manifest:** [.well-known/x402.json](https://chart-viz.apikeg.com/.well-known/x402.json)
- **MCP Discovery Manifest:** [.well-known/mcp.json](https://chart-viz.apikeg.com/.well-known/mcp.json)
- **A2A Agent Card:** [.well-known/agent-card.json](https://chart-viz.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
- [`render_chart`](https://chart-viz.apikeg.com/tools/render-chart.md) (`POST https://chart-viz.apikeg.com/v1/render-chart`) — $0.002 USD per rendered executive SVG chart (x402 instant micropayment): Compiles structured business data into a crisp standalone SVG + base64 data URI across bar, stacked_bar, horizontal_bar, line, area, waterfall, funnel, and gantt chart types, returning a verified zero-overlap layoutReport.
- [`render_kpi_card`](https://chart-viz.apikeg.com/tools/render-kpi-card.md) (`POST https://chart-viz.apikeg.com/v1/render-kpi-card`) — $0.001 USD per executive KPI snapshot card (1-6 tiles) (x402 instant micropayment): Renders 1-6 executive KPI summary tiles with formatted headline values ($1.2M, 45.3%), semantic trend pills (+14.2% MoM), and inline SVG sparklines ready for Slack, Notion, Email, PDFs, or slide decks.

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

## Common Agent Use Cases
- generate standalone SVG chart API for Slack Notion PDF
- executive waterfall bridge chart SVG MCP tool
- KPI summary card with sparklines SVG generator
- conversion funnel and Gantt timeline SVG API
- collision-free chart rendering for AI agents

---

## Detailed Tool Specifications

### `render_chart` — Render Publication-Grade Executive SVG Chart
- **REST Endpoint:** `POST https://chart-viz.apikeg.com/v1/render-chart`
- **Tool Doc Page:** https://chart-viz.apikeg.com/tools/render-chart
- **MCP Tool Name:** `render_chart`
- **Pricing:** $0.002 USD per rendered executive SVG chart (x402 instant micropayment)
- **Side Effects:** readOnly=true, idempotent=true, destructive=false
- **Build vs. Buy ROI:** Replaces fragile headless Chromium/Canvas chart pipelines and LLM-hallucinated SVG paths with deterministic Heckbert scales and SAT text collision resolution at $0.002/chart in <10ms.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "chartType": {
      "type": "string",
      "enum": [
        "bar",
        "stacked_bar",
        "horizontal_bar",
        "line",
        "area",
        "waterfall",
        "funnel",
        "gantt"
      ],
      "description": "Enterprise chart type: 'bar', 'stacked_bar', 'horizontal_bar', 'line', 'area', 'waterfall', 'funnel', or 'gantt'."
    },
    "title": {
      "type": "string",
      "maxLength": 180,
      "description": "Executive headline chart title."
    },
    "subtitle": {
      "type": "string",
      "maxLength": 220,
      "description": "Context subtitle (timeframe, unit scope, or cohort)."
    },
    "footnote": {
      "type": "string",
      "maxLength": 240,
      "description": "Source attribution or footnote rendered along the bottom edge."
    },
    "width": {
      "type": "integer",
      "default": 840,
      "minimum": 360,
      "maximum": 2400,
      "description": "Target SVG viewport width in pixels."
    },
    "height": {
      "type": "integer",
      "default": 480,
      "minimum": 240,
      "maximum": 1800,
      "description": "Target SVG viewport height in pixels (auto-expands if dense rows/margins require it)."
    },
    "palette": {
      "type": "string",
      "enum": [
        "corporate",
        "slate",
        "emerald",
        "dark"
      ],
      "default": "corporate",
      "description": "Accessible executive palette ('corporate', 'slate', 'emerald', or 'dark')."
    },
    "valueFormat": {
      "type": "string",
      "enum": [
        "compact",
        "currency",
        "percent",
        "percent_ratio",
        "integer",
        "decimal",
        "raw"
      ],
      "default": "compact",
      "description": "Axis and data-label formatter ('compact' -> 12.4K, 'currency' -> $1.2M, 'percent' -> 45.3%, 'percent_ratio' -> 0.453 as 45.3%, 'integer', 'decimal', 'raw')."
    },
    "currencySymbol": {
      "type": "string",
      "default": "$",
      "maxLength": 8,
      "description": "Currency symbol prefix used when valueFormat is 'currency'."
    },
    "unitSuffix": {
      "type": "string",
      "default": "",
      "maxLength": 16,
      "description": "Optional unit suffix appended to formatted values (e.g. ' ms', 'x')."
    },
    "xAxisLabel": {
      "type": "string",
      "maxLength": 120,
      "description": "Optional horizontal axis title."
    },
    "yAxisLabel": {
      "type": "string",
      "maxLength": 120,
      "description": "Optional vertical axis title."
    },
    "showDataLabels": {
      "type": "boolean",
      "description": "Render collision-checked value labels directly on bars/points."
    },
    "showLegend": {
      "type": "boolean",
      "description": "Override automatic legend visibility."
    },
    "showGrid": {
      "type": "boolean",
      "default": true,
      "description": "Render subtle dashed reference gridlines."
    },
    "includeZero": {
      "type": "boolean",
      "description": "Force numeric scale to include the 0 baseline."
    },
    "categories": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1,
        "maxLength": 160
      },
      "minItems": 1,
      "maxItems": 120,
      "description": "Category or time-bucket labels for bar, stacked_bar, horizontal_bar, line, and area charts."
    },
    "series": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "Series legend name (e.g. 'Enterprise ARR' or 'FY26 Actuals')."
          },
          "values": {
            "type": "array",
            "items": {
              "type": "number",
              "description": "Numeric data values corresponding 1:1 with categories."
            },
            "minItems": 1,
            "maxItems": 120,
            "description": "Ordered numeric values matching categories length."
          },
          "color": {
            "type": "string",
            "maxLength": 32,
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "description": "Optional 6-digit hex color override (e.g. '#1D4ED8')."
          }
        },
        "required": [
          "name",
          "values"
        ],
        "additionalProperties": false,
        "description": "Named numeric data series."
      },
      "minItems": 1,
      "maxItems": 12,
      "description": "1 to 12 data series for Cartesian charts."
    },
    "referenceLine": {
      "type": "object",
      "properties": {
        "value": {
          "type": "number",
          "description": "Target or threshold axis value for the dashed reference line."
        },
        "label": {
          "type": "string",
          "maxLength": 100,
          "description": "Optional callout badge text (defaults to 'Target: <formatted value>')."
        },
        "color": {
          "type": "string",
          "maxLength": 32,
          "pattern": "^#[0-9A-Fa-f]{6}$",
          "description": "Optional 6-digit hex color override for the reference line."
        }
      },
      "required": [
        "value"
      ],
      "additionalProperties": false,
      "description": "Optional target/threshold reference line."
    },
    "waterfallSteps": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "Bridge step label (e.g. 'Opening ARR', 'Expansion', 'Churn', 'Ending ARR')."
          },
          "kind": {
            "type": "string",
            "enum": [
              "start",
              "delta",
              "subtotal",
              "total"
            ],
            "description": "Bridge step role: 'start' (initial baseline), 'delta' (+/- bridge change), 'subtotal' (running intermediate total), or 'total' (final total)."
          },
          "value": {
            "type": "number",
            "description": "Step amount. Required for 'start' and 'delta'; optional for 'subtotal' and 'total' (auto-computed from running balance when omitted)."
          }
        },
        "required": [
          "label",
          "kind"
        ],
        "additionalProperties": false,
        "description": "Executive waterfall financial/ops bridge step."
      },
      "minItems": 2,
      "maxItems": 40,
      "description": "Ordered bridge steps for 'waterfall' charts."
    },
    "funnelStages": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "description": "Conversion funnel stage name (e.g. 'Qualified Pipeline')."
          },
          "value": {
            "type": "number",
            "minimum": 0,
            "description": "Non-negative volume or revenue at this stage."
          },
          "color": {
            "type": "string",
            "maxLength": 32,
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "description": "Optional 6-digit hex color override."
          }
        },
        "required": [
          "label",
          "value"
        ],
        "additionalProperties": false,
        "description": "Conversion funnel stage."
      },
      "minItems": 2,
      "maxItems": 20,
      "description": "Ordered conversion stages for 'funnel' charts."
    },
    "ganttTasks": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "maxLength": 64,
            "description": "Optional caller task identifier."
          },
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 140,
            "description": "Workstream or milestone title."
          },
          "start": {
            "type": "string",
            "minLength": 8,
            "maxLength": 40,
            "description": "ISO 8601 start date (e.g. '2026-04-01')."
          },
          "end": {
            "type": "string",
            "minLength": 8,
            "maxLength": 40,
            "description": "ISO 8601 end date (e.g. '2026-04-21'). Omit or match start for milestones."
          },
          "group": {
            "type": "string",
            "maxLength": 80,
            "description": "Optional swimlane/owner prefix (e.g. 'Platform' or 'GTM')."
          },
          "progress": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "description": "Optional completion percentage [0-100] rendered inside the bar."
          },
          "milestone": {
            "type": "boolean",
            "description": "Set true to render as a diamond milestone marker."
          },
          "color": {
            "type": "string",
            "maxLength": 32,
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "description": "Optional 6-digit hex color override."
          }
        },
        "required": [
          "label",
          "start"
        ],
        "additionalProperties": false,
        "description": "Gantt timeline task or milestone row."
      },
      "minItems": 1,
      "maxItems": 60,
      "description": "Timeline tasks and milestones for 'gantt' charts."
    },
    "ganttMilestones": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100,
            "description": "Vertical milestone callout label (e.g. 'GA Launch')."
          },
          "date": {
            "type": "string",
            "minLength": 8,
            "maxLength": 40,
            "description": "ISO 8601 milestone date (e.g. '2026-06-01')."
          },
          "color": {
            "type": "string",
            "maxLength": 32,
            "pattern": "^#[0-9A-Fa-f]{6}$",
            "description": "Optional 6-digit hex color override."
          }
        },
        "required": [
          "label",
          "date"
        ],
        "additionalProperties": false,
        "description": "Vertical milestone guide line across the Gantt timeline."
      },
      "minItems": 1,
      "maxItems": 12,
      "description": "Optional vertical milestone guide lines for 'gantt' charts."
    }
  },
  "required": [
    "chartType"
  ],
  "additionalProperties": false
}
```

#### Examples
**FY26 ARR Financial Waterfall Bridge** — Renders start, positive/negative deltas, subtotal, and ending ARR with dashed connectors.
```bash
curl -X POST "https://chart-viz.apikeg.com/v1/render-chart" \
  -H "Content-Type: application/json" \
  -d '{"chartType":"waterfall","title":"FY26 Net ARR Bridge","subtitle":"Consolidated SaaS ($USD)","palette":"corporate","valueFormat":"currency","currencySymbol":"$","unitSuffix":"","width":840,"height":480,"showGrid":true,"waterfallSteps":[{"label":"Opening ARR","value":4200000,"kind":"start"},{"label":"New Logos","value":1150000,"kind":"delta"},{"label":"Expansion","value":680000,"kind":"delta"},{"label":"Gross ARR","kind":"subtotal"},{"label":"Contraction","value":-210000,"kind":"delta"},{"label":"Logo Churn","value":-320000,"kind":"delta"},{"label":"Ending ARR","kind":"total"}]}'
```
Expected result: Standalone 840x480 SVG + data:image/svg+xml;base64 URI with zeroOverlapsVerified=true.
**Product Launch Gantt Timeline with Milestones**
```bash
curl -X POST "https://chart-viz.apikeg.com/v1/render-chart" \
  -H "Content-Type: application/json" \
  -d '{"chartType":"gantt","title":"Enterprise v2.0 Launch Plan","palette":"slate","valueFormat":"compact","currencySymbol":"$","unitSuffix":"","width":840,"height":420,"showGrid":true,"ganttTasks":[{"label":"Security Audit","group":"Infra","start":"2026-04-01","end":"2026-04-18","progress":100},{"label":"Beta Cohort","group":"Product","start":"2026-04-15","end":"2026-05-10","progress":65},{"label":"GA Launch","group":"GTM","start":"2026-05-15","milestone":true}]}'
```
Expected result: Standalone Gantt SVG with auto-sized left task gutter, UTC date ticks, progress bars, and milestone diamond.

### `render_kpi_card` — Render Executive KPI Snapshot Card
- **REST Endpoint:** `POST https://chart-viz.apikeg.com/v1/render-kpi-card`
- **Tool Doc Page:** https://chart-viz.apikeg.com/tools/render-kpi-card
- **MCP Tool Name:** `render_kpi_card`
- **Pricing:** $0.001 USD per executive KPI snapshot card (1-6 tiles) (x402 instant micropayment)
- **Side Effects:** readOnly=true, idempotent=true, destructive=false
- **Build vs. Buy ROI:** Instant board-grade visual metric snapshot with proportional typography and zero-overlap verification at $0.001/card.

#### Input JSON Schema
```json
{
  "type": "object",
  "properties": {
    "title": {
      "type": "string",
      "maxLength": 160,
      "description": "Optional executive card header title."
    },
    "subtitle": {
      "type": "string",
      "maxLength": 200,
      "description": "Optional card subtitle or reporting period."
    },
    "footnote": {
      "type": "string",
      "maxLength": 200,
      "description": "Optional footer attribution note."
    },
    "palette": {
      "type": "string",
      "enum": [
        "corporate",
        "slate",
        "emerald",
        "dark"
      ],
      "default": "corporate",
      "description": "Accessible executive color palette ('corporate', 'slate', 'emerald', or 'dark')."
    },
    "columns": {
      "type": "integer",
      "minimum": 1,
      "maximum": 3,
      "description": "Grid column count (1-3). Defaults automatically from tile count."
    },
    "width": {
      "type": "integer",
      "minimum": 320,
      "maximum": 2400,
      "description": "SVG width in pixels (defaults to 400/680/940 for 1/2/3 columns)."
    },
    "metrics": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "label": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "description": "KPI tile metric title (e.g. 'Net New ARR', 'Gross Margin', 'NDR')."
          },
          "value": {
            "type": "number",
            "description": "Headline numeric metric value."
          },
          "displayValue": {
            "type": "string",
            "maxLength": 40,
            "description": "Optional custom pre-formatted headline override (e.g. '4.2 mos')."
          },
          "format": {
            "type": "string",
            "enum": [
              "compact",
              "currency",
              "percent",
              "percent_ratio",
              "integer",
              "decimal",
              "raw"
            ],
            "default": "compact",
            "description": "Number format for headline value ('currency', 'percent', 'compact', etc.)."
          },
          "currencySymbol": {
            "type": "string",
            "default": "$",
            "maxLength": 8,
            "description": "Currency symbol when format is 'currency'."
          },
          "unitSuffix": {
            "type": "string",
            "default": "",
            "maxLength": 16,
            "description": "Optional unit suffix (e.g. ' bps', 'x')."
          },
          "decimals": {
            "type": "integer",
            "minimum": 0,
            "maximum": 4,
            "description": "Optional fixed decimal precision override."
          },
          "deltaText": {
            "type": "string",
            "maxLength": 48,
            "description": "Explicit trend pill text (e.g. '+14.2% MoM' or '-40 bps QoQ')."
          },
          "deltaPercent": {
            "type": "number",
            "description": "Numeric percentage change used to build the trend pill when deltaText is omitted (e.g. 14.2 -> '+14.2%')."
          },
          "deltaPeriod": {
            "type": "string",
            "maxLength": 24,
            "description": "Comparison window appended to deltaPercent (e.g. 'MoM', 'QoQ', 'YoY')."
          },
          "sentiment": {
            "type": "string",
            "enum": [
              "positive",
              "negative",
              "neutral"
            ],
            "description": "Explicit trend pill color semantics ('positive', 'negative', or 'neutral')."
          },
          "invertSentiment": {
            "type": "boolean",
            "description": "Set true when negative deltas are good (e.g. Churn Rate, CAC Payback, P99 Latency)."
          },
          "sparkline": {
            "type": "array",
            "items": {
              "type": "number"
            },
            "minItems": 2,
            "maxItems": 120,
            "description": "Optional historical series (2-120 points) rendered as an inline vector sparkline."
          },
          "subtext": {
            "type": "string",
            "maxLength": 64,
            "description": "Optional secondary benchmark text (e.g. 'Plan: $1.10M')."
          }
        },
        "required": [
          "label",
          "value"
        ],
        "additionalProperties": false,
        "description": "Single KPI metric tile specification."
      },
      "minItems": 1,
      "maxItems": 6,
      "description": "1 to 6 executive KPI tiles to render."
    }
  },
  "required": [
    "metrics"
  ],
  "additionalProperties": false
}
```

#### Examples
**SaaS Board Flash KPI Card**
```bash
curl -X POST "https://chart-viz.apikeg.com/v1/render-kpi-card" \
  -H "Content-Type: application/json" \
  -d '{"title":"November SaaS Flash Report","subtitle":"Consolidated Actuals vs. Prior Month","palette":"corporate","metrics":[{"label":"Ending ARR","value":14800000,"format":"currency","currencySymbol":"$","unitSuffix":"","deltaPercent":14.2,"deltaPeriod":"MoM","sparkline":[11200000,12100000,12950000,13800000,14800000],"subtext":"Plan: $14.2M"},{"label":"Net Dollar Retention","value":118.4,"format":"percent","currencySymbol":"$","unitSuffix":"","deltaPercent":2.1,"deltaPeriod":"QoQ","sparkline":[114,115.2,116.3,118.4]},{"label":"Logo Churn","value":1.8,"format":"percent","currencySymbol":"$","unitSuffix":"","deltaPercent":-0.6,"deltaPeriod":"MoM","invertSentiment":true,"sparkline":[2.9,2.5,2.4,1.8]}]}'
```
Expected result: Standalone 3-column SVG KPI card with semantic green trend pills and inline gradient sparklines.
