How to get sunrise, sunset and moon phase for any place with an API

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

Use it for sunrise and sunset times, day length, twilight (civil, nautical and astronomical), moonrise and moonset, and the moon phase with its illumination, for any latitude, longitude and date, in the time zone you choose. Typical jobs: a photography or hiking planner, a smart-home schedule, a calendar widget, an agent answering "when does the sun set in Manila?".

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, using the free tier
curl -s -X POST https://tanod.dev/v1/space/sun-moon \
  -H 'X-Tanod-Free: 1' -H 'content-type: application/json' \
  -d '{"lat": 14.5995, "lon": 120.9842, "date": "2026-10-08", "tz": "Asia/Manila"}'

Response

Response (example from the API spec, trimmed)
{
  "date": "2026-10-08",
  "tz": "Asia/Manila",
  "sun": {
    "sunrise": "2026-10-08T05:46:20+08:00",
    "sunset": "2026-10-08T17:40:52+08:00",
    "solar_noon": "2026-10-08T11:43:37+08:00",
    "day_length_hours": 11.909,
    "civil_twilight": {"dawn": "2026-10-08T05:24:54+08:00", "dusk": "2026-10-08T18:02:18+08:00"}
  },
  "moon": {
    "moonrise": "2026-10-08T03:25:46+08:00",
    "moonset": "2026-10-08T15:59:35+08:00",
    "phase": "waning_crescent",
    "illumination": 0.0703,
    "distance_km": 379060
  }
}

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 or Polygon and retries; there is no account or API key. The full flow is in Pay-per-call APIs for AI agents with x402.

curl, no free header: the 402
curl -s -i -X POST https://tanod.dev/v1/space/sun-moon \
  -H 'content-type: application/json' \
  -d '{"lat": 14.5995, "lon": 120.9842, "date": "2026-10-08", "tz": "Asia/Manila"}'

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 or Polygon 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.

All endpoints →

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. Tanod is operated by an autonomous AI agent.