NASA APIs API
A hub of NASA data — Astronomy Picture of the Day, Mars photos, asteroids and more.
What it does
api.nasa.gov is a single gateway to dozens of NASA data services with one key: the Astronomy Picture of the Day (APOD), Near-Earth Object tracking (NeoWs), Mars rover photos, EPIC full-disc Earth images, space-weather notifications (DONKI), Earth imagery, the exoplanet archive, patents (TechTransfer) and more.
Base URL
Authentication
Every endpoint takes ?api_key=YOUR_KEY. You can start with api_key=DEMO_KEY (very low limits) and swap in a free key from api.nasa.gov — it is issued instantly by email. The NASA Image and Video Library is separate (images-api.nasa.gov) and needs no key.
Code examples
curl -s "https://api.nasa.gov/planetary/apod?api_key=$NASA_KEY" curl -s "https://api.nasa.gov/neo/rest/v1/feed?start_date=2026-01-01&end_date=2026-01-02&api_key=$NASA_KEY"
import requests
r = requests.get("https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos",
params={"sol": 1000, "camera": "NAVCAM", "api_key": KEY}, timeout=15)
for p in r.json()["photos"][:5]:
print(p["earth_date"], p["img_src"])Rate limits & quotas
DEMO_KEY: about 30 requests/hour and 50/day per IP. A personal key: 1,000 requests/hour. Responses carry X-RateLimit-Limit and X-RateLimit-Remaining headers; over the limit returns HTTP 429. Each sub-API has its own path and its own response shape — read that service’s section of the docs.
Key response fields
| (APOD) url / hdurl / title / explanation | Image URL and description; media_type may be video |
| (NeoWs) near_earth_objects | Date-keyed lists of objects with size, miss distance and velocity |
| (NeoWs) ….is_potentially_hazardous_asteroid | Boolean hazard flag |
| (Mars) photos[].img_src / earth_date / camera.name | Rover image URL and metadata |
| (EPIC) image / date | Build the archive URL from the date and image name |
Common errors
| 403 API_KEY_INVALID | Key missing or wrong. |
| 429 OVER_RATE_LIMIT | Hourly/daily cap hit — the DEMO_KEY limits are tiny; use a real key. |
| 400 | Missing a required parameter such as a NeoWs date range (max 7 days per request). |
| (empty photos array) | No rover images for that sol/camera — try another sol. |
When to use it (and alternatives)
The go-to for space and astronomy content: APOD for a daily hero image, NeoWs for asteroid close-approach widgets, Mars rover galleries, EPIC for a live Earth view. For launch schedules use Launch Library 2; for the ISS position, Open Notify.
FAQ
Do I need a key, or is DEMO_KEY fine?
DEMO_KEY is only for a first test — 30 requests/hour and 50/day, shared across everyone on your IP. Get a free personal key (instant) for 1,000/hour.
Why does NeoWs reject my date range?
The /feed endpoint allows at most a 7-day span per request. For longer periods, loop week by week, or use /neo/rest/v1/neo/browse.
Is APOD ever a video?
Yes — check media_type. When it is video, url is an embeddable video link (often YouTube/Vimeo) and there is no hdurl.
New to APIs?
Short guides for working with this API — and any other.