# Mathpix

> **You are on:** `https://beta-api.paywithlocus.com/api` | [llms.txt](https://beta.paywithlocus.com/llms.txt)
>
> Locus runs on multiple environments -- make sure every URL you call matches your expected environment.
> | Environment | Landing | API |
> |---|---|---|
> | Production | paywithlocus.com | api.paywithlocus.com |
> | Beta | beta.paywithlocus.com | beta-api.paywithlocus.com |
> | Stage | stage.paywithlocus.com | stage-api.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)

## Access Methods

| Method | Base URL | Auth |
|--------|----------|------|
| **MPP (Tempo)** | `https://mathpix.mpp.paywithlocus.com/mathpix/` | HTTP 402 auto-payment |
| **Wrapped API** | `https://beta-api.paywithlocus.com/api/wrapped/mathpix/` | `Authorization: Bearer <LOCUS_API_KEY>` |

**OpenAPI discovery:** `GET https://mathpix.mpp.paywithlocus.com/openapi.json`

## 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://mathpix.mpp.paywithlocus.com/mathpix/process-image \
  -H "Content-Type: application/json" \
  -d '{"src":"<string>","formats":"<string[]>","math_inline_delimiters":"<string[]>","math_display_delimiters":"<string[]>","rm_spaces":"<boolean>","rm_fonts":"<boolean>","idiomatic_eqn_arrays":"<boolean>","include_line_data":"<boolean>","include_word_data":"<boolean>","include_smiles":"<boolean>","confidence_threshold":"<number>","region":"<object>"}'
```

### 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://mathpix.mpp.paywithlocus.com/mathpix/process-strokes \
  -H "Content-Type: application/json" \
  -d '{"strokes":"<object>","formats":"<string[]>","math_inline_delimiters":"<string[]>","math_display_delimiters":"<string[]>","rm_spaces":"<boolean>","rm_fonts":"<boolean>","metadata":"<object>"}'
```
