SerpBase
Back to Blog

Unit Converter API from Google Search: Miles, Cups, Pounds as JSON

Send 5 miles to km as a Google query and the Unit Converter card comes back as featured_snippet. Five conversions tested, with a parser.

December 2, 2026
By SerpBase Team2 min read

Short answer: send the conversion as a query — 5 miles to km — to /google/search. Google's unit converter comes back as featured_snippet with the title "Unit Converter" and the result in one line, for 1 credit.

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":"5 miles to km","gl":"us","hl":"en","device":"desktop"}'

What came back

Five conversions on 2 December 2026:

QueryLayoutfeatured_snippet.snippet
5 miles to kmdesktop5 Mile = 8.04672 Kilometer
100 f to cdesktop100 Fahrenheit = 37.7778 Degree Celsius
150 lbs to kgphone150 Pound = 68.0389 Kilogram
1 cup to mlphone1 US cup = 236.588 Milliliter
how many ounces in a cupdesktop1 US cup = 8 US fluid ounce

Each came back as:

"featured_snippet": {
  "title": "Unit Converter",
  "snippet": "5 Mile = 8.04672 Kilometer"
}

Note the last row: a question in plain words ("how many ounces in a cup") triggered the same card, and Google chose US units because the search was made with gl: "us".

Python: parse value and units

import re, requests

def google_convert(q):
    r = requests.post(
        "https://api.serpbase.dev/google/search",
        headers={"X-API-Key": "YOUR_API_KEY"},
        json={"q": q, "gl": "us", "hl": "en", "device": "desktop"},
        timeout=60,
    ).json()
    if r["status"] != 0:
        raise SystemExit(r.get("error"))
    card = r.get("featured_snippet") or {}
    if card.get("title") != "Unit Converter":
        return None
    m = re.match(r"([\d,.]+) (.+?) = ([\d,.]+) (.+)", card["snippet"])
    return m.groups() if m else card["snippet"]

print(google_convert("100 f to c"))  # ('100', 'Fahrenheit', '37.7778', 'Degree Celsius')

Things that trip people up

  • Units are singular names. "Mile", "Kilometer", "Degree Celsius" — map them to your own unit codes.
  • Country matters for ambiguous units. Cups, gallons and ounces differ between US and imperial measures; the card says which ("US cup"). Set gl to the market you care about.
  • For plain arithmetic you do not need an API. Converting a fixed unit pair is a constant; use the search when users type free-form conversions and you want Google's interpretation.
  • Not every phrasing triggers the card. If featured_snippet is missing or has another title, fall back to your own conversion.

Related

Cost and docs

A Google search is 1 credit, with or without operators. Failed requests are not charged, and new accounts get 500 free credits.