API Reference

Deterministic quality measurement for AI agents. Accept scenario definitions, run Monte Carlo evaluations, and gate CI/CD pipelines on pass/fail status.

Authentication

All CI/CD endpoints require the X-BaselineForge-Key header.

X-BaselineForge-Key Header

Set the environment variable BASELINE_FORGE_API_KEY in your server/app environment. Pass it as a header on every CI/CD request:

X-BaselineForge-Key: <your-api-key>

If the key is missing or invalid, the endpoint returns 401 Unauthorized. If the env var is not configured at all, POST /api/ci/check returns 503 Service Unavailable.

Get your API key from your deployment environment's config (e.g., Render environment variables).

Run a Scenario Evaluation

Execute a Monte Carlo scenario and receive structured metrics with pass/fail classification against baselines.

POST /api/scenarios/run

Accepts a scenario definition, executes n trials, classifies the result against baseline thresholds, persists the run record, and returns structured results including success rate, cost, duration, and regression signals.

Request Body

FieldTypeRequiredDescription
agent_typestringYesAgent archetype, e.g. "engineering", "support", "research"
namestringNoScenario name for tracking. Defaults to <agent_type>:<timestamp>
profile_idnumberNoBaseline profile to auto-apply thresholds. Overridden by explicit baseline fields.
nnumberNoNumber of trials, 1–50. Defaults to 10.
fixtureobjectNoControlled environment config: company_type, task, complexity (1–10), or any custom key-value pairs.
baselineobjectNoOverrides or sets thresholds: success_rate (target %), soft_failure (floor %), cost_per_task (max USD), max_duration_ms

Example Request

# Run an engineering agent scenario with 20 trials
curl -X POST https://baselineforge-2.polsia.app/api/scenarios/run \\
  -H "Content-Type: application/json" \\
  -d '{
    "name": "engineering-agent-v3",
    "agent_type": "engineering",
    "profile_id": 2,
    "n": 20,
    "fixture": {
      "company_type": "saas",
      "complexity": 7
    }
  }'

Example Response

{
  "scenario_id": 1,
  "run_id": 14,
  "agent_type": "engineering",
  "profile": { "id": 2, "name": "Coding Agent" },
  "measurement": {
    "success_rate": 0.91,
    "cost_usd": 0.38,
    "duration_ms": 12450,
    "trials": 20,
    "trial_results": [...]
  },
  "status": "pass",
  "baseline": {
    "success_rate": 0.91,
    "soft_failure": 0.33,
    "cost_per_task": 0.50
  },
  "regression_signals": [],
  "ran_at": "2026-05-24T07:00:00.000Z"
}

CI/CD Gate Check

Run a scenario check as part of a CI pipeline. Returns HTTP 200 on pass, 422 on fail.

POST /api/ci/check X-BaselineForge-Key required

Executes the scenario associated with scenario_id and returns structured pass/fail results. CI pipelines should gate on the HTTP status code: 200 = pass, 422 = fail. All request metadata (commit SHA, branch) is stored in the ci_runs table for audit.

Request Headers

HeaderValue
X-BaselineForge-KeyYour BASELINE_FORGE_API_KEY env var value

Request Body

FieldTypeRequiredDescription
scenario_idnumberYesID of the scenario to run (must already exist in the database)
commit_shastringYesGit commit SHA being checked (stored in CI run record)
branchstringNoGit branch name for badge filtering, e.g. "main"

Example Request

curl -X POST https://baselineforge-2.polsia.app/api/ci/check \\
  -H "Content-Type: application/json" \\
  -H "X-BaselineForge-Key: $BASELINE_FORGE_API_KEY" \\
  -d '{
    "scenario_id": 1,
    "commit_sha": "a3f8c2d",
    "branch": "main"
  }'

Example Response (pass)

{
  "passed": true,
  "commit_sha": "a3f8c2d",
  "branch": "main",
  "duration_ms": 3120,
  "summary": {
    "total": 10,
    "passed": 9,
    "failed": 1,
    "soft_failed": 0
  },
  "results": [...],
  "regression_signals": [],
  "scenario": { "id": 1, "name": "engineering-agent-v3", "agent_type": "engineering" },
  "run_id": 15
}

Error Responses

StatusBodyCause
400{ "error": "scenario_id is required..." }Missing or invalid fields
401{ "error": "Unauthorized..." }Missing or wrong X-BaselineForge-Key
404{ "error": "Scenario N not found" }scenario_id does not exist
422Full response body with "passed": falseScenario failed baseline thresholds

Compare Scenario Runs

Compare two runs side-by-side and get structured deltas with direction indicators.

GET /api/scenarios/:id/compare

Returns per-metric deltas (success_rate, cost_usd, duration_ms) between two runs of the same scenario. run_a defaults to the most recent run before run_b. Both runs must belong to the same scenario.

Query Parameters

ParamRequiredDescription
run_bYesID of the newer run to compare
run_aNoID of the older run. Omit to auto-select the most recent prior run

Example Request

curl "https://baselineforge-2.polsia.app/api/scenarios/1/compare?run_b=14&run_a=12"

Example Response

{
  "scenario_id": 1,
  "run_a": {
    "id": 12,
    "metrics": {
      "success_rate": 0.87,
      "cost_usd": 0.52,
      "duration_ms": 14800
    },
    "status": "soft_fail",
    "created_at": "2026-05-23T10:00:00.000Z"
  },
  "run_b": {
    "id": 14,
    "metrics": {
      "success_rate": 0.91,
      "cost_usd": 0.38,
      "duration_ms": 12450
    },
    "status": "pass",
    "created_at": "2026-05-24T07:00:00.000Z"
  },
  "deltas": {
    "success_rate": { "old": 0.87, "new": 0.91, "change_pct": 4.60, "direction": "improved" },
    "cost_usd":      { "old": 0.52, "new": 0.38, "change_pct": -26.92, "direction": "improved" },
    "duration_ms":    { "old": 14800, "new": 12450, "change_pct": -15.88, "direction": "improved" }
  },
  "summary": { "total_metrics": 3, "improved": 3, "regressed": 0, "stable": 0 }
}

