# Molar Mass API
> Molar-mass and stoichiometry maths as an API, computed locally and deterministically. The molarmass endpoint parses any chemical formula — with parentheses, square brackets and hydrate dots, such as Ca(OH)2, [Fe(CN)6]3 or CuSO4·5H2O — against the IUPAC conventional atomic weights and returns the molar mass in grams per mole, the total atom count and the per-element breakdown with each element's mass contribution and mass percent. The convert endpoint moves between moles, mass in grams and number of molecules for a formula, using n = mass ÷ M = molecules ÷ Nₐ with Avogadro's number. The percent endpoint gives the percent composition by mass and, for a given sample mass, the mass of each element it contains. The formula is parsed locally, so it works for any valid formula, not just compounds in a database, and is instant and private. Ideal for chemistry-education, laboratory, pharmaceutical and science app developers, stoichiometry and lab-prep tools, and STEM teaching. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 3 endpoints. This computes molar mass from a formula; for compound database lookup use a chemistry API and for element properties an elements API.

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

## Pricing
- **Free** (Free) — 3,000 calls/Mo, 2 req/s
- **Starter** ($5/Mo) — 40,000 calls/Mo, 5 req/s
- **Pro** ($15/Mo) — 250,000 calls/Mo, 15 req/s
- **Mega** ($45/Mo) — 1,500,000 calls/Mo, 40 req/s

## Endpoints

### Molar Mass

#### `GET /v1/convert` — Mole / mass / molecules

**Parameters:**
- `formula` (query, required, string) — Chemical formula Example: `H2O`
- `moles` (query, optional, string) — Amount (mol) Example: `2`
- `mass` (query, optional, string) — Or mass (g)
- `molecules` (query, optional, string) — Or number of molecules

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/molarmass-api/v1/convert?formula=H2O&moles=2"
```

**Response:**
```json
{
    "data": {
        "note": "n = mass/M = molecules/Nₐ. Nₐ = 6.02214076×10²³ mol⁻¹.",
        "moles": 2,
        "inputs": {
            "formula": "H2O",
            "molar_mass_g_mol": 18.015
        },
        "mass_g": 36.03,
        "molecules": 1.204428152e+24
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:04.792Z",
        "request_id": "72625459-77e7-4358-9adc-3fa26c0557ac"
    },
    "status": "ok",
    "message": "Mole convert",
    "success": true
}
```

#### `GET /v1/molarmass` — Molar mass of a formula

**Parameters:**
- `formula` (query, required, string) — Chemical formula Example: `CuSO4.5H2O`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/molarmass-api/v1/molarmass?formula=CuSO4.5H2O"
```

**Response:**
```json
{
    "data": {
        "note": "Molar mass = Σ(atomic weight × count), using IUPAC conventional atomic weights. Percent is the mass fraction of each element.",
        "inputs": {
            "formula": "CuSO4.5H2O"
        },
        "elements": [
            {
                "count": 1,
                "element": "Cu",
                "percent": 25.451283,
                "atomic_weight": 63.546,
                "mass_contribution": 63.546
            },
            {
                "count": 1,
                "element": "S",
                "percent": 12.84059,
                "atomic_weight": 32.06,
                "mass_contribution": 32.06
            },
            {
                "count": 9,
                "element": "O",
                "percent": 57.670911,
                "atomic_weight": 15.999,
                "mass_contribution": 143.991
            },
            {
                "count": 10,
                "element": "H",
                "percent": 4.037216,
                "atomic_weight": 1.008,
                "mass_contribution": 10.08
            }
        ],
        "atom_count": 21,
        "molar_mass_g_mol": 249.677
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:04.898Z",
        "request_id": "19ee7c8a-4f3e-40b7-96eb-ba5776846a07"
    },
    "status": "ok",
    "message": "Molar mass",
    "success": true
}
```

#### `GET /v1/percent` — Percent composition

**Parameters:**
- `formula` (query, required, string) — Chemical formula Example: `C6H12O6`
- `mass` (query, optional, string) — Sample mass (g) for element masses Example: `100`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/molarmass-api/v1/percent?formula=C6H12O6&mass=100"
```

**Response:**
```json
{
    "data": {
        "note": "Mass percent = (element mass in one mole / molar mass) × 100. With a sample mass, the mass of each element is given too.",
        "inputs": {
            "formula": "C6H12O6",
            "sample_mass_g": 100,
            "molar_mass_g_mol": 180.156
        },
        "composition": [
            {
                "mass_g": 40.001998,
                "element": "C",
                "percent": 40.001998
            },
            {
                "mass_g": 6.714181,
                "element": "H",
                "percent": 6.714181
            },
            {
                "mass_g": 53.283821,
                "element": "O",
                "percent": 53.283821
            }
        ]
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:05.015Z",
        "request_id": "e9bd47a0-c1af-4f3c-b8ff-e914e0374739"
    },
    "status": "ok",
    "message": "Percent comp",
    "success": true
}
```

### Meta

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

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

**Response:**
```json
{
    "data": {
        "notes": "Formulas support parentheses, square brackets and hydrate dots (·, ., *), e.g. Ca(OH)2, [Fe(CN)6]3, CuSO4.5H2O. IUPAC conventional atomic weights; Nₐ = 6.02214076×10²³.",
        "service": "molarmass-api",
        "formulae": {
            "mole": "n = mass / M = molecules / Nₐ",
            "percent": "element mass / molar mass × 100",
            "molar_mass": "Σ(atomic weight × count)"
        },
        "endpoints": {
            "GET /v1/meta": "This document.",
            "GET /v1/convert": "Convert between moles, mass (g) and molecules for a formula.",
            "GET /v1/percent": "Percent composition, and the mass of each element in a given sample mass.",
            "GET /v1/molarmass": "Molar mass, atom count and per-element percent composition of a formula."
        },
        "description": "Molar-mass and stoichiometry calculator: parse a chemical formula (parentheses, brackets, hydrates) for its molar mass and percent composition, and convert between moles, mass and molecules."
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:05.142Z",
        "request_id": "b94d3843-0e6b-42b6-b52a-d77030111f09"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


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