# Mathpix — Wrapped API

> **You are on:** `https://api.paywithlocus.com/api` | [llms.txt](https://paywithlocus.com/llms.txt) | [docs](https://docs.paywithlocus.com)
>
> Locus runs on multiple environments -- make sure every URL you call matches your expected environment.
> | Environment | Landing | API | Docs |
> |---|---|---|---|
> | Production | paywithlocus.com | api.paywithlocus.com | docs.paywithlocus.com |
> | Beta | beta.paywithlocus.com | api.beta.paywithlocus.com | docs.paywithlocus.com |
> | Stage | stage.paywithlocus.com | api.stage.paywithlocus.com | docs.paywithlocus.com |
>
> If the API URL above doesn't match your expected environment, re-fetch this file from the correct domain.

> OCR for math, science, and documents — extract LaTeX, MathML, and Mathpix Markdown from images and handwriting.

**Category:** AI / OCR | **Website:** [mathpix.com](https://mathpix.com) | **Docs:** [docs.mathpix.com](https://docs.mathpix.com)

Pay-per-use API proxy. Each call is automatically billed to your wallet in USDC.

## Access

**Base URL:** `https://api.paywithlocus.com/api/wrapped/mathpix/`
**Auth:** `Authorization: Bearer <LOCUS_API_KEY>`

> Also available via public x402 on Base (no account needed): [x402/mathpix.md](https://paywithlocus.com/x402/mathpix.md)

> Also available via MPP (no account needed): [mpp/mathpix.md](https://paywithlocus.com/mpp/mathpix.md)

## Endpoints

### Process Image

OCR a single image — returns recognized text, LaTeX, MathML, or HTML. Supports math, tables, diagrams, and handwriting.

**Estimated cost:** $0.005

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `src` | string | Yes | Image URL (http/https) or base64-encoded image (data:image/...;base64,...) |
| `formats` | string[] | No | Output formats to return: "text", "data", "html", "latex_styled". Defaults to ["text"]. |
| `math_inline_delimiters` | string[] | No | Custom inline math delimiters, e.g. ["$", "$"]. Default: ["\\(", "\\)"]. |
| `math_display_delimiters` | string[] | No | Custom display math delimiters, e.g. ["$$", "$$"]. Default: ["\\[", "\\]"]. |
| `rm_spaces` | boolean | No | Remove extra whitespace from equations. Default: true. |
| `rm_fonts` | boolean | No | Strip font commands like \mathbf. Default: false. |
| `idiomatic_eqn_arrays` | boolean | No | Use aligned/gathered instead of array environments. Default: false. |
| `include_line_data` | boolean | No | Return line-by-line segmentation data. |
| `include_word_data` | boolean | No | Return word-level segmentation data. |
| `include_smiles` | boolean | No | Enable chemistry diagram OCR (returns SMILES notation). |
| `confidence_threshold` | number | No | Minimum confidence (0–1) before returning an error. |
| `region` | object | No | Pixel region to process: { x1, y1, x2, y2 } coordinates. |

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/mathpix/process-image \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"src":"<png data url: supply valid media bytes>","formats":["text"]}'
```

### Process Strokes

Recognize handwritten math/text from stroke coordinate data (digital ink). Returns LaTeX and Mathpix Markdown.

**Estimated cost:** $0.013

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `strokes` | object | Yes | Stroke data: { x: [[x1, x2, ...], ...], y: [[y1, y2, ...], ...] } — arrays of coordinate arrays per stroke. |
| `formats` | string[] | No | Output formats: "text", "data", "html", "latex_styled". |
| `math_inline_delimiters` | string[] | No | Custom inline math delimiters. |
| `math_display_delimiters` | string[] | No | Custom display math delimiters. |
| `rm_spaces` | boolean | No | Remove extra whitespace from equations. Default: true. |
| `rm_fonts` | boolean | No | Strip font commands. Default: false. |
| `metadata` | object | No | Custom key-value metadata, e.g. { improve_mathpix: true }. |

```bash
curl -X POST https://api.paywithlocus.com/api/wrapped/mathpix/process-strokes \
  -H "Authorization: Bearer YOUR_LOCUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"strokes":{"strokes":{"x":[[131,131,130,130,131,133,136,146,151,158,161,162,162,162,162,159,155,147,142,137,136,138,143,160,171,190,197,202,202,202,201,194,189,177,170,158,153,150,148],[231,231,233,235,239,248,252,260,264,273,277,280,282,283],[273,272,271,270,267,262,257,249,243,240,237,235,234,234,233,233],[296,296,297,299,300,301,301,302,303,304,305,306,306,305,304,298,294,286,283,281,281,282,284,284,285,287,290,293,294,299,301,308,309,314,315,316]],"y":[[213,213,212,211,210,208,207,206,206,209,212,217,220,227,230,234,236,238,239,239,239,239,239,239,241,247,252,259,261,264,266,269,270,271,271,271,270,269,268],[231,231,232,235,238,246,249,257,261,267,270,272,273,274],[230,230,230,231,234,240,246,258,268,273,277,281,281,283,283,284],[192,192,191,189,188,187,187,187,188,188,190,193,195,198,200,205,208,213,215,215,215,214,214,214,214,216,218,220,221,223,223,223,223,221,221,220]]}},"formats":["text"]}'
```
