# Magnetic Field & Force API
> Magnetic fields and forces as an API, computed locally and deterministically. The wire endpoint computes the magnetic field around a long straight current-carrying wire, B = μ0·I/(2π·r) — the field at a distance r from a wire carrying a current I — and solves for whichever of the current, the distance or the field you leave out, reporting the field in tesla, millitesla, microtesla and gauss. The solenoid endpoint gives the uniform field inside a long solenoid, B = μ0·n·I (n turns per metre, given directly or as a total number of turns over a length), or the field at the centre of a circular loop, B = μ0·N·I/(2R). The force endpoint computes the magnetic force on a moving charge, F = q·v·B·sin(θ) (the Lorentz force), or on a current-carrying wire in a field, F = B·I·L·sin(θ), with the force per metre. The vacuum permeability μ0 = 4π×10⁻⁷ is built in, with an optional relative permeability for a magnetic core. Everything is computed locally and deterministically, so it is instant and private. Ideal for electromagnetism-education tools, electromagnet, motor and inductor design, magnetic-sensor and physics-simulation apps. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 3 endpoints. This is magnetostatics; for Coulomb electrostatics use a Coulomb API and for Ohm's-law circuits use an Ohm's-law 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/magnetic-api/..."
```

## Pricing
- **Free** (Free) — 2,000 calls/Mo, 2 req/s
- **Starter** ($9/Mo) — 40,000 calls/Mo, 5 req/s
- **Pro** ($24/Mo) — 250,000 calls/Mo, 15 req/s
- **Mega** ($75/Mo) — 1,509,000 calls/Mo, 40 req/s

## Endpoints

### Magnetic

#### `GET /v1/force` — Magnetic force

**Parameters:**
- `magnetic_field` (query, required, string) — Field B (T) Example: `0.5`
- `charge` (query, optional, string) — Charge q (C) for a moving charge
- `velocity` (query, optional, string) — Velocity v (m/s)
- `current` (query, optional, string) — Or current I (A) for a wire Example: `10`
- `length` (query, optional, string) — And wire length L (m) Example: `0.2`
- `angle` (query, optional, string) — Angle θ to the field (deg, default 90) Example: `90`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/magnetic-api/v1/force?magnetic_field=0.5&current=10&length=0.2&angle=90"
```

**Response:**
```json
{
    "data": {
        "mode": "current_wire",
        "force_n": 1,
        "formula": "F = B·I·L·sin(θ).",
        "length_m": 0.2,
        "angle_deg": 90,
        "current_a": 10,
        "force_per_metre_n": 5,
        "magnetic_field_tesla": 0.5
    },
    "meta": {
        "timestamp": "2026-06-04T10:18:44.463Z",
        "request_id": "4bbb84c1-85fa-46b4-9958-899512983c41"
    },
    "status": "ok",
    "message": "Magnetic force",
    "success": true
}
```

#### `GET /v1/solenoid` — Solenoid / loop field

**Parameters:**
- `current` (query, required, string) — Current I (A) Example: `2`
- `turns_per_metre` (query, optional, string) — Turns per metre n (solenoid) Example: `1000`
- `turns` (query, optional, string) — Or total turns N
- `length` (query, optional, string) — And length (m)
- `type` (query, optional, string) — solenoid | loop Example: `solenoid`
- `radius` (query, optional, string) — Radius for a loop (m)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/magnetic-api/v1/solenoid?current=2&turns_per_metre=1000&type=solenoid"
```

**Response:**
```json
{
    "data": {
        "formula": "B = μ0·n·I (n = turns per metre) inside a long solenoid.",
        "current_a": 2,
        "configuration": "solenoid",
        "turns_per_metre": 1000,
        "magnetic_field_mt": 2.5132741242,
        "magnetic_field_ut": 2513.27412424,
        "magnetic_field_gauss": 25.13274124,
        "magnetic_field_tesla": 0.00251327412424
    },
    "meta": {
        "timestamp": "2026-06-04T10:18:44.561Z",
        "request_id": "e69a4485-593c-4640-a185-b9a88ab65f18"
    },
    "status": "ok",
    "message": "Solenoid / loop field",
    "success": true
}
```

#### `GET /v1/wire` — Field around a straight wire

**Parameters:**
- `current` (query, optional, string) — Current I (A) Example: `10`
- `distance` (query, optional, string) — Distance r from the wire (m) Example: `0.05`
- `magnetic_field` (query, optional, string) — Or field B (T) to solve another
- `relative_permeability` (query, optional, string) — Relative permeability (default 1)

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/magnetic-api/v1/wire?current=10&distance=0.05"
```

**Response:**
```json
{
    "data": {
        "formula": "B = μ0·I/(2π·r).",
        "current_a": 10,
        "distance_m": 0.05,
        "magnetic_field_mt": 0.04,
        "magnetic_field_ut": 40.00000002,
        "magnetic_field_gauss": 0.4,
        "magnetic_field_tesla": 4.000000002e-5
    },
    "meta": {
        "timestamp": "2026-06-04T10:18:44.667Z",
        "request_id": "c44dd53a-8a40-4958-89d1-b24aa73a1a2f"
    },
    "status": "ok",
    "message": "Field around a straight wire",
    "success": true
}
```

### Meta

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

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

**Response:**
```json
{
    "data": {
        "api": "magnetic",
        "note": "Magnetic fields & forces — computed locally and deterministically, no key, no third-party service.",
        "constants": {
            "vacuum_permeability": 1.25663706212e-6
        },
        "endpoints": [
            "/v1/wire",
            "/v1/solenoid",
            "/v1/force",
            "/v1/meta"
        ]
    },
    "meta": {
        "timestamp": "2026-06-04T10:18:44.774Z",
        "request_id": "b3a911c3-20da-4384-9c9b-59e42e9ba5a3"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


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