OpenCage API
Forward and reverse geocoding aggregating many open data sources.
What it does
OpenCage is a forward and reverse geocoding API that aggregates many open datasets (OpenStreetMap, Natural Earth, government sources) behind one clean interface, and enriches every result with annotations: timezone, currency, calling code, sun times, Mercator coordinates and more.
Base URL
Authentication
Sign up for a key and pass it as ?key=YOUR_KEY. The free trial key is generous enough for development and small sites.
Code examples
curl -s "https://api.opencagedata.com/geocode/v1/json?q=Brandenburg+Gate,Berlin&key=$OC_KEY"
import requests
r = requests.get("https://api.opencagedata.com/geocode/v1/json",
params={"q": "52.5163,13.3777", "key": KEY, "no_annotations": 0}, timeout=10)
res = r.json()["results"][0]
print(res["formatted"])
print(res["annotations"]["timezone"]["name"],
res["annotations"]["currency"]["iso_code"])Rate limits & quotas
Free trial: 2,500 requests/day at 1 request/second. The response rate object reports your remaining quota and reset time. Over the limit returns HTTP 402 (quota) or 429 (per-second). Batch by looping — there is no bulk endpoint, but the per-second limit is the only constraint.
Key response fields
| results[].geometry.lat / lng | Coordinates of the match |
| results[].formatted | Human-readable full address |
| results[].components | Structured parts: road, city, postcode, country… |
| results[].confidence | 1–10 rough accuracy score |
| results[].annotations | Timezone, currency, calling code, what3words, sun times |
Common errors
| 401 | Missing or invalid key. |
| 402 | Daily quota used up — resets at midnight UTC. |
| 429 | Exceeded 1 request/second — throttle. |
| 400 / results: [] | Ungeocodable or empty query — check status and result count. |
When to use it (and alternatives)
A great middle ground: cleaner and better-documented than raw Nominatim, with permissive terms (you may store results), and the annotations save you extra API calls. For map tiles and routing you still need Mapbox.
FAQ
Can I cache or store OpenCage results?
Yes — OpenCage explicitly permits storing geocoding results, which many providers forbid. This makes it well suited to building your own address database.
Forward and reverse use the same endpoint?
Yes. Pass a place string for forward geocoding or "lat,lng" for reverse — the API figures out which you meant.
What are annotations good for?
They turn one geocode call into timezone, currency and calling-code lookups too — useful for localisation. Set no_annotations=1 to skip them and shrink the response.
New to APIs?
Short guides for working with this API — and any other.