Skip to main content

Sun Calculation Failed

sun_calculation_failed422

Validation · Sunrise-based calculations (panchanga family, charts without a birth time)

Sunrise or sunset couldn't be computed for this date and location. Verify inputs or use a different date.

What this means​

A calculation that depended on sunrise or sunset time for the requested location and date couldn't produce a result. This affects sunrise-anchored calculations: panchanga (which uses sunrise as the day boundary), hora and choghadiya (slot systems anchored to sunrise/sunset), and any other operation that needs to know when the Sun crosses the local horizon. Charts requested without a birth time use sunrise as the birth moment, so they can hit it too.

When you'll see this​

  • A panchanga or muhurta request at a latitude above ~65° on a date close to the summer or winter solstice.
  • A hora or choghadiya calculation in the same conditions.
  • Input parameters produced an unresolvable case for sunrise (e.g. invalid timezone combined with edge-case latitude).
  • A test or fixture used extreme polar conditions.
Learn more about how this works

Sunrise and sunset are computed by finding the moment the Sun's center (or limb, depending on convention) crosses the local horizon. At extreme latitudes near the solstices, this crossing doesn't happen — the Sun stays above the horizon for the whole day (polar day) or below it (polar night). When that's the case, there's no sunrise to anchor on, and operations that need sunrise simply can't proceed.

The most common gotcha: this can happen south of the polar circle. The polar circle is at ~66.5°, but near the solstices the Sun can fail to set at latitudes as low as ~65° depending on atmospheric refraction conventions. You might hit this for a place that doesn't feel "polar" — Iceland's northern coast, for instance, on dates close to June 21.

Example response​

{
"success": false,
"error": "sun_calculation_failed",
"message": "Sunrise or sunset could not be computed for this date and location, usually because the Sun does not rise or set there that day (polar day or night). Verify latitude, longitude, and timezone, or use another date.",
"details": [],
"retry_after": null,
"doc_url": "https://docs.asterwise.com/reference/errors/sun_calculation_failed/",
"request_id": "req_01HXYZABCDEFGH",
"timestamp": "2026-05-25T12:34:56Z"
}
NEW TO APIS?
Quick fix
  1. Verify the date and location combination is reasonable. Most occurrences are at extreme latitudes near solstices.
  2. For panchanga/muhurta/hora calculations at high latitudes, choose a date closer to an equinox (March or September) where the Sun does cross the horizon.
  3. If the location is genuinely problematic year-round (above 70° latitude), use a nearby non-polar reference location for sunrise-based calculations.
PRODUCTION ENGINEER
Recovery pattern

Pre-validate or pre-detect the polar-date condition on your side, or offer a fallback location when the error fires.

Python:

Production handler​

import httpx

def call_sunrise_anchored(url, headers, payload, fallback_lat=None, fallback_lon=None):
response = httpx.post(url, headers=headers, json=payload, timeout=30)
if response.status_code == 422:
body = response.json()
if body.get("error") == "sun_calculation_failed" and fallback_lat is not None:
payload["lat"] = fallback_lat
payload["lon"] = fallback_lon
response = httpx.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
return response.json()

Avoid this error by​

  • For panchanga, muhurta, and hora calculations targeting global users, warn if the user's location is above 60° latitude — most occurrences cluster there.
  • Cache sunrise/sunset times where you can. Astronomical events are deterministic for a fixed location-date pair, so there's no reason to recompute on every request.
  • For multi-location products, document the constraint clearly so users aren't surprised by edge-case failures.