# Schema-Validated HTTP 200-Only Metering and Deterministic Error Classification

Canonical URL: https://dataroute.dev/method/http-200-billing/
Author: DataRoute Engineering | Published: 2026-11-22

> Transport status alone leaves callers exposed to paying for empty HTML shells and upstream timeouts. DataRoute pairs strict schema verification with atomic USD ledger commits so only verified HTTP 200 payloads deduct credits.

## 1. The Two-Condition Metering Gate

        Before a DataRoute gateway request deducts prepaid USD credits, the finalized response passes two mandatory checks inside the metering middleware:

        
          - **HTTP Status Gate:** The gateway response status must equal `200`. Every `4xx` client error and every `5xx` upstream error short-circuits directly to `billable: false`.

          - **Schema Validation Gate:** The normalized `data` object must pass strict route-level schema validation (required IDs, types, non-corrupted text/Markdown fields, and absence of upstream block-page markers). If an upstream returns HTTP `200` containing a login redirect, CAPTCHA challenge, or truncated JSON, DataRoute converts the outcome to `422 validation_failed` or retries failover—never charging the caller.

        

        

## 2. Valid Empty Sets vs. Malformed Payloads

        Public data systems must distinguish carefully between a genuine empty query result and a broken upstream scrape:

        
          - **Genuine confirmed 404 or private target:** When an upstream explicitly confirms a tweet ID or user handle does not exist or is restricted, DataRoute emits HTTP `404 resource_not_found` with `billable: false`.

          - **Broken or empty scrape shell:** When an upstream omits expected structural markers or returns a stripped anti-bot page, the schema gate rejects the payload, triggers secondary failover, and deducts `$0.00` if all upstreams fail.

          - **Validated zero-match search:** When a search upstream returns a verified structured search envelope confirming zero public matches for an obscure query string, schema validation passes and explicit metadata confirms zero matches.

        

        

## 3. Atomic USD Ledger Reservation & Commit

        The planned Stage 1 PostgreSQL USD credit ledger uses an idempotent hold-and-settle flow keyed on `request_id`:

        

```
1. Authenticate DATAROUTE_API_KEY + check available USD credit balance
2. Assign unique request_id and reserve route ceiling in ledger
3. Dispatch to primary engine / dual-upstream failover router
4. Validate response HTTP status === 200 AND route JSON schema
   ├─ PASS -> Commit exact USD charge, return HTTP 200 with billing.billable = true
   └─ FAIL -> Release reservation ($0.00 charge), return normalized 4xx/5xx with billing.billable = false
```

        

## 4. Deterministic Non-Billable Error Codes

        Every non-200 response guarantees `billing.billable: false` and includes an explicit `error.retryable` boolean so SDKs, n8n workflows, and AI agents apply exponential backoff only on transient upstream conditions (`429`, `502`, `504`) while halting immediately on parameter or credit errors (`400`, `401`, `402`).

## Key Takeaways
- Credit deduction requires both HTTP 200 status and passing route-level JSON schema validation.
- CAPTCHA pages, truncated upstream bodies, timeouts, 429s, and 5xx failures trigger zero charge.
- Stage 1 PostgreSQL ledger commits atomically by unique request_id with hold-and-release semantics.

## Questions & Answers
### What if an upstream returns HTTP 200 with an HTML CAPTCHA page inside?
DataRoute inspects and validates every normalized payload before billing. An upstream HTTP 200 wrapping a CAPTCHA or login wall fails schema validation, triggers failover when available, and results in zero credit deduction if no healthy upstream succeeds.

### Are HTTP 400 invalid parameter or 404 not found responses billed?
No. HTTP 400 invalid_parameter, 401 invalid_api_key, 402 insufficient_credits, 404 resource_not_found, 422 validation_failed, 429 rate_limited, 502 upstream_exhausted, and 504 upstream_timeout all set billing.billable to false and deduct zero credits.

### How does DataRoute prevent double billing on client retries?
Each request receives a unique request_id tied to one atomic ledger settlement entry, and failed or timed-out executions release any temporary balance hold immediately.

### Does the HTTP 200-only guarantee apply to MCP tool calls too?
Yes. Every tool call routed through https://dataroute.dev/mcp invokes the same schema validation gate and atomic USD credit ledger as direct REST calls.
