---
title: "Sunrise, sunset and moon phase API | APIFor"
description: "Sunrise, sunset, solar noon, day length, the three twilights and the moon phase for any coordinates and date. 1 credit per call, REST and MCP, one API key."
canonical: "https://apifor.dev/services/sun/"
---

1. [Services](https://apifor.dev/services/)
2. [Sun](https://apifor.dev/services/sun/)

# Sunrise, sunset and moon phase API

Sunrise, sunset, solar noon, day length, the three twilights and the moon phase for any coordinates and date.

GET /v1/sun 1 credit About $0.001

[Get a free API key](https://app.apifor.dev/register) [Endpoint reference](https://apifor.dev/docs/reference/sun/)

## Try it

GET /v1/sun

```bash
curl 'https://api.apifor.dev/v1/sun?lat=-6.2&lng=106.8167&date=2026-11-28&tz=%2B07:00' \
  -H 'x-api-key: YOUR_API_KEY'
```

Example response · 200

```json
{
  "success": true,
  "data": {
    "date": "2026-11-28",
    "lat": -6.2,
    "lng": 106.8167,
    "timezone": "+07:00",
    "sunrise": "05:26",
    "sunset": "17:53",
    "solar_noon": "11:40",
    "day_length_seconds": 44795,
    "polar": null,
    "twilight": {
      "civil": {
        "dawn": "05:04",
        "dusk": "18:15"
      },
      "nautical": {
        "dawn": "04:38",
        "dusk": "18:41"
      },
      "astronomical": {
        "dawn": "04:11",
        "dusk": "19:08"
      }
    },
    "moon": {
      "phase": "Waning Gibbous",
      "illumination": 0.797,
      "age_days": 19.16,
      "trend": "waning",
      "elongation_degrees": 126.4,
      "at": "2026-11-28T12:00:00Z"
    },
    "solar_declination": -21.267,
    "equation_of_time_minutes": 12.7,
    "times_note": "Times are HH:MM in the requested tz (default UTC). Sunrise and sunset include standard refraction (zenith 90.833°)."
  },
  "meta": {
    "attribution": {
      "source": "Computed by APIFor (NOAA/USNO solar formulae, Meeus lunar phase, tabular Islamic calendar)",
      "license": "MIT",
      "license_url": "https://opensource.org/license/mit",
      "source_url": "https://gml.noaa.gov/grad/solcalc/calcdetails.html",
      "attribution_page": "https://apifor.dev/sources",
      "notice": "Calculated on request. Sunrise and sunset are typically within 1 to 2 minutes of observed times."
    }
  }
}
```

A real response from our OpenAPI file, with long lists and strings shortened.

## Endpoints and price

| Endpoint | Credits | About |
| --- | --- | --- |
| GET `/v1/sun` | 1 credit | $0.001 |
| GET `/v1/sun/coverage` (Free) | Free | $0 |

USD at Starter pack prices ($5 for 5,000 credits). Calls that fail before work starts are refunded.

## Coverage today

Works for any country.

Sources, row counts and country-only fields per country: [`GET /v1/sun/coverage`](https://apifor.dev/docs/reference/sun/#get-sun-coverage), free with your API key. [How coverage works](https://apifor.dev/docs/coverage/)

## Limits

- Dates from 1900 to 2100.
- tz takes a UTC offset such as +07:00 or an IANA zone such as Asia/Tokyo.
- Near the poles sunrise and sunset can be null, with polar set to polar_night or midnight_sun.

## Sources and licences

- **[NOAA solar calculation formulae and Meeus lunar phase](https://gml.noaa.gov/grad/solcalc/calcdetails.html)**: Computed (MIT code)

## Also on MCP

Connect `https://mcp.apifor.dev/mcp` and your agent gets a tool for this service, billed the same way.

[MCP setup](https://apifor.dev/docs/mcp/)

## Questions

**How accurate is it?**

Sunrise and sunset use standard refraction and are usually within a minute or two of observed times.

**Which time is the moon phase for?**

12:00 UTC on the date you ask for.

## Related services

[All services](https://apifor.dev/services/)

- [Hijri calendar converter API](https://apifor.dev/services/calendars/)
- [Quran text API](https://apifor.dev/services/quran/)
- [Bible text API](https://apifor.dev/services/bible/)
- [English dictionary API](https://apifor.dev/services/dictionary/)
- [Prayer times API](https://apifor.dev/services/prayer-times/)
- [Public holidays API](https://apifor.dev/services/holidays/)
