SerpBase
Back to Blog

Google Calculator API: Math Answers From Google Search as JSON

Send a sum such as 15% of 240 to /google/search and read featured_snippet. Four sums tested, with a Python helper that returns the number.

December 4, 2026
By SerpBase Team2 min read

Short answer: send the sum as a normal search query to /google/search and read featured_snippet. When Google shows its calculator, the answer comes back as one line of text, for example "15% of 240 = 36", under the title "Calculator". All four sums we tried on 4 December 2026 returned one.

The request

curl -X POST 'https://api.serpbase.dev/google/search' \
  -H 'Content-Type: application/json' \
  -H 'X-API-Key: YOUR_API_KEY' \
  -d '{"q":"15% of 240","gl":"us","hl":"en"}'

What came back

{
  "status": 0,
  "credits_charged": 1,
  "query": "15% of 240",
  "featured_snippet": {
    "title": "Calculator",
    "snippet": "15% of 240 = 36",
    "position": 1
  },
  "organic": []
}

The four tests:

queryfeatured_snippet.snippet
15% of 24015% of 240 = 36
18% of 64.5018% of 64.50 = 11.61
(12*7)+5(12 * 7) + 5 = 89
sqrt(144)sqrt(144) = 12

The rest of the results page (7 to 9 organic results in these runs) comes back in the same answer, as with any search.

Python: get the number

import requests

def google_calc(expression):
    r = requests.post(
        "https://api.serpbase.dev/google/search",
        headers={"X-API-Key": "YOUR_API_KEY"},
        json={"q": expression, "gl": "us", "hl": "en"},
        timeout=60,
    ).json()
    if r["status"] != 0:
        raise RuntimeError(r.get("error"))
    card = r.get("featured_snippet") or {}
    if card.get("title") != "Calculator" or " = " not in card.get("snippet", ""):
        return None                      # Google showed no calculator for this query
    text = card["snippet"].rsplit(" = ", 1)[1]
    try:
        return float(text.replace(",", ""))
    except ValueError:
        return text                      # keep answers that are not a plain number

print(google_calc("15% of 240"))

When this is useful

  • Questions typed by people. "18% of 64.50" or "15% of 240" are written the way a person asks; Google parses them, so you do not have to.
  • Checking what Google shows. If you build a calculator page or a snippet-tracking tool, this tells you whether Google answers the query itself before any website gets a click.
  • One tool for an agent. An assistant that already calls a search API can answer simple sums through the same call.

For plain arithmetic inside your own program, compute it locally — it is faster and costs nothing.

Things that trip people up

  • Check the title. featured_snippet is also used for other answer boxes (unit conversions arrive as "Unit Converter", and currency conversions use the same field), so test for "Calculator".
  • The answer is text. Split on the last " = "; Google may add spaces to what you typed ((12*7)+5 came back as (12 * 7) + 5 = 89).
  • position is not always 1. For sqrt(144) it was 2. Do not rely on it.
  • No calculator, no field. If Google does not recognise the query as a sum, featured_snippet is absent and you get an ordinary results page; it still costs 1 credit.

Cost and docs

A Google search is 1 credit, $0.25–$0.50 per 1,000 depending on the pack. Failed requests are not charged, and new accounts get 500 free credits.