# Filament Calculator API
> 3D-printing filament maths as an API, computed locally and deterministically. The length-weight endpoint converts between the length and the weight of a spool of filament from its diameter (1.75 mm or 2.85 mm) and material density, using weight = (π/4·d²·length)·density — so one metre of 1.75 mm PLA weighs about 2.98 g, a standard 1 kg PLA spool holds roughly 335 m, and the same weight of the lighter ABS gives about 400 m. The cost endpoint computes the filament cost of a print from the weight or length used and the price per kilogram, and the spool-remaining endpoint turns a remaining-weight measurement (weigh the spool, subtract the empty-spool weight) into the remaining length so you know whether a job will finish. Built-in densities cover PLA, ABS, PETG, TPU, nylon, ASA, PC, HIPS, PVA, wood-fill and carbon-fibre blends, or supply your own. Diameters are in millimetres, lengths in metres and weights in grams. Everything is computed locally and deterministically, so it is instant and private. Ideal for 3D-printing, maker, print-farm, slicer-plugin, prototyping and STEM-education app developers, filament-usage and print-cost tools, and workshop software. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 3 endpoints. This is filament geometry and cost; for tank or material volume use a volume 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/filament-api/..."
```

## Pricing
- **Free** (Free) — 7,800 calls/Mo, 2 req/s
- **Starter** ($4/Mo) — 78,000 calls/Mo, 6 req/s
- **Pro** ($11/Mo) — 340,000 calls/Mo, 15 req/s
- **Mega** ($35/Mo) — 1,800,000 calls/Mo, 40 req/s

## Endpoints

### Filament

#### `GET /v1/cost` — Print cost

**Parameters:**
- `weight_g` (query, optional, string) — Weight used (g) Example: `25`
- `length_m` (query, optional, string) — Or length used (m)
- `price_per_kg` (query, required, string) — Filament price per kg Example: `20`
- `material` (query, optional, string) — Material Example: `pla`
- `diameter` (query, optional, string) — Diameter (mm) Example: `1.75`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/filament-api/v1/cost?weight_g=25&price_per_kg=20&material=pla&diameter=1.75"
```

**Response:**
```json
{
    "data": {
        "cost": 0.5,
        "note": "Cost = (weight_g / 1000) · price_per_kg. 25 g of filament at 20 per kg costs 0.50.",
        "inputs": {
            "diameter": 1.75,
            "material": "pla",
            "weight_g": 25,
            "price_per_kg": 20
        },
        "weight_g": 25
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:20.067Z",
        "request_id": "c74f72cc-732e-4db3-92fb-04aff6029054"
    },
    "status": "ok",
    "message": "Print cost",
    "success": true
}
```

#### `GET /v1/length-weight` — Length ↔ weight

**Parameters:**
- `length_m` (query, optional, string) — Length (m) → weight Example: `335`
- `weight_g` (query, optional, string) — Weight (g) → length Example: `1000`
- `material` (query, optional, string) — pla, abs, petg, tpu, nylon, asa… Example: `pla`
- `diameter` (query, optional, string) — Diameter (mm, default 1.75) Example: `1.75`
- `density` (query, optional, string) — Custom density (g/cm³)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/filament-api/v1/length-weight?length_m=335&weight_g=1000&material=pla&diameter=1.75"
```

**Response:**
```json
{
    "data": {
        "note": "Weight = length · (π/4·d²·density). 1 m of 1.75 mm PLA ≈ 2.98 g.",
        "inputs": {
            "density": 1.24,
            "diameter": 1.75,
            "length_m": 335,
            "material": "pla"
        },
        "weight_g": 999.1541,
        "grams_per_meter": 2.98255
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:20.188Z",
        "request_id": "128765f3-00ed-46fc-970a-6c3e075e74af"
    },
    "status": "ok",
    "message": "Length/weight conversion",
    "success": true
}
```

#### `GET /v1/spool-remaining` — Remaining spool length

**Parameters:**
- `remaining_weight_g` (query, required, string) — Remaining filament weight (g) Example: `250`
- `material` (query, optional, string) — Material Example: `pla`
- `diameter` (query, optional, string) — Diameter (mm) Example: `1.75`
- `density` (query, optional, string) — Custom density (g/cm³)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/filament-api/v1/spool-remaining?remaining_weight_g=250&material=pla&diameter=1.75"
```

**Response:**
```json
{
    "data": {
        "note": "Remaining length = remaining weight / grams-per-metre. Weigh the spool, subtract the empty-spool weight, and convert.",
        "inputs": {
            "density": 1.24,
            "diameter": 1.75,
            "material": "pla",
            "remaining_weight_g": 250
        },
        "grams_per_meter": 2.98255,
        "remaining_length_m": 83.8209
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:20.295Z",
        "request_id": "668bbaea-28b1-4092-bea1-5a3ed620b8dc"
    },
    "status": "ok",
    "message": "Spool remaining length",
    "success": true
}
```

### Meta

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

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

**Response:**
```json
{
    "data": {
        "notes": "Diameter in mm (default 1.75), density in g/cm³ (or a named material: pla, abs, petg, tpu, nylon, asa, pc, hips, pva, wood, carbon-fiber). Lengths in metres, weights in grams.",
        "service": "filament-api",
        "endpoints": {
            "GET /v1/cost": "Print cost from filament used and price per kg.",
            "GET /v1/meta": "This document.",
            "GET /v1/length-weight": "Convert filament length ↔ weight.",
            "GET /v1/spool-remaining": "Remaining length from remaining weight on a spool."
        },
        "materials": [
            "pla",
            "abs",
            "petg",
            "tpu",
            "nylon",
            "asa",
            "pc",
            "hips",
            "pva",
            "wood",
            "carbon-fiber"
        ],
        "description": "3D-printing filament: length ↔ weight via diameter and density, print cost, and remaining spool length."
    },
    "meta": {
        "timestamp": "2026-06-05T19:50:20.404Z",
        "request_id": "06c64237-e2f9-4be4-9d15-029e9f43da62"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


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