# Statistical Inference API
> Inferential-statistics maths as an API, computed locally and deterministically. The samplesize endpoint computes how many respondents a survey or experiment needs for a proportion, n = Z²·p(1−p)/E², from a confidence level and a margin of error (using p = 0.5 for the most conservative size), with a finite-population correction when the population is known. The confidence endpoint builds a confidence interval for a mean (estimate ± Z·σ/√n) or a proportion (p ± Z·√(p(1−p)/n)), returning the standard error, margin of error and the lower and upper bounds. The ztest endpoint runs a one-sample z-test, z = (x̄ − μ₀)/(σ/√n), and returns the z-score, the one- or two-tailed p-value and whether the result is significant at the chosen alpha. The z-scores come from an exact inverse-normal and the p-values from the normal CDF. Everything is computed locally and deterministically, so it is instant and private. Ideal for A/B-testing, survey, research and analytics app developers, experiment dashboards and data-science tools, and education. Pure local computation — no key, no third-party service, instant. Live, nothing stored. 3 endpoints. This is inferential statistics; for descriptive statistics use a statistics API and for probability distributions use a probability 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/inference-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** ($49/Mo) — 1,571,000 calls/Mo, 40 req/s

## Endpoints

### Inference

#### `GET /v1/confidence` — Confidence interval

**Parameters:**
- `type` (query, optional, string) — mean | proportion (default mean) Example: `mean`
- `n` (query, required, string) — Sample size Example: `50`
- `confidence` (query, optional, string) — Confidence level (%, default 95) Example: `95`
- `mean` (query, optional, string) — Sample mean (type=mean) Example: `100`
- `stddev` (query, optional, string) — Std deviation (type=mean) Example: `15`
- `proportion` (query, optional, string) — Sample proportion (type=proportion) Example: `0.4`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/inference-api/v1/confidence?type=mean&n=50&confidence=95&mean=100&stddev=15&proportion=0.4"
```

**Response:**
```json
{
    "data": {
        "note": "CI = estimate ± Z·SE. For a mean SE = σ/√n; for a proportion SE = √(p(1−p)/n). Uses the normal (z) approximation.",
        "lower": 95.842289,
        "upper": 104.157711,
        "inputs": {
            "n": 50,
            "type": "mean",
            "confidence": 95
        },
        "z_score": 1.959964,
        "estimate": 100,
        "standard_error": 2.12132,
        "margin_of_error": 4.157711
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:14.415Z",
        "request_id": "41e4a104-21cc-4fd3-8779-c6ffdad834fc"
    },
    "status": "ok",
    "message": "Confidence interval",
    "success": true
}
```

#### `GET /v1/samplesize` — Sample size

**Parameters:**
- `confidence` (query, optional, string) — Confidence level (%, default 95) Example: `95`
- `margin_of_error` (query, optional, string) — Margin of error (fraction or %, default 0.05) Example: `0.05`
- `proportion` (query, optional, string) — Expected proportion (default 0.5) Example: `0.5`
- `population` (query, optional, string) — Population size for finite correction Example: `10000`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/inference-api/v1/samplesize?confidence=95&margin_of_error=0.05&proportion=0.5&population=10000"
```

**Response:**
```json
{
    "data": {
        "note": "n = Z²·p(1−p)/E². Use p = 0.5 for the most conservative (largest) sample. Finite-population correction applied when a population is given.",
        "inputs": {
            "confidence": 95,
            "proportion": 0.5,
            "margin_of_error": 0.05
        },
        "z_score": 1.959964,
        "population": 10000,
        "sample_size": 385,
        "sample_size_finite": 370
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:14.517Z",
        "request_id": "c4d5902b-5042-49d0-95ba-9f70397bf606"
    },
    "status": "ok",
    "message": "Sample size",
    "success": true
}
```

#### `GET /v1/ztest` — One-sample z-test

**Parameters:**
- `sample_mean` (query, required, string) — Sample mean Example: `105`
- `population_mean` (query, required, string) — Hypothesised mean μ₀ Example: `100`
- `stddev` (query, required, string) — Population std deviation Example: `15`
- `n` (query, required, string) — Sample size Example: `50`
- `tail` (query, optional, string) — two | left | right (default two) Example: `two`
- `alpha` (query, optional, string) — Significance level (default 0.05) Example: `0.05`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/inference-api/v1/ztest?sample_mean=105&population_mean=100&stddev=15&n=50&tail=two&alpha=0.05"
```

**Response:**
```json
{
    "data": {
        "note": "z = (x̄ − μ₀)/(σ/√n). p-value from the standard normal; significant when p < alpha. Known-σ (z) test.",
        "inputs": {
            "n": 50,
            "tail": "two",
            "alpha": 0.05,
            "stddev": 15,
            "sample_mean": 105,
            "population_mean": 100
        },
        "p_value": 0.01842209,
        "z_score": 2.357023,
        "significant": true,
        "standard_error": 2.12132
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:14.611Z",
        "request_id": "f23825a5-c530-48ca-acdb-6ec2fa76a478"
    },
    "status": "ok",
    "message": "Z-test",
    "success": true
}
```

### Meta

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

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

**Response:**
```json
{
    "data": {
        "notes": "Confidence as a percentage (e.g. 95), margin of error as a fraction or percent. Z-test assumes a known population standard deviation and the normal approximation.",
        "service": "inference-api",
        "formulae": {
            "ztest": "z = (x̄ − μ₀)/(σ/√n)",
            "confidence": "CI = estimate ± Z·SE",
            "sample_size": "n = Z²·p(1−p)/E²"
        },
        "endpoints": {
            "GET /v1/meta": "This document.",
            "GET /v1/ztest": "One-sample z-test with z-score, p-value and significance.",
            "GET /v1/confidence": "Confidence interval for a mean or a proportion.",
            "GET /v1/samplesize": "Sample size for a proportion at a confidence level and margin of error, with finite-population correction."
        },
        "description": "Inferential-statistics calculator: sample-size determination, confidence intervals and the one-sample z-test."
    },
    "meta": {
        "timestamp": "2026-06-04T18:38:14.722Z",
        "request_id": "7f3022db-bc2a-42ae-9e7b-29f82fa7d568"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


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