API Directory › 🌦 Weather › OpenWeatherMap
API KeyHTTPSCORS

OpenWeatherMap API

Popular weather API for current conditions, forecasts and historical data across the globe.

Category
Auth
API Key
HTTPS
Yes
CORS
Yes
Open OpenWeatherMap docs ↗

What it does

OpenWeatherMap gives you current conditions, a 5-day / 3-hour forecast, and historical weather for anywhere on Earth, looked up by city name, coordinates or ZIP code. Responses are JSON (XML optional) and include temperature, “feels like”, humidity, pressure, wind, cloud cover and a short condition code you can map to an icon.

Base URL

https://api.openweathermap.org/data/2.5

Authentication

Free: create an account at openweathermap.org, then copy the key from the API keys tab. Pass it as the appid query parameter on every request. A brand-new key takes anywhere from 10 minutes to about 2 hours to activate — until then you’ll get 401s.

Code examples

curl
curl "https://api.openweathermap.org/data/2.5/weather?q=Lagos&units=metric&appid=YOUR_KEY"
Python
import requests

r = requests.get(
    "https://api.openweathermap.org/data/2.5/weather",
    params={"q": "Lagos", "units": "metric", "appid": "YOUR_KEY"},
    timeout=10,
)
r.raise_for_status()
data = r.json()
print(data["main"]["temp"], data["weather"][0]["description"])
JavaScript
const url = "https://api.openweathermap.org/data/2.5/weather"
  + "?q=Lagos&units=metric&appid=YOUR_KEY";

const res = await fetch(url);
if (!res.ok) throw new Error(`OWM ${res.status}`);
const data = await res.json();
console.log(data.main.temp, data.weather[0].description);

Rate limits & quotas

The free plan allows 60 calls/minute and 1,000,000 calls/month. The newer One Call API 3.0 (minute-by-minute + daily forecast + alerts) has its own free allowance of 1,000 calls/day. Go over and you get HTTP 429; the monthly cap is billed per extra call once you add a card. Cache aggressively — weather rarely changes minute to minute.

Key response fields

weather[0].mainCondition group: Clear, Clouds, Rain, Snow, Thunderstorm…
weather[0].descriptionHuman-readable summary, e.g. “light rain”
weather[0].iconIcon code — build the URL https://openweathermap.org/img/wn/{icon}@2x.png
main.tempTemperature in the units you requested (metric=°C, imperial=°F)
main.feels_likePerceived temperature accounting for wind & humidity
main.humidityRelative humidity, %
wind.speedWind speed (m/s metric, mph imperial)
dtData timestamp, Unix UTC seconds
sys.countryISO-3166 country code of the matched location

Common errors

401Missing, misspelled or not-yet-active appid. Wait for activation or regenerate.
404City name not found — try q=City,CC with a country code, or use lat/lon.
429Over 60 calls/min or your daily One Call allowance. Back off and cache.

When to use it (and alternatives)

Reach for OpenWeatherMap as the general-purpose default — broad coverage, generous free tier, simple key auth. For US-only forecasts the National Weather Service API (weather.gov) is free and needs no key. For marine, tide and surf data use Stormglass. For unlimited historical series with no key at all, Open-Meteo is an excellent alternative.

FAQ

Is the OpenWeatherMap API free?

Yes — the free plan covers 60 calls/minute and 1,000,000 calls/month for current weather and the 5-day forecast. One Call API 3.0 needs a card on file but includes 1,000 free calls/day.

Why is my OpenWeatherMap API key returning 401?

New keys take 10 minutes to ~2 hours to activate. If it’s been longer, check for a trailing space, confirm you’re passing it as appid (not apikey), and regenerate the key if needed.

How do I get weather by coordinates instead of city name?

Swap q=City for lat=6.45&lon=3.39. Coordinates are more reliable than names for places that aren’t major cities.

New to APIs?

Short guides for working with this API — and any other.

🛠️ Handy LarzOS tools

Free tools to help you work with this API.

Weather Checker

Related Weather APIs

← Back

More Weather APIs · All 196 APIs