# Number Theory API
> An integer toolkit as an API. Factorize any number into its prime factors with exponents (and a readable 2^3 × 3^2 × 5 form), with the divisor count, the divisor sum, the full list of divisors and whether the number is perfect; find the greatest common divisor and least common multiple of two numbers (and whether they are coprime); and test primality, returning the next and previous prime. Handles numbers up to a trillion. Perfect for maths education and puzzles, cryptography demos, generating test data and any time you need the building blocks of a number. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 4 endpoints. A focused integer toolkit, distinct from a general math-expression engine.

## 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/numbertheory-api/..."
```

## Pricing
- **Free** (Free) — 1,135 calls/Mo, 2 req/s
- **Starter** ($2/Mo) — 9,750 calls/Mo, 8 req/s
- **Pro** ($22/Mo) — 148,500 calls/Mo, 20 req/s
- **Mega** ($60/Mo) — 785,000 calls/Mo, 50 req/s

## Endpoints

### Number Theory

#### `GET /v1/factorize` — Prime factorization + divisors

**Parameters:**
- `number` (query, required, string) — Integer 1 to 1e12 Example: `360`
- `divisors` (query, optional, string) — false to skip the divisor list

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/numbertheory-api/v1/factorize?number=360"
```

**Response:**
```json
{
    "data": {
        "number": 360,
        "divisors": [
            1,
            2,
            3,
            4,
            5,
            6,
            8,
            9,
            10,
            12,
            15,
            18,
            20,
            24,
            30,
            36,
            40,
            45,
            60,
            72,
            90,
            120,
            180,
            360
        ],
        "is_prime": false,
        "is_perfect": false,
        "divisor_sum": 1170,
        "divisor_count": 24,
        "factorization": "2^3 × 3^2 × 5",
        "prime_factors": [
            {
                "prime": 2,
                "exponent": 3
            },
            {
                "prime": 3,
                "exponent": 2
            },
            {
                "prime": 5,
                "exponent": 1
            }
        ]
    },
    "meta": {
        "timestamp": "2026-06-03T01:09:40.581Z",
        "request_id": "de0d9194-b95b-4471-a306-d9d2aa583cfc"
    },
    "status": "ok",
    "message": "Prime factorization",
    "success": true
}
```

#### `GET /v1/gcd` — GCD and LCM

**Parameters:**
- `a` (query, required, string) — First number Example: `48`
- `b` (query, required, string) — Second number Example: `180`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/numbertheory-api/v1/gcd?a=48&b=180"
```

**Response:**
```json
{
    "data": {
        "a": 48,
        "b": 180,
        "gcd": 12,
        "lcm": 720,
        "coprime": false
    },
    "meta": {
        "timestamp": "2026-06-03T01:09:40.674Z",
        "request_id": "b3915559-0784-4186-9405-833222dd5a06"
    },
    "status": "ok",
    "message": "GCD and LCM",
    "success": true
}
```

#### `GET /v1/is-prime` — Primality test

**Parameters:**
- `number` (query, required, string) — Integer to test Example: `97`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/numbertheory-api/v1/is-prime?number=97"
```

**Response:**
```json
{
    "data": {
        "number": 97,
        "is_prime": true,
        "next_prime": 101,
        "previous_prime": 89
    },
    "meta": {
        "timestamp": "2026-06-03T01:09:40.765Z",
        "request_id": "64ab1eb6-d7ff-4d83-a0bd-6e04e11bd16a"
    },
    "status": "ok",
    "message": "Primality test",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

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

**Response:**
```json
{
    "data": {
        "name": "Number Theory API",
        "notes": "Numbers up to 1e12. The full divisor list is returned only for n ≤ 10,000,000 (count and sum are always given). Nothing is stored.",
        "version": "v1",
        "endpoints": [
            {
                "path": "/v1/factorize",
                "params": {
                    "number": "1 to 1e12 (required)",
                    "divisors": "false to skip the divisor list"
                },
                "returns": "prime factors, divisor count/sum, divisors, is_perfect"
            },
            {
                "path": "/v1/gcd",
                "params": {
                    "a": "required",
                    "b": "required"
                },
                "returns": "gcd, lcm, whether coprime"
            },
            {
                "path": "/v1/is-prime",
                "params": {
                    "number": "required"
                },
                "returns": "is_prime + next and previous prime"
            },
            {
                "path": "/v1/meta",
                "params": [],
                "returns": "this document"
            }
        ],
        "description": "An integer toolkit: prime factorization with exponents, the divisors of a number (count and sum), greatest common divisor and least common multiple, and primality testing with the next and previous prime. Pure local, no key."
    },
    "meta": {
        "timestamp": "2026-06-03T01:09:40.840Z"
…(truncated, see openapi.json for full schema)
```


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