TL;DR
NASA provides free access to a dozen APIs covering space imagery, planetary science, and spaceflight data. The most popular are Astronomy Picture of the Day (APOD) — which returns NASA's daily space photo with an explanation — and Mars Rover Photos, which lets you browse images from Curiosity, Opportunity, and Spirit. Use the demo key DEMO_KEY to get started instantly with no registration. Rate limits: 30 requests/hour with DEMO_KEY, 1000/hour with a free registered key.
Quick start: https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY
No API key needed — DEMO_KEY works for basic use!
How to Use This API
1. Astronomy Picture of the Day
https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY
Returns the APOD for today: title, explanation, image URL (or video URL for video-of-the-day), date, and copyright. Add date=2026-06-01 for a specific date.
2. Mars Rover Photos — Curiosity
https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=1000&api_key=DEMO_KEY
Returns photos taken on the 1000th Martian sol (day). Each photo has a URL, camera name, and Earth date. Replace sol with earth_date=2026-06-16.
3. Near-Earth Object (Asteroid) Feed
https://api.nasa.gov/neo/rest/v1/feed?start_date=2026-06-10&end_date=2026-06-16&api_key=DEMO_KEY
Lists all asteroids passing near Earth within the date range, with size, velocity, miss distance, and hazard assessment.
4. JavaScript — APOD Wallpaper Fetcher
async function getAPOD(date = null) {
let url = 'https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY';
if (date) url += `&date=${date}`;
const resp = await fetch(url);
const data = await resp.json();
return {
title: data.title,
explanation: data.explanation,
imageUrl: data.hdurl || data.url,
mediaType: data.media_type,
copyright: data.copyright
};
}
getAPOD('2026-06-01').then(apod => {
console.log(apod.title);
console.log(apod.explanation.substring(0, 100) + '...');
});
5. Python — Mars Rover Photo Gallery
import requests
KEY = 'DEMO_KEY'
def get_mars_photos(sol=1000, camera=None):
url = ('https://api.nasa.gov/mars-photos/api/v1/'
'rovers/curiosity/photos')
params = {'sol': sol, 'api_key': KEY}
if camera:
params['camera'] = camera
resp = requests.get(url, params=params)
photos = resp.json()['photos']
for p in photos[:5]:
print(f"Photo #{p['id']}: {p['img_src']}")
print(f" Camera: {p['camera']['full_name']}")
print(f" Earth date: {p['earth_date']}")
get_mars_photos(sol=1000, camera='navcam')
https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY
Frequently Asked Questions
- What's the difference between DEMO_KEY and a registered key?
- DEMO_KEY allows 30 requests per hour and 50 per day from a single IP. A free registered key (sign up at api.nasa.gov) gives you 1000 requests per hour. Registration is free and instant via email.
- What other NASA APIs are available?
- Besides APOD and Mars Rover, NASA offers: EPIC (Earth Polychromatic Imaging Camera), DONKI (space weather), TechTransfer (patents), TLE (satellite tracking), EONET (natural events), and more. All listed at api.nasa.gov.
- Does Mars Rover Photos support all rovers?
- Yes: Curiosity, Opportunity, Spirit, and Perseverance. Each rover has its own endpoint and available cameras. Perseverance also includes Ingenuity helicopter images!
- What camera options are available for Mars rovers?
- For Curiosity: FHAZ, RHAZ, NAVCAM, MAST, CHEMCAM, MAHLI, MARDI. For Perseverance: EDL_RDC, MCZ, NAVCAM_LEFT, SUPERCAM_RMI, and more.
- Does the NEO endpoint predict asteroid impacts?
- No, it lists close approaches. Each asteroid has
is_potentially_hazardous_asteroidboolean andmiss_distance(kilometers). No impact prediction data is included. - Can I use NASA images in commercial projects?
- Generally yes — NASA media is in the public domain. However, some APOD images may have third-party copyrights (noted in the
copyrightfield). Check each image's attribution.
API Details
- API URL
https://api.nasa.gov- Documentation
- api.nasa.gov
- Category
- Space
- Authentication
- DEMO_KEY (free, 30 req/hr) — or register for 1000 req/hr
- Geographic Coverage
- Global — space imagery and planetary data
What You Can Build
- Daily space photo widget showing today's APOD with explanation
- Mars rover image explorer — browse photos by sol, camera, and rover
- Asteroid tracker showing near-Earth objects approaching this week
- Planetary science teaching tool with real NASA imagery
- Night sky app that pairs APOD with local weather for stargazing conditions