---
title: "Sun API Reference | APIFor"
description: "Endpoint reference for the Sun service: parameters, request bodies, example responses, status codes and credits per call."
canonical: "https://apifor.dev/docs/reference/sun/"
---

**Sun All docs**

# Sun API Reference

2 routes. Base URL `https://api.apifor.dev`, authenticated with `x-api-key`. Failed calls are not charged. Overview, limits and sources are on the [Sunrise, sunset and moon phase API](https://apifor.dev/services/sun/) page.

GET `/v1/sun` 1 credit

Sunrise, sunset, solar noon, day length, civil/nautical/astronomical twilight and the moon phase for a place and date, calculated on request. 1 credit.

| Parameter | In | Type | Rules |
| --- | --- | --- | --- |
| lat * | query | number | -90 to 90 · Latitude, -90 to 90. |
| lng * | query | number | -180 to 180 · Longitude, -180 to 180. |
| date | query | string | YYYY-MM-DD between 1900 and 2100. Default: today (UTC). |
| tz | query | string | max 40 chars · UTC offset (e.g. +07:00) or IANA zone (e.g. Asia/Jakarta) for the returned times. Default UTC. |

GET /v1/sun

```bash
curl 'https://api.apifor.dev/v1/sun?lat=-6.2&lng=106.8167&date=2026-11-28&tz=%2B07%3A00' \
  -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."
    }
  }
}
```

- `200` Sun and moon times
- `400` Invalid parameters

GET `/v1/sun/coverage` Free

Countries this service covers, with sources, licences, row counts and country-only fields. Free (0 credits), still needs an API key. Price note: Free.

GET /v1/sun/coverage

```bash
curl 'https://api.apifor.dev/v1/sun/coverage' \
  -H 'x-api-key: YOUR_API_KEY'
```

Example response · 200

```json
{
  "success": true,
  "data": {
    "service": "sun",
    "global": true,
    "country_param": "none",
    "param_name": "country",
    "countries": []
  }
}
```

- `200` Coverage

[Error handling](https://apifor.dev/docs/errors/) · [Rate limits](https://apifor.dev/docs/rate-limits/) · [Prices](https://apifor.dev/pricing/#services)
