Calculator

Evaluate mathematical expressions: arithmetic, algebra, trig, logarithms, unit conversions, and plain English queries.

⚡ 1 credit per call

Try it

Fill in the fields below and hit Send.

Why use this

Models get maths wrong. This offloads calculation to a proper evaluator. Accepts mathjs syntax or plain English.

Pricing

Any call 1 credit

Request format

Send a single expression field — either mathjs syntax or plain English:

{ "expression": "sqrt(144)" }
{ "expression": "square root of 144" }

Plain English input is echoed back in its normalised mathjs form:

{ "result": 12, "expression": "sqrt(144)" }

What you can send

mathjs expressions

Anything the mathjs expression parser accepts:

2 + 3 * 4           → 14
(2 + 3) * 4         → 20
sqrt(81)            → 9
2^8                 → 256
pi * 5^2            → 78.54...
log(100, 10)        → 2
sin(pi / 2)         → 1

Unit conversions (mathjs native)

1 mile to km                    → 1.609...
1 feet to m                     → 0.3048
100 celsius to fahrenheit       → 212
32 fahrenheit to celsius        → 0

Plain English

what is 2 + 2                   → 4
15 percent of 340               → 51
15% of 340                      → 51
square root of 144              → 12
cube root of 27                 → 3
2 to the power of 8             → 256
9 squared                       → 81
3 cubed                         → 27
half of 60                      → 30
double 15                       → 30
10 plus 5                       → 15
10 divided by 5                 → 2

Error responses

Invalid or unrecognisable expressions return 400 — no credit charged:

{
  "error": "VALIDATION_ERROR",
  "message": "Cannot evaluate: \"banana phone\". Try a mathjs expression (e.g. \"sqrt(144)\") or plain English (e.g. \"square root of 144\")."
}

API Reference

Endpoint

POST https://api.lightningapi.tools/calculator/calculate

Required headers

Authorization: Bearer <apiKey>
Content-Type: application/json

Example request

{
  "expression": "sqrt(144)"
}

Example response

{
  "result": 12,
  "expression": "sqrt(144)"
}