CI Status Badge

Embed a live SVG status badge in your README or dashboard.

GET /api/ci/badge/:scenarioId

Returns a shields.io-format SVG badge showing PASS / FAIL / NO RUNS for the latest CI run of the scenario. Cached for 60 seconds to avoid DB load from frequent polling. Filter by branch with ?branch=main.

Path Parameters

ParamDescription
scenarioIdNumeric scenario ID

Query Parameters

ParamDescription
branchOptional branch filter, e.g. ?branch=main — returns latest run for that branch only

Example — Raw SVG URL

https://baselineforge-2.polsia.app/api/ci/badge/1?branch=main

Markdown Embed (README)

BaselineForge CI Status [![BaselineForge](https://baselineforge-2.polsia.app/api/ci/badge/1?branch=main)](https://baselineforge-2.polsia.app)

Update 1 to your actual scenario ID. For unfiltered badge (all branches): drop ?branch=main.

Status States

StatusColorMeaning
PASS🟢 greenLatest CI run passed all baselines
FAIL🔴 redLatest CI run failed or soft-failed baselines
NO RUNS⬜ grayNo CI runs recorded for this scenario/branch
UNKNOWN⬜ grayScenario not found or DB error (fail-open)

Baseline Profiles

Pre-defined agent archetype templates with default success rate and cost thresholds. Pass profile_id to /api/scenarios/run to auto-fill baseline thresholds.

GET /api/profiles

List all available baseline profile templates. Each profile contains default_thresholds and metric_definitions.

Example Request

curl https://baselineforge-2.polsia.app/api/profiles

Example Response

{
  "profiles": [
    {
      "id": 1,
      "name": "Support Agent",
      "agent_type": "support",
      "success_rate_threshold": 0.93,
      "default_thresholds": {
        "success_rate": 0.93,
        "soft_failure": 0.50,
        "cost_per_task": 0.25
      },
      "metric_definitions": [...],
      "custom_metrics": {}
    },
    {
      "id": 2,
      "name": "Coding Agent",
      "agent_type": "engineering",
      "success_rate_threshold": 0.91,
      "default_thresholds": {
        "success_rate": 0.91,
        "soft_failure": 0.33,
        "cost_per_task": 0.50
      },
      "metric_definitions": [...],
      "custom_metrics": {}
    },
    {
      "id": 3,
      "name": "Research Agent",
      "agent_type": "research",
      "success_rate_threshold": 0.89,
      "default_thresholds": {
        "success_rate": 0.89,
        "soft_failure": 0.40,
        "cost_per_task": 0.60
      },
      "metric_definitions": [...],
      "custom_metrics": {}
    }
  ]
}
GET /api/profiles/:id

Fetch a single profile by ID. Returns the profile with full default_thresholds and metric_definitions.

Example Request

curl https://baselineforge-2.polsia.app/api/profiles/2

CI/CD Integration Quickstart

Add a BaselineForge quality gate to any GitHub Actions workflow in under 5 minutes.

GitHub Actions — Full Workflow Example

Set BASELINE_FORGE_API_KEY as a GitHub Secret, then add this step to your workflow:

# .github/workflows/quality-gate.yml
name: BaselineForge Quality Gate

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  baseline-check:
    runs-on: ubuntu-latest
    steps:
      - name: Run BaselineForge quality check
        run: |
          # Replace SCENARIO_ID with your scenario ID from /docs/profiles
          RESPONSE=$(curl -s -w "\n%{http_code}" -X POST "${{ secrets.BASELINE_FORGE_API_URL }}/api/ci/check" \\
            -H "Content-Type: application/json" \\
            -H "X-BaselineForge-Key: ${{ secrets.BASELINE_FORGE_API_KEY }}" \\
            -d '{
              "scenario_id": 1,
              "commit_sha": "${{ github.sha }}",
              "branch": "${{ github.ref_name }}"
            }')

          STATUS_CODE=$(echo "$RESPONSE" | tail -1)
          BODY=$(echo "$RESPONSE" | sed '$d')

          echo "BaselineForge response:"
          echo "$BODY" | jq .

          if [ "$STATUS_CODE" = "200" ]; then
            echo "BaselineForge: PASS — all baselines met"
            exit 0
          elif [ "$STATUS_CODE" = "422" ]; then
            echo "BaselineForge: FAIL — baseline thresholds not met"
            exit 1
          else
            echo "BaselineForge: Unexpected status $STATUS_CODE"
            echo "$BODY" | jq .
            exit 1
          fi
        env:
          BASELINE_FORGE_API_URL: https://baselineforge-2.polsia.app

Setup Steps

  1. Add BASELINE_FORGE_API_KEY as a GitHub Secret (Settings → Secrets → Actions)
  2. Set BASELINE_FORGE_API_URL secret to https://baselineforge-2.polsia.app
  3. Copy the workflow file to .github/workflows/baselineforge.yml
  4. Update scenario_id to match your scenario's ID (found on the profiles page)
  5. Push — the gate will run on every push and PR to main/develop

Badge in Your README

Paste this markdown to show live CI status:

BaselineForge CI Status [![BaselineForge](https://baselineforge-2.polsia.app/api/ci/badge/1?branch=main)](https://baselineforge-2.polsia.app/docs)