# Math API
> A full math engine as an API, powered by mathjs. Evaluate any expression — arithmetic, hundreds of functions (sqrt, sin, log, gcd, factorial, combinations, …), constants (pi, e), complex numbers, matrices and number theory — with optional precision control (e.g. 2+3*sqrt(16) → 14, pi at 5 digits → 3.1416). Take the symbolic derivative of an expression with respect to a variable (x^2+3x → 2*x+3), and simplify algebra (2x+3x → 5*x). No formula libraries to bundle, no maths to reimplement: send an expression, get the answer. Ideal for calculators and STEM education apps, spreadsheet and form logic, quiz and homework tools, engineering and data dashboards, and any product that needs reliable server-side computation.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/math-api/..."
```

## Pricing
- **Free** (Free) — 12,500 calls/Mo, 2 req/s
- **Starter** ($4/Mo) — 185,000 calls/Mo, 8 req/s
- **Pro** ($11/Mo) — 820,000 calls/Mo, 20 req/s
- **Mega** ($33/Mo) — 3,300,000 calls/Mo, 50 req/s

## Endpoints

### Math

#### `GET /v1/derivative` — Symbolic derivative

**Parameters:**
- `expr` (query, required, string) — Expression, e.g. x^2+3x Example: `x^2+3x`
- `variable` (query, optional, string) — Variable to differentiate by (default x) Example: `x`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/math-api/v1/derivative?expr=x%5E2%2B3x&variable=x"
```

**Response:**
```json
{
    "data": {
        "variable": "x",
        "derivative": "2 * x + 3",
        "expression": "x^2+3x"
    },
    "meta": {
        "timestamp": "2026-06-01T00:04:29.855Z",
        "request_id": "d00146ad-91c2-4ed8-91d0-03b0b5400d76"
    },
    "status": "ok",
    "message": "Derivative computed",
    "success": true
}
```

#### `GET /v1/evaluate` — Evaluate a math expression

**Parameters:**
- `expr` (query, required, string) — Expression, e.g. 2+3*sqrt(16) or gcd(12,18)+factorial(5) Example: `2+3*sqrt(16)`
- `precision` (query, optional, string) — Significant digits 1-64

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/math-api/v1/evaluate?expr=2%2B3%2Asqrt%2816%29"
```

**Response:**
```json
{
    "data": {
        "result": "14",
        "expression": "2+3*sqrt(16)"
    },
    "meta": {
        "timestamp": "2026-06-01T00:04:30.026Z",
        "request_id": "4b6d6d26-8724-4170-91de-6cdb473f0650"
    },
    "status": "ok",
    "message": "Expression evaluated",
    "success": true
}
```

#### `GET /v1/simplify` — Simplify an algebraic expression

**Parameters:**
- `expr` (query, required, string) — Expression, e.g. 2x+3x Example: `2x+3x`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/math-api/v1/simplify?expr=2x%2B3x"
```

**Response:**
```json
{
    "data": {
        "expression": "2x+3x",
        "simplified": "5 * x"
    },
    "meta": {
        "timestamp": "2026-06-01T00:04:30.201Z",
        "request_id": "7ffda779-c9ad-4063-8bde-66b55adafee6"
    },
    "status": "ok",
    "message": "Expression simplified",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Usage notes

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/math-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "note": "A math engine. /v1/evaluate = evaluate any expression — arithmetic, functions (sqrt, sin, log, gcd, factorial, …), constants (pi, e), complex numbers, unit conversions (e.g. 12.7 cm to inch), matrices and number theory; optional precision=1..64. /v1/derivative = the symbolic derivative of an expression with respect to a variable (e.g. expr=x^2+3x, variable=x → 2*x+3). /v1/simplify = simplify algebra (e.g. 2x+3x → 5*x). Expressions are math-only (no quotes).",
        "source": "mathjs (api.mathjs.org)",
        "endpoints": [
            "/v1/evaluate",
            "/v1/derivative",
            "/v1/simplify",
            "/v1/meta"
        ]
    },
    "meta": {
        "timestamp": "2026-06-01T00:04:30.270Z",
        "request_id": "2963b340-8a03-42c8-adf9-fe171e4ea231"
    },
    "status": "ok",
    "message": "Meta retrieved",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/math-api
OpenAPI spec: https://www.oanor.com/api/math-api/openapi.json
