Zelvyn
Home/Docs

Documentation

Math | Data | Decisions — deterministic APIs with a consistent response envelope across all domains.

Overview

Zelvyn provides a simple, predictable JSON API for mathematics, statistics and business analytics. Unless the control plane has narrowed it for a specific endpoint, every operation returns the standard envelope:

json
{
  "success": true,
  "data": { "result": 0.3 },
  "meta": {
    "requestId": "req_01HX...",
    "timestamp": "2026-01-01T00:00:00.000Z",
    "durationMs": 4
  }
}
json
{
  "success": false,
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "values must contain at least 1 value",
    "details": { "field": "values" }
  },
  "meta": {
    "requestId": "req_01HX...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}
43operations, all documented here
10,000values per dataset
1024 KiBmaximum request body
v1stable API version

No computation is persisted. Results are deterministic and validation is consistent across every endpoint.

Base URL

All public endpoints are served from:

url
https://api-zelvyn.devs.surf

Paths follow one shape: /api/v1/{domain}/{operation}. The domain is one of statistics, mathematics, business analytics, and the operation is the slug of the calculation. The health probe at /api/v1/health is the single path without an operation.

Quick start

Get started in minutes with a simple request.

cURL

bash
# Works without a key. Optional: add -H 'Authorization: Bearer $ZELVYN_API_KEY'
curl -X POST https://api-zelvyn.devs.surf/api/v1/math/add \
  -H "Content-Type: application/json" \
  -d '{"values":[0.1,0.2]}'

JavaScript (fetch)

javascript
const res = await fetch("https://api-zelvyn.devs.surf/api/v1/math/add", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    // Optional, if you have a key (higher rate limit):
    // Authorization: `Bearer ${process.env.ZELVYN_API_KEY}`,
  },
  body: JSON.stringify({ values: [0.1, 0.2] }),
});
const json = await res.json();

Python (requests)

python
import requests

res = requests.post(
    "https://api-zelvyn.devs.surf/api/v1/math/add",
    headers={
        "Content-Type": "application/json",
        # Optional, if you have a key (higher rate limit):
        # "Authorization": f"Bearer {os.environ['ZELVYN_API_KEY']}",
    },
    json={"values": [0.1, 0.2]},
)
print(res.json())

Response

json
{
  "success": true,
  "data": { "result": 0.3 },
  "meta": {
    "requestId": "req_01HX...",
    "timestamp": "2026-01-01T00:00:00.000Z",
    "durationMs": 4
  }
}

Authentication

No API key is required. Every calculation endpoint works on the anonymous rate limit. If you have a key, send it as Authorization: Bearer <key> or x-api-key: <key> to use your plan's higher limit and quota. Keys are scoped to an environment and a plan. To request a higher limit, contact support.

Conventions

These rules hold on every endpoint, so an integration only has to learn them once.

RuleWhat it means
Strict bodiesUnknown fields are rejected, not ignored — a typo surfaces as a precise VALIDATION_ERROR.
Percent pointsPercentage metrics return percent points: 40 means 40%, never 0.4. roas is the exception — it is a plain ratio, so 4 means 4×.
Decimal exactnessArithmetic is computed with 40 significant digits internally, so 0.1 + 0.2 is exactly 0.3.
Exact big integersInteger results beyond Number.MAX_SAFE_INTEGER are returned as decimal strings — never rounded, never truncated.
CorrelationSend x-request-id and it is echoed in meta.requestId; otherwise the API generates a UUID.
POST onlyEvery calculation is a POST with a JSON body — the path says what to compute, the body says what to compute it with.
VersioningThe version lives in the path (/api/v1). A breaking change ships as a new path; the old one keeps serving until its sunset date is announced.

Mathematics

16 deterministic operations covering arithmetic, powers, roots, logarithms, combinatorics and number theory. Every one of them below is documented with the fields it reads and the answer it gives.

Add numbers

POST/api/v1/math/add

Try it →

Returns the sum of the values (Σ valuesᵢ). Decimal-exact internally (40 significant digits), so [0.1, 0.2] returns 0.3. Negatives and zero are allowed.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to add. 1–10,000 values.

Request

