Sunrise and Sunset API

⭐ Beginner's Pick Science & Math / No Auth Required Beginner HTTPS
Free to Use Varies (check documentation)

Overview

The Sunrise and Sunset API returns accurate sunrise, sunset, solar noon, and day length data for any latitude/longitude coordinate on Earth. It is completely free and requires no API key, making it one of the easiest APIs to start with. Use it to build apps that adapt content or UI based on daylight, from smart home automation to photography planning tools.

💡

Beginner Tip

Pass any latitude and longitude plus a date to get precise solar times — for example, use your city coordinates to see today sunrise and sunset. All times are returned in UTC by default; add tzid=YOUR_TIMEZONE to get local times.

Available Data

repository name and description
star and fork counts
contributor data
issues and pull requests
commit history

Example Response

JSON Response
{
  "status": "success",
  "data": {
    "result": "Data from Sunrise and Sunset",
    "description": "Sunset and sunrise times for a given latitude and longitude",
    "timestamp": "2025-01-15T10:00:00Z"
  }
}

Field Reference

results.sunrise ISO 8601 timestamp of sunrise for the requested location and date.
results.sunset ISO 8601 timestamp of sunset for the requested location and date.
results.solar_noon The time when the sun reaches its highest point in the sky.
results.day_length Total length of the day in seconds between sunrise and sunset.
results.civil_twilight_begin Start of civil twilight when the sky first begins to lighten before sunrise.
status Request status — OK on success or INVALID_REQUEST when parameters are wrong.

Implementation Example

// ⚠️ Note: This URL may be a documentation page. Check official docs for actual API endpoint.
const url = "https://sunrise-sunset.org/api";
const response = await fetch(url);
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

Common Errors & Troubleshooting

Times returned in UTC when local time expected The API defaults to UTC unless a timezone is specified.
Add the tzid parameter with an IANA timezone identifier such as tzid=Europe/London to receive times in local timezone.
Identical sunrise/sunset for polar regions Near the poles, the sun may not set or rise at all on certain dates due to midnight sun or polar night.
Check the day_length field — a value of 0 or 86400 seconds indicates polar night or midnight sun respectively.
400 Bad Request Latitude or longitude values are out of range or formatted incorrectly.
Ensure latitude is between -90 and 90, and longitude is between -180 and 180, using decimal degrees.

Matrix Score Breakdown

🌐 Reachability 30/30
⚡ Speed 15/20
🔒 Security 15/15
🛠 Developer XP 12/20
✓ Reliability 7/15
Response Time 253ms

Fully tested on Apr 5, 2026

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS NO
Category Science & Math
Difficulty Beginner
Verified: 2026-04-04

Similar APIs

View All →