# BCorrect™ Spelling & Grammar API — Developer Reference (v1.2.0)

> Machine-readable Markdown reference for the BCorrect™ API.
> HTML Docs (Direct API): https://badcharacterscanner.com/api/docs
> HTML Docs (RapidAPI): https://badcharacterscanner.com/api/docs/rapidapi
> OpenAPI 3.1 Schema: https://badcharacterscanner.com/openapi.json
> LLMs Index: https://badcharacterscanner.com/llms.txt
> Engine Versions & Known Issues: https://badcharacterscanner.com/api/versions

## Base URLs & Authentication

| Gateway | Base URL | Auth Headers |
|---|---|---|
| Direct API (Stripe Credits) | `https://bcorrect-api.fly.dev/api/v1` | `X-API-Key: sk_YOUR_KEY_HERE` |
| RapidAPI Hub | `https://bcorrect-api.p.rapidapi.com/api/v1` | `X-RapidAPI-Key: YOUR_KEY`, `X-RapidAPI-Host: bcorrect-api.p.rapidapi.com` |
| WebSocket (Direct) | `wss://bcorrect-api.fly.dev/ws/keystroke` | `X-API-Key` |

Both gateways run the same **v1.2.0** deterministic H-Manifold™ engine in volatile RAM with zero data retention.

## Endpoints

- `GET /api/v1/health` — Engine status, version, vocabulary size, and uptime (no auth required on Direct API).
- `POST /api/v1/check` — Spell & grammar check with optional diagnostics, readability, clarity suggestions, and ranked candidates.
- `POST /api/v1/batch` — Check up to 50 texts in parallel (`{ "texts": ["..."] }`).
- `POST /api/v1/check/stream` — Server-Sent Events (SSE) progressive chunked checking for long documents.
- `WS /ws/keystroke` — Sub-5ms bidirectional WebSocket checking for live editors.
- `GET /api/v1/usage` — Account credit balance and daily/monthly character usage.
- `GET /api/v1/monitoring/reynolds` — Manifold laminar/turbulent telemetry.

## Quick Start (`POST /api/v1/check`)

```bash
curl -X POST https://bcorrect-api.fly.dev/api/v1/check \
  -H "X-API-Key: sk_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Yesturday I went to the store and boughtt some groceries.",
    "mode": "correct",
    "profile": "standard",
    "exact_quotes": ["CustomTerm"],
    "options": {
      "dialect": "us",
      "max_candidates": 5,
      "include_diagnostics": true,
      "include_readability": true
    }
  }'
```

## Request Schema (`POST /api/v1/check`)

- `text` (string, required, max 5MB): Text to evaluate.
- `mode` (`"correct" | "candidates"`, default `"correct"`): Return full corrected string + corrections, or candidate lists per token.
- `profile` (`"standard" | "fast" | "deep" | "academic"`, default `"standard"`):
  - `standard`: ~30-50ms P95, sentence + paragraph context.
  - `fast`: <20ms P95, sliding token window for real-time keystrokes.
  - `deep`: ~150-200ms P95, cross-document global context.
  - `academic`: ~80-100ms P95, formal register + citation shield.
- `exact_quotes` (`string[]`, optional): Protected brand names, identifiers, or terms.
- `options` (object, optional):
  - `dialect`: `"us" | "uk" | "ca" | "au"` (auto-detected if omitted)
  - `confidence_threshold`: number `0.0..1.0` (default `0.75`)
  - `max_candidates`: integer (default `10`)
  - `style_preservation`: `"standardize" | "preserve"` (default `"standardize"`)
  - `include_diagnostics`: boolean (default `true`)
  - `include_readability`: boolean (default `false`)
  - `include_clarity`: boolean (default `false`)
  - `ignore_quoted_text`: boolean (default `false`)
  - `ignore_bracketed_text`: boolean (default `true`)
  - `ignore_math_blocks`: boolean (default `true`)
  - `ignore_code_blocks`: boolean (default `true`)
  - `ignore_markdown_urls`: boolean (default `true`)
  - `retrospective_corrections`: boolean (default `true`)
  - `include_geometric_info`: boolean (default `false`)

## Response Schema (`200 OK`)

```json
{
  "originalText": "He woudl of avoided the severe mistakes if he was more careful.",
  "correctedText": "He would have avoided the severe mistakes if he was more careful.",
  "corrections": [
    {
      "original": "woudl",
      "corrected": "would",
      "confidence": 0.99,
      "positionInOriginal": { "start": 3, "end": 8 },
      "positionInCorrected": { "start": 3, "end": 8 },
      "source": "Dictionary",
      "category": "Spelling",
      "errorType": "PhoneticTransposition",
      "explanation": "Transposition error corrected to 'would'.",
      "educationalTip": "Remember the auxiliary sequence 'w-o-u-l-d'.",
      "candidates": [{ "word": "would", "confidence": 0.99, "source": "NGram-Tree" }]
    }
  ],
  "charCount": 63,
  "processingMs": 16.16,
  "hasHomoglyphs": false,
  "telemetry": {
    "engineProcessingTimeUs": 16160,
    "engineProcessingTimeMs": 16.16,
    "wordsEvaluated": 11,
    "charactersEvaluated": 63,
    "fmmFlowRegime": "Laminar"
  },
  "creditsRemaining": 49937
}
```

## Critical Client Notes

- **Offsets**: `positionInOriginal` and `positionInCorrected` are UTF-8 byte offsets. Convert to UTF-16 code units in JS before slicing non-ASCII strings, and apply replacements right-to-left (descending by `start`).
- **Cold Starts**: HTTP `502` or `503` indicates instance warming (`Retry-After: 3`). Wait 3 seconds and retry up to 2 times.
- **Pricing**: 1 character = 1 credit. Starter $5 (2M), Pro $20 (25M), Pro+ $100 (120M), Enterprise custom.
- **Support**: https://badcharacterscanner.com/contact or `shoy@badcharacterscanner.com`