json
{
  "values": [
    0.1,
    0.2,
    0.3
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "add",
    "result": 0.6
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Subtract numbers (left to right)

POST/api/v1/math/subtract

Try it →

Returns values₀ − values₁ − values₂ − …, evaluated strictly left to right — the array is the expression. Requires at least two values.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to subtract. 2–10,000 values.

Request

json
{
  "values": [
    10,
    3,
    4
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "subtract",
    "result": 3
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Multiply numbers

POST/api/v1/math/multiply

Try it →

Returns the product of the values (Π valuesᵢ). Decimal-exact internally.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to multiply. 1–10,000 values.

Request

json
{
  "values": [
    2,
    3,
    4
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "multiply",
    "result": 24
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Divide numbers (left to right)

POST/api/v1/math/divide

Try it →

Returns values₀ ÷ values₁ ÷ values₂ ÷ …, evaluated strictly left to right. A zero divisor is a DIVISION_BY_ZERO domain error (HTTP 422), not a validation error.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to divide. 2–10,000 values.

Request

json
{
  "values": [
    100,
    4,
    5
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "divide",
    "result": 5
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Percent of a value

POST/api/v1/math/percent-of

Try it →

Returns (percentage / 100) × value. Both inputs are finite numbers; negatives are allowed.

FieldTypeRequiredNotes
percentagenumberyesThe percentage rate, as percent points (15 means 15%).
valuenumberyesThe base value the percentage is taken from.

Request

json
{
  "percentage": 15,
  "value": 240
}

Response

json
{
  "success": true,
  "data": {
    "operation": "percent-of",
    "result": 36
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Percentage change between two values

POST/api/v1/math/percentage-change

Try it →

Returns ((to − from) / from) × 100 as percent points (so 25 means +25%). The signed from value is the denominator; from = 0 has no defined relative change and yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
fromnumberyesThe starting value — the denominator of the change.
tonumberyesThe ending value — the numerator of the change.

Request

json
{
  "from": 80,
  "to": 100
}

Response

json
{
  "success": true,
  "data": {
    "operation": "percentage-change",
    "result": 25
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Raise a base to an exponent

POST/api/v1/math/power

Try it →

Returns base^exponent. 0^0 = 1 and 0^positive = 0 by convention; 0^negative yields DIVISION_BY_ZERO (422); a negative base with a non-integer exponent yields UNDEFINED_RESULT (422); overflow yields UNDEFINED_RESULT (422).

FieldTypeRequiredNotes
basenumberyesThe base of the power.
exponentnumberyesThe exponent applied to the base.

Request

json
{
  "base": 2,
  "exponent": 10
}

Response

json
{
  "success": true,
  "data": {
    "operation": "power",
    "result": 1024
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Square root

POST/api/v1/math/sqrt

Try it →

Returns the principal (non-negative) square root. A negative input has no real square root and yields UNDEFINED_RESULT (HTTP 422).

FieldTypeRequiredNotes
valuenumberyesThe value to take the square root of.

Request

json
{
  "value": 144
}

Response

json
{
  "success": true,
  "data": {
    "operation": "sqrt",
    "result": 12
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

N-th root

POST/api/v1/math/nth-root

Try it →

Returns the principal real degree-th root of the value. The degree is an integer from 1 to 10,000. An even root of a negative value yields UNDEFINED_RESULT (422); odd roots of negatives return the negative real root.

FieldTypeRequiredNotes
valuenumberyesThe value to take the root of.
degreeintegeryesThe degree of the root — an integer from 1 to 10,000.

Request

json
{
  "value": 27,
  "degree": 3
}

Response

json
{
  "success": true,
  "data": {
    "operation": "nth-root",
    "result": 3
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Logarithm to a base (default 10)

POST/api/v1/math/log

Try it →

Returns the logarithm of the value to the given base. The base is optional and defaults to 10. value ≤ 0, base ≤ 0 and base = 1 yield UNDEFINED_RESULT (HTTP 422).

FieldTypeRequiredNotes
valuenumberyesThe value to take the logarithm of.
basenumbernoThe logarithm base. Defaults to 10 when omitted.

Request

json
{
  "value": 1000
}

Response

json
{
  "success": true,
  "data": {
    "operation": "log",
    "result": 3
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Natural logarithm

POST/api/v1/math/ln

Try it →

Returns the natural logarithm (base e). value ≤ 0 yields UNDEFINED_RESULT (HTTP 422).

FieldTypeRequiredNotes
valuenumberyesThe value to take the natural logarithm of.

Request

json
{
  "value": 1
}

Response

json
{
  "success": true,
  "data": {
    "operation": "ln",
    "result": 0
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Factorial

POST/api/v1/math/factorial

Try it →

Returns n! for an integer n from 0 to 1,000 (0! = 1). Exact integer results beyond Number.MAX_SAFE_INTEGER are returned as decimal strings and are never rounded.

FieldTypeRequiredNotes
nintegeryesThe number to take the factorial of — 0 to 1,000.

Request

json
{
  "n": 5
}

Response

json
{
  "success": true,
  "data": {
    "operation": "factorial",
    "result": 120
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Greatest common divisor

POST/api/v1/math/gcd

Try it →

Returns the greatest common divisor of two integers, sign-independently. gcd(0, b) = |b|; gcd(0, 0) yields UNDEFINED_RESULT (HTTP 422). Both inputs must be safe integers.

FieldTypeRequiredNotes
aintegeryesThe first integer — signs are ignored.
bintegeryesThe second integer — signs are ignored.

Request

json
{
  "a": 12,
  "b": 18
}

Response

json
{
  "success": true,
  "data": {
    "operation": "gcd",
    "result": 6
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Least common multiple

POST/api/v1/math/lcm

Try it →

Returns the least common multiple of two integers, sign-independently. lcm(0, b) = 0; lcm(0, 0) yields UNDEFINED_RESULT (HTTP 422). Both inputs must be safe integers.

FieldTypeRequiredNotes
aintegeryesThe first integer — signs are ignored.
bintegeryesThe second integer — signs are ignored.

Request

json
{
  "a": 4,
  "b": 6
}

Response

json
{
  "success": true,
  "data": {
    "operation": "lcm",
    "result": 12
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Permutations P(n, r)

POST/api/v1/math/permutations

Try it →

Returns the number of ordered selections P(n, r) = n! / (n − r)!. n and r are integers from 0 to 1,000 and the contract requires r ≤ n. Exact integer results beyond Number.MAX_SAFE_INTEGER are returned as decimal strings.

FieldTypeRequiredNotes
nintegeryesThe population size — 0 to 1,000.
rintegeryesThe number of selections — 0 to 1,000 and never greater than n.

Request

json
{
  "n": 5,
  "r": 2
}

Response

json
{
  "success": true,
  "data": {
    "operation": "permutations",
    "result": 20
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Combinations C(n, r)

POST/api/v1/math/combinations

Try it →

Returns the number of unordered selections C(n, r) = n! / (r! (n − r)!). n and r are integers from 0 to 1,000 and the contract requires r ≤ n. Exact integer results beyond Number.MAX_SAFE_INTEGER are returned as decimal strings.

FieldTypeRequiredNotes
nintegeryesThe population size — 0 to 1,000.
rintegeryesThe number of selections — 0 to 1,000 and never greater than n.

Request

json
{
  "n": 52,
  "r": 5
}

Response

json
{
  "success": true,
  "data": {
    "operation": "combinations",
    "result": 2598960
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Statistics

9 descriptive statistics over datasets of up to 10,000 values, computed with compensated summation.

Arithmetic mean

POST/api/v1/statistics/mean

Try it →

Returns the arithmetic mean of the dataset (Σ xᵢ / n). Uses Neumaier compensated summation, so datasets with widely varying magnitudes keep their low-order digits.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to average. 1–10,000 values.

Request

json
{
  "values": [
    10,
    20,
    30
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "mean",
    "result": 20
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Median

POST/api/v1/statistics/median

Try it →

Returns the middle value of the sorted dataset, or the mean of the two middle values when the count is even.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to sort and read the middle of. 1–10,000 values.

Request

json
{
  "values": [
    1,
    3,
    2,
    5,
    4
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "median",
    "result": 3
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Population variance

POST/api/v1/statistics/variance

Try it →

Returns the population variance σ² = (Σ (xᵢ − μ)²) / n — divided by n, not n−1. Decimal-exact two-pass computation; never negative.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to measure the spread of. 1–10,000 values.

Request

json
{
  "values": [
    2,
    4,
    4,
    4,
    5,
    5,
    7,
    9
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "variance",
    "result": 4
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Population standard deviation

POST/api/v1/statistics/standard-deviation

Try it →

Returns the population standard deviation σ — the square root of the population variance (divided by n). Never negative.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to measure the spread of. 1–10,000 values.

Request

json
{
  "values": [
    2,
    4,
    4,
    4,
    5,
    5,
    7,
    9
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "standard-deviation",
    "result": 2
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Percentile (linear interpolation)

POST/api/v1/statistics/percentile

Try it →

Returns the requested percentile of the dataset using linear interpolation between the closest ranks (the inclusive NumPy definition). 0 is the minimum, 100 the maximum.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to read the percentile from. 1–10,000 values.
percentilenumberyesTarget percentile between 0 and 100 (inclusive).

Request

json
{
  "values": [
    1,
    2,
    3,
    4
  ],
  "percentile": 75
}

Response

json
{
  "success": true,
  "data": {
    "operation": "percentile",
    "result": 3.25
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Sum of a dataset

POST/api/v1/statistics/sum

Try it →

Returns the sum of the dataset (Σ xᵢ), decimal-exact. Equivalent to /api/v1/math/add for numeric arrays.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to add up. 1–10,000 values.

Request

json
{
  "values": [
    10,
    20,
    30
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "sum",
    "result": 60
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Minimum value

POST/api/v1/statistics/min

Try it →

Returns the smallest value in the dataset.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to compare. 1–10,000 values.

Request

json
{
  "values": [
    3,
    1,
    4,
    1,
    5
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "min",
    "result": 1
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Maximum value

POST/api/v1/statistics/max

Try it →

Returns the largest value in the dataset.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to compare. 1–10,000 values.

Request

json
{
  "values": [
    3,
    1,
    4,
    1,
    5
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "max",
    "result": 5
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Range (max − min)

POST/api/v1/statistics/range

Try it →

Returns max − min, the spread of the dataset. Non-negative by construction.

FieldTypeRequiredNotes
valuesnumber[]yesFinite numbers to measure. 1–10,000 values.

Request

json
{
  "values": [
    3,
    1,
    4,
    1,
    5
  ]
}

Response

json
{
  "success": true,
  "data": {
    "operation": "range",
    "result": 4
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Business analytics

17 business metrics — profitability, growth, marketing efficiency, pricing, retention and customer value — under the same contract as everything else.

Profit

POST/api/v1/business/profit

Try it →

Returns revenue − costs. Monetary inputs are signed, so a negative result is a meaningful loss.

FieldTypeRequiredNotes
revenuenumberyesTotal revenue.
costsnumberyesTotal costs.

Request

json
{
  "revenue": 1000,
  "costs": 600
}

Response

json
{
  "success": true,
  "data": {
    "operation": "profit",
    "result": 400
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Profit margin (percent)

POST/api/v1/business/profit-margin

Try it →

Returns (revenue − costs) / revenue × 100 as percent points (40 means 40%). revenue = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
revenuenumberyesTotal revenue.
costsnumberyesTotal costs.

Request

json
{
  "revenue": 1000,
  "costs": 600
}

Response

json
{
  "success": true,
  "data": {
    "operation": "profit-margin",
    "result": 40
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Markup (percent)

POST/api/v1/business/markup

Try it →

Returns (price − cost) / cost × 100 as percent points. cost = 0 yields DIVISION_BY_ZERO (HTTP 422). Distinct from margin, which is based on revenue/price.

FieldTypeRequiredNotes
pricenumberyesThe selling price.
costnumberyesThe unit cost.

Request

json
{
  "price": 120,
  "cost": 100
}

Response

json
{
  "success": true,
  "data": {
    "operation": "markup",
    "result": 20
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Return on investment ROI (percent)

POST/api/v1/business/roi

Try it →

Returns profit / investment × 100 as percent points, where profit is the net gain. investment = 0 yields DIVISION_BY_ZERO (HTTP 422). Distinct from ROAS, which is a revenue ratio.

FieldTypeRequiredNotes
profitnumberyesThe net gain of the investment.
investmentnumberyesThe amount invested.

Request

json
{
  "profit": 250,
  "investment": 1000
}

Response

json
{
  "success": true,
  "data": {
    "operation": "roi",
    "result": 25
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Return on ad spend ROAS (ratio)

POST/api/v1/business/roas

Try it →

Returns revenue / adSpend as a plain ratio (4 means 4×). adSpend = 0 yields DIVISION_BY_ZERO (HTTP 422). Unlike ROI, this is not multiplied by 100.

FieldTypeRequiredNotes
revenuenumberyesRevenue attributed to ads.
adSpendnumberyesThe money spent on ads — never negative.

Request

json
{
  "revenue": 4000,
  "adSpend": 1000
}

Response

json
{
  "success": true,
  "data": {
    "operation": "roas",
    "result": 4
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Compound annual growth rate CAGR (percent)

POST/api/v1/business/cagr

Try it →

Returns ((endValue / beginValue)^(1 / periods) − 1) × 100 as percent points. periods must be greater than 0. beginValue ≤ 0 or endValue < 0 yields UNDEFINED_RESULT (HTTP 422); a total loss returns −100.

FieldTypeRequiredNotes
beginValuenumberyesThe value at the start of the period.
endValuenumberyesThe value at the end of the period.
periodsnumberyesThe number of compounding periods — greater than 0.

Request

json
{
  "beginValue": 100,
  "endValue": 121,
  "periods": 2
}

Response

json
{
  "success": true,
  "data": {
    "operation": "cagr",
    "result": 10
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Break-even volume (units)

POST/api/v1/business/break-even

Try it →

Returns fixedCosts / (price − variableCost) — the number of units needed to cover the fixed costs (may be fractional). A contribution of price − variableCost ≤ 0 makes break-even unreachable and yields UNDEFINED_RESULT (HTTP 422).

FieldTypeRequiredNotes
fixedCostsnumberyesCosts incurred regardless of volume.
pricenumberyesThe selling price per unit.
variableCostnumberyesThe cost per unit sold.

Request

json
{
  "fixedCosts": 1000,
  "price": 20,
  "variableCost": 12
}

Response

json
{
  "success": true,
  "data": {
    "operation": "break-even",
    "result": 125
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Conversion rate (percent)

POST/api/v1/business/conversion-rate

Try it →

Returns conversions / sessions × 100 as percent points. Counts are non-negative. sessions = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
conversionsnumberyesNumber of conversions — never negative.
sessionsnumberyesNumber of sessions — never negative.

Request

json
{
  "conversions": 50,
  "sessions": 1000
}

Response

json
{
  "success": true,
  "data": {
    "operation": "conversion-rate",
    "result": 5
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Click-through rate CTR (percent)

POST/api/v1/business/ctr

Try it →

Returns clicks / impressions × 100 as percent points. Counts are non-negative. impressions = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
clicksnumberyesNumber of clicks — never negative.
impressionsnumberyesNumber of impressions — never negative.

Request

json
{
  "clicks": 100,
  "impressions": 10000
}

Response

json
{
  "success": true,
  "data": {
    "operation": "ctr",
    "result": 1
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Cost per click CPC

POST/api/v1/business/cpc

Try it →

Returns cost / clicks. cost and clicks are non-negative. clicks = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
costnumberyesTotal cost — never negative.
clicksnumberyesNumber of clicks — never negative.

Request

json
{
  "cost": 250,
  "clicks": 100
}

Response

json
{
  "success": true,
  "data": {
    "operation": "cpc",
    "result": 2.5
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Cost per mille CPM

POST/api/v1/business/cpm

Try it →

Returns cost / impressions × 1000 — the cost per 1,000 impressions. impressions = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
costnumberyesTotal cost — never negative.
impressionsnumberyesNumber of impressions — never negative.

Request

json
{
  "cost": 500,
  "impressions": 100000
}

Response

json
{
  "success": true,
  "data": {
    "operation": "cpm",
    "result": 5
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Cost per acquisition CPA

POST/api/v1/business/cpa

Try it →

Returns cost / conversions. conversions = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
costnumberyesTotal cost — never negative.
conversionsnumberyesNumber of conversions — never negative.

Request

json
{
  "cost": 500,
  "conversions": 25
}

Response

json
{
  "success": true,
  "data": {
    "operation": "cpa",
    "result": 20
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Customer acquisition cost CAC

POST/api/v1/business/cac

Try it →

Returns cost / customers. customers = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
costnumberyesTotal cost — never negative.
customersnumberyesNumber of customers acquired — never negative.

Request

json
{
  "cost": 5000,
  "customers": 50
}

Response

json
{
  "success": true,
  "data": {
    "operation": "cac",
    "result": 100
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Average order value AOV

POST/api/v1/business/aov

Try it →

Returns revenue / orders. revenue is signed; orders is non-negative. orders = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
revenuenumberyesTotal revenue.
ordersnumberyesNumber of orders — never negative.

Request

json
{
  "revenue": 10000,
  "orders": 200
}

Response

json
{
  "success": true,
  "data": {
    "operation": "aov",
    "result": 50
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Retention rate (percent)

POST/api/v1/business/retention-rate

Try it →

Returns retained / starting × 100 as percent points. Counts are non-negative. starting = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
retainednumberyesCustomers retained — never negative.
startingnumberyesCustomers at the start of the period — never negative.

Request

json
{
  "retained": 900,
  "starting": 1000
}

Response

json
{
  "success": true,
  "data": {
    "operation": "retention-rate",
    "result": 90
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Churn rate (percent)

POST/api/v1/business/churn-rate

Try it →

Returns churned / starting × 100 as percent points. Counts are non-negative. starting = 0 yields DIVISION_BY_ZERO (HTTP 422).

FieldTypeRequiredNotes
churnednumberyesCustomers lost — never negative.
startingnumberyesCustomers at the start of the period — never negative.

Request

json
{
  "churned": 100,
  "starting": 1000
}

Response

json
{
  "success": true,
  "data": {
    "operation": "churn-rate",
    "result": 10
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Customer lifetime value CLV

POST/api/v1/business/clv

Try it →

Returns averageOrderValue × purchasesPerPeriod × lifespanPeriods. No currency is assumed. Exact integer results beyond Number.MAX_SAFE_INTEGER are returned as decimal strings.

FieldTypeRequiredNotes
averageOrderValuenumberyesThe average value of one order.
purchasesPerPeriodnumberyesPurchases per period — never negative.
lifespanPeriodsnumberyesHow many periods the customer stays — never negative.

Request

json
{
  "averageOrderValue": 50,
  "purchasesPerPeriod": 12,
  "lifespanPeriods": 3
}

Response

json
{
  "success": true,
  "data": {
    "operation": "clv",
    "result": 1800
  },
  "meta": {
    "requestId": "req_...",
    "timestamp": "2026-01-01T00:00:00.000Z"
  }
}

Endpoint reference

Every path the API answers, in one table — the fields each one requires, at a glance.

MethodPathRequired fieldsSummary
GET/api/v1/health—Liveness / readiness probe
POST/api/v1/statistics/meanvaluesArithmetic mean
POST/api/v1/statistics/medianvaluesMedian
POST/api/v1/statistics/variancevaluesPopulation variance
POST/api/v1/statistics/standard-deviationvaluesPopulation standard deviation
POST/api/v1/statistics/percentilevalues, percentilePercentile (linear interpolation)
POST/api/v1/statistics/sumvaluesSum of a dataset
POST/api/v1/statistics/minvaluesMinimum value
POST/api/v1/statistics/maxvaluesMaximum value
POST/api/v1/statistics/rangevaluesRange (max − min)
POST/api/v1/math/addvaluesAdd numbers
POST/api/v1/math/subtractvaluesSubtract numbers (left to right)
POST/api/v1/math/multiplyvaluesMultiply numbers
POST/api/v1/math/dividevaluesDivide numbers (left to right)
POST/api/v1/math/percent-ofpercentage, valuePercent of a value
POST/api/v1/math/percentage-changefrom, toPercentage change between two values
POST/api/v1/math/powerbase, exponentRaise a base to an exponent
POST/api/v1/math/sqrtvalueSquare root
POST/api/v1/math/nth-rootvalue, degreeN-th root
POST/api/v1/math/logvalueLogarithm to a base (default 10)
POST/api/v1/math/lnvalueNatural logarithm
POST/api/v1/math/factorialnFactorial
POST/api/v1/math/gcda, bGreatest common divisor
POST/api/v1/math/lcma, bLeast common multiple
POST/api/v1/math/permutationsn, rPermutations P(n, r)
POST/api/v1/math/combinationsn, rCombinations C(n, r)
POST/api/v1/business/profitrevenue, costsProfit
POST/api/v1/business/profit-marginrevenue, costsProfit margin (percent)
POST/api/v1/business/markupprice, costMarkup (percent)
POST/api/v1/business/roiprofit, investmentReturn on investment ROI (percent)
POST/api/v1/business/roasrevenue, adSpendReturn on ad spend ROAS (ratio)
POST/api/v1/business/cagrbeginValue, endValue, periodsCompound annual growth rate CAGR (percent)
POST/api/v1/business/break-evenfixedCosts, price, variableCostBreak-even volume (units)
POST/api/v1/business/conversion-rateconversions, sessionsConversion rate (percent)
POST/api/v1/business/ctrclicks, impressionsClick-through rate CTR (percent)
POST/api/v1/business/cpccost, clicksCost per click CPC
POST/api/v1/business/cpmcost, impressionsCost per mille CPM
POST/api/v1/business/cpacost, conversionsCost per acquisition CPA
POST/api/v1/business/caccost, customersCustomer acquisition cost CAC
POST/api/v1/business/aovrevenue, ordersAverage order value AOV
POST/api/v1/business/retention-rateretained, startingRetention rate (percent)
POST/api/v1/business/churn-ratechurned, startingChurn rate (percent)
POST/api/v1/business/clvaverageOrderValue, purchasesPerPeriod, lifespanPeriodsCustomer lifetime value CLV

Errors

Errors always arrive in the same envelope, with a stable error.code. Branch on the code, not on the message.

HTTPCodeMeaning
400VALIDATION_ERRORMalformed body, wrong type, unknown field or out-of-range value
404INVALID_OPERATIONUnknown endpoint or operation
405METHOD_NOT_ALLOWEDThe path exists but not for this HTTP method
410ENDPOINT_SUNSETThe endpoint was retired on the date in the sunset header
413PAYLOAD_TOO_LARGERequest body exceeds the 1 MiB limit
422DIVISION_BY_ZEROThe denominator of the operation is zero
422UNDEFINED_RESULTThe result is mathematically or business-undefined
422INVALID_DATASETThe dataset cannot produce a meaningful result
429RATE_LIMITEDThe per-window rate limit was exceeded — check retry-after
500INTERNAL_ERRORUnexpected internal failure
503SERVICE_UNAVAILABLEThe control plane is temporarily unavailable

Rate limits

Live limits are published by the control plane and enforced per caller and per endpoint.

LimitValueNotes
Dataset values10,000Per request, across every statistics operation.
Request body1024 KiBLarger bodies are rejected with PAYLOAD_TOO_LARGE.
Anonymous caller60 requests / minuteMeasured by the API, not by the browser.
Retry signalretry-afterSeconds to wait after a 429 before trying again.

When you exceed a limit, the API answers with RATE_LIMITED and a retry-after header. Wait for that many seconds, then retry — do not tighten a client-side loop.

Troubleshooting

Most failures are precise, and each one has a first move.

SituationFirst moveCollect this
VALIDATION_ERRORRead error.details.field and compare the body with the endpoint reference. Unknown fields are rejected.The exact request body — never an API key.
DIVISION_BY_ZEROCheck the denominator in your payload. The API does not invent a value for an undefined result.The operation and the values that produced it.
PAYLOAD_TOO_LARGESplit the dataset or trim the body below 1024 KiB.The body size and the value count.
RATE_LIMITEDWait for retry-after, then retry with backoff.meta.requestId and the plan you are using.
INTERNAL_ERRORRetry once with backoff. If it repeats, report the request id.meta.requestId and the timestamp.

Changelog

The public contract changes deliberately — never silently.

  • v1 — stable API version. Every operation lives under /api/v1 and the response envelope is frozen.
  • OpenAPI 3.1 — the published specification is generated from the same registry the docs render.
  • Response profiles — x-zelvyn-profile can narrow a response to compact, default or detailed.
  • Endpoint controls — operators can disable an endpoint, require auth, or publish a sunset date without a deploy.

OpenAPI

The OpenAPI 3.1 document is the machine-readable version of this reference. Use it to generate a client, validate a request, or import the API into your tooling.

bash
curl -sS https://api-zelvyn.devs.surf/openapi.json