LAB API

Lab Extension API

Three POST surfaces let a lab plug into the trades-agent loop: run a lab model as the WHY producer, ask targeted post-dataset questions, and inject lab-specific benchmark criteria into the publish gate.

Auth And Sandbox Model

Authentication
Use a lab-scoped bearer token in Authorization. Server config maps each lab_id through TRADES_DATA_LAB_TOKENS or TRADES_DATA_LAB_ID plus TRADES_DATA_LAB_TOKEN.
Sandbox
Send X-Lab-Sandbox: true only with lab-test-fixture-* IDs for local fixture checks. Production lab IDs require bearer tokens.
Worker access
All worker-bound questions pass through the same materiality and fatigue gates as internal questions. The worker never sees which lab asked.
Third-party inference
Pipeline requests require a contributor-agreement third-party-inference sublicense for the relevant worker pool. Missing sublicense returns 403.
Admin observability
/lab/admin/<lab_id> uses the same lab-scoped token mapping before private dashboard state is read. Browser access may use admin_token; API access should use Authorization.

API Keys

Generate an API key

Keys are scoped to read_catalog, place_order, download. The secret is shown once — save it immediately. You must be signed in to your lab's web-portal account.

Endpoints

POST/api/lab/pipelineclient-runs-pipeline

Register a lab model endpoint and prompt template for Phase E WHY producer replacement. The intake records the request; downstream runtime execution and worker questions still pass through trades-agent gates.

Writes: apps/web/public/lab-clips/lab-produced/<lab_id>/<clip_id>.json

Request Shape

{
  "lab_id": "acme-lab",
  "clip_id": "test03",
  "model_endpoint_url": "https://lab.example.com/trades/why-producer",
  "model_prompt_template": "Given the span evidence, return WHY claims with citations."
}

Curl

curl -sS -X POST "https://tradesdata.ai/api/lab/pipeline" \
  -H "Authorization: Bearer $TRADES_DATA_LAB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "lab_id": "acme-lab",
    "clip_id": "test03",
    "model_endpoint_url": "https://lab.example.com/trades/why-producer",
    "model_prompt_template": "Given the span evidence, return WHY claims with citations."
  }'
POST/api/lab/questionspost-dataset Q&A

Submit targeted follow-up questions on delivered spans. Accepted questions are queued for the next worker session for the relevant worker pool.

Writes: runs/_meta/lab-extension/<lab_id>/questions/<dataset_bundle_id>.json and apps/web/public/lab-clips/lab-questions/<lab_id>/<dataset_bundle_id>.json

Request Shape

{
  "lab_id": "acme-lab",
  "dataset_bundle_id": "test03-tier1-raw",
  "questions": [
    {
      "clip_id": "test03",
      "span_id": "span-00042",
      "question_text": "Was the driver angle chosen to avoid stripping the screw head?",
      "materiality_reason": "This changes the WHY claim for the span and affects training labels for tool-angle recovery."
    }
  ]
}

Curl

curl -sS -X POST "https://tradesdata.ai/api/lab/questions" \
  -H "Authorization: Bearer $TRADES_DATA_LAB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "lab_id": "acme-lab",
    "dataset_bundle_id": "test03-tier1-raw",
    "questions": [
      {
        "clip_id": "test03",
        "span_id": "span-00042",
        "question_text": "Was the driver angle chosen to avoid stripping the screw head?",
        "materiality_reason": "This changes the WHY claim for the span and affects training labels for tool-angle recovery."
      }
    ]
  }'
POST/api/lab/benchmarksbenchmark injection

Register lab-specific acceptance criteria to run alongside the publish gate and ship as lab-origin rows in the standards scorecard.

Writes: apps/web/public/lab-clips/standards-scorecard/<clip_id>.json

Request Shape

{
  "lab_id": "acme-lab",
  "clip_id": "test03",
  "criteria": [
    {
      "criterion_id": "lab-recovery-angle-001",
      "what_it_grades": "Error-recovery spans include tool angle rationale",
      "verifiable_assertion": "Every recovery span has a WHY claim citing sensor evidence and worker review state.",
      "pass_threshold": 0.95
    }
  ]
}

Curl

curl -sS -X POST "https://tradesdata.ai/api/lab/benchmarks" \
  -H "Authorization: Bearer $TRADES_DATA_LAB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "lab_id": "acme-lab",
    "clip_id": "test03",
    "criteria": [
      {
        "criterion_id": "lab-recovery-angle-001",
        "what_it_grades": "Error-recovery spans include tool angle rationale",
        "verifiable_assertion": "Every recovery span has a WHY claim citing sensor evidence and worker review state.",
        "pass_threshold": 0.95
      }
    ]
  }'