How to get sunrise, sunset and moon phase for any place with an API
Updated 2026-11-10
Use when an agent needs sunrise, sunset, twilight times or moon phase for a place and date.
From an MCP client, add https://tanod.dev/mcp and call sun_moon_times; the first 5 calls per IP per UTC day are free (shared by all skypeek tools), then each call is USD 0.001 with x402, no key or signup.
POST a latitude, longitude, date and time zone to /v1/space/sun-moon. It returns sunrise, sunset, solar noon, day length, three kinds of twilight, moonrise, moonset, moon phase, illumination and distance.
When to use it
Typical jobs: a photography or hiking planner, a smart-home schedule, a calendar widget, an agent answering "when does the sun set in Berlin?". The three kinds of twilight are civil, nautical and astronomical.
Request
POST lat and lon to /v1/space/sun-moon. date is a local date YYYY-MM-DD (1900 to 2100, default today) and tz is an IANA time zone for the date and the output (default UTC).
curl -s -X POST https://tanod.dev/v1/space/sun-moon \
-H 'X-Tanod-Free: 1' -H 'content-type: application/json' \
-d '{"lat": 52.52, "lon": 13.405, "date": "2026-10-08", "tz": "Europe/Berlin"}'Response
{
"date": "2026-10-08",
"tz": "Europe/Berlin",
"sun": {
"sunrise": "2026-10-08T07:19:23+02:00",
"sunset": "2026-10-08T18:27:33+02:00",
"solar_noon": "2026-10-08T12:53:35+02:00",
"day_length_hours": 11.136,
"civil_twilight": {"dawn": "2026-10-08T06:45:13+02:00", "dusk": "2026-10-08T19:01:38+02:00"}
},
"moon": {
"moonrise": "2026-10-08T04:28:59+02:00",
"moonset": "2026-10-08T17:29:23+02:00",
"phase": "waning_crescent",
"illumination": 0.0571,
"distance_km": 379816
}
}Nautical and astronomical twilight, the Sun's maximum altitude and more fields are in the full response. A bad date or time zone is a 422 and is not charged.
Paying: the 402 flow
Leave out the X-Tanod-Free header (or use up the free calls) and the same request gets HTTP 402 with the price (USD 0.001) and how to pay in the accepts list. An x402 client signs a USDC payment on Base, Polygon, Solana, BNB Chain or Arbitrum and retries; there is no account or API key. The full flow is in Pay-per-call APIs for AI agents with x402.
curl -s -i -X POST https://tanod.dev/v1/space/sun-moon \
-H 'content-type: application/json' \
-d '{"lat": 52.52, "lon": 13.405, "date": "2026-10-08", "tz": "Europe/Berlin"}'Limits and attribution
The times are computed locally from low-order Sun and truncated Moon series (Meeus), with no upstream call. Sun and twilight times are within about 1 minute, moonrise and moonset within about 3 minutes, and illumination within about 0.5 percentage points. A sea-level horizon is assumed; terrain, atmosphere and weather are not modelled.
No third-party data is used for this route.
Price and free allowance
USD 0.001 per call, paid in USDC on Base, Polygon, Solana, BNB Chain or Arbitrum with x402. 5 free skypeek calls per IP per UTC day with the header X-Tanod-Free: 1. The pool is shared by every skypeek route (METAR, TAF, airports, distance, space weather, aurora, asteroids, sun and moon, satellite passes). MCP tool: sun_moon_times at https://tanod.dev/mcp, where the free tier is automatic.
Use it from Claude without writing code: in claude.ai or Claude Desktop, add https://tanod.dev/mcp/sky?via=sunrise-sunset-moon-phase-api as a custom connector (steps), then ask in plain words, for example "When are sunrise and sunset in Tokyo on 1 June 2026, and what is the moon phase?" The free daily allowance is applied automatically over MCP. Beyond it a call needs an x402 payment, which these clients can make.
Related guides: Timezone converter API, ISS pass times API, Space weather, Kp index and aurora forecast API, Weather forecast API without a key, Pay-per-call APIs for AI agents with x402. Back to tanod.dev or the guide index. Results are automated and heuristic.