# DataRoute Unified HTTP Contract (api.dataroute.dev/v1/*)

Canonical URL: https://dataroute.dev/docs/api-contract/
Updated: 2026-11-22 | Status: Stage 0 Pre-Launch Specification

## Authentication
`Authorization: Bearer $DATAROUTE_API_KEY` over HTTPS against `https://api.dataroute.dev/v1/*`.

## Success Envelope
```json
{
  "ok": true,
  "request_id": "dr_req_01JDR9X4K8M2N7Q5V1W6Y3Z8",
  "route": "GET /v1/social/x/search",
  "data": {
    "query": "openrouter mcp",
    "items": [
      {
        "id": "1894012345678901234",
        "author_handle": "example_dev",
        "text": "Unified MCP routing for public web and social data...",
        "created_at": "2026-11-22T06:15:00Z"
      }
    ],
    "next_cursor": "cursor_example_token"
  },
  "provenance": {
    "engine": "ark",
    "upstream_id": "ark_owned_pool_us_west",
    "failover_attempts": 0,
    "latency_ms": 418,
    "fetched_at": "2026-11-22T06:16:02Z"
  },
  "billing": {
    "billable": true,
    "http_status": 200,
    "schema_valid": true,
    "currency": "USD"
  }
}
```

## Error Envelope (Non-Billable)
```json
{
  "ok": false,
  "request_id": "dr_req_01JDR9Z0P9Q4R8S2T6U1V5W9",
  "route": "GET /v1/search/serp",
  "error": {
    "code": "upstream_exhausted",
    "message": "Primary and secondary SERP upstreams failed within the request timeout window.",
    "retryable": true
  },
  "provenance": {
    "engine": "multi_upstream_serp",
    "upstream_id": "serp_secondary_eu",
    "failover_attempts": 2,
    "latency_ms": 4820,
    "fetched_at": "2026-11-22T06:21:14Z"
  },
  "billing": {
    "billable": false,
    "http_status": 502,
    "schema_valid": false,
    "currency": "USD"
  }
}
```

## Error Taxonomy
| HTTP | Code | Billable | Owner | Meaning |
| --- | --- | --- | --- | --- |
| 200 | `ok` | Yes (schema-valid) | DataRoute Gateway | Valid structured payload passed schema verification and explicit provenance checks. |
| 400 | `invalid_parameter` | No ($0.00) | Client Request | Malformed query parameter, unsupported market code, or invalid URL/domain format. |
| 401 | `invalid_api_key` | No ($0.00) | Client Auth | Missing, revoked, or malformed DATAROUTE_API_KEY bearer token. |
| 402 | `insufficient_credits` | No ($0.00) | Account Ledger | Prepaid USD credit balance is below the route maximum reservation. |
| 404 | `resource_not_found` | No ($0.00) | Public Target | Target public tweet, user handle, video ID, or URL was confirmed nonexistent or private. |
| 422 | `validation_failed` | No ($0.00) | Schema Gate | Upstream returned data that failed required field validation; rejected before billing. |
| 429 | `rate_limited` | No ($0.00) | Gateway / Upstream | Caller concurrency limit reached or all configured upstream pools temporarily throttled. |
| 502 | `upstream_exhausted` | No ($0.00) | Failover Router | Primary and secondary upstreams returned upstream errors; circuit breaker updated. |
| 504 | `upstream_timeout` | No ($0.00) | Failover Router | Bounded end-to-end execution budget expired before a valid response arrived. |

## Questions & Answers
### Why does DataRoute include a provenance block in every API response?
Silent upstream swaps hide latency regressions, schema drift, and licensing boundaries. Including engine, upstream_id, failover_attempts, latency_ms, and fetched_at on every response lets engineering teams audit billing, debug retries, and verify compliance boundaries deterministically.

### How should clients authenticate requests to https://api.dataroute.dev/v1/*?
Every planned HTTP route expects an Authorization: Bearer $DATAROUTE_API_KEY header over HTTPS. Keys support self-service rotation in the planned Stage 1 console without interrupting prepaid credit balances.

### Does DataRoute support Markdown responses directly on Web Capture routes?
Yes. POST /v1/web/markdown returns clean extracted Markdown inside the JSON data.markdown field by default, and documentation routes on https://dataroute.dev support Accept: text/markdown negotiation directly.

### How does request_id support idempotent billing reconciliation?
Every gateway request generates a globally unique request_id persisted alongside its HTTP status, schema check outcome, serving upstream, and exact credit ledger entry so every deduction can be reconciled line by line.
