xkcd API
Free xkcd comic API with no key: fetch any comic by number or the latest, with image URL, title, alt text and publication date. Tested curl example.
Endpoint tested and returned HTTP 200 on 19 Aug 2026
What is the xkcd API?
The xkcd API is a free, key-free JSON endpoint returning metadata for any xkcd comic — image URL, title, the hover alt text, comic number and publication date.
xkcd publishes a JSON endpoint for every comic, which is about as simple as an API gets: `/info.0.json` for the latest, or `/{num}/info.0.json` for a specific one. No key, no query parameters, no pagination.
The `alt` field is the one people forget. It holds the hover text that is arguably the best part of each comic, and any decent implementation should surface it as a title attribute or caption rather than dropping it.
Quick facts
- Base URL
https://xkcd.com- Authentication
- No API key required.
- Rate limit
- No published limit.
- Pricing
- Free. Comics are CC BY-NC 2.5 — non-commercial use with attribution.
- CORS
- Not enabled — call it from your server
- Official docs
- Read the docs
How to use the xkcd API
Every request below was executed against the live API on 19 Aug 2026, and the response shown is the real body it returned — not an illustration.
1. Fetch the latest xkcd comic
GET https://xkcd.com/info.0.json
curl 'https://xkcd.com/info.0.json'const res = await fetch("https://xkcd.com/info.0.json");
if (!res.ok) throw new Error(`Request failed: ${res.status}`);
const data = await res.json();
console.log(data);import requests
res = requests.get("https://xkcd.com/info.0.json", timeout=20)
res.raise_for_status()
print(res.json()){
"month": "8",
"num": 3287,
"link": "",
"year": "2026",
"news": "",
"safe_title": "Perseids",
"transcript": "",
"alt": "Recently I've been watching the Daytime Perseids. I haven't seen a meteor from them yet, but the clouds are pretty and the snacks are good.",
"img": "https://imgs.xkcd.com/comics/perseids.png",
"title": "Perseids",
"day": "19"
}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
info.0.json | path | Optional | The most recent comic. info.0.json |
<num>/info.0.json | path | Optional | A specific comic by number. 614/info.0.json |
Response fields
numinteger- Comic number.
title / safe_titlestring- Comic title.
imgstring- Direct image URL.
altstring- Hover text — the punchline, do not omit it.
year / month / daystring- Publication date components, as strings.
transcriptstring- Text transcript, populated for older comics only.
What you can build with the xkcd API
- Show a daily or random xkcd comic on a site
- Build a comic browser with keyboard navigation
- Add a comic command to a Slack or Discord bot
- Practise fetch and image rendering in a beginner tutorial
Common errors and how to fix them
404
That comic number does not exist.
Fix: Comic 404 famously does not exist — a deliberate joke. Fetch the latest first to learn the maximum number.
Empty transcript
Transcripts were discontinued for newer comics.
Fix: Fall back to the alt text, which is always present.
CORS blocked
xkcd does not send CORS headers.
Fix: Fetch it from your server, or use a CORS proxy for client-only projects.
xkcd API — frequently asked questions
Is the xkcd API free?
Yes, free with no API key. The comics themselves are CC BY-NC 2.5, so non-commercial use with attribution.
How do I get a random comic?
Fetch /info.0.json to learn the latest comic number, then request a random number between 1 and that maximum.
What is the alt field?
The hover text — often the funniest part of the comic. Surface it as a title attribute or caption rather than dropping it.
Why does comic 404 return a 404 error?
It is a deliberate joke: xkcd never published a comic numbered 404. Your error handling should tolerate it.
Tools that pair with this API
JSON Formatter
Format, beautify and minify JSON online with 2-space, 4-space or tab indentation. Sort keys alphabetically and catch syntax errors instantly — free and private.
Image Cropper
Crop images online to an exact rectangle with pixel-precise x, y, width and height inputs or aspect-ratio presets. Free, private and browser-based.
Alternatives to xkcd API
If xkcd does not fit, these entertainment apis cover similar ground. Every one was called before publishing, and each links to its own reference page with a working curl command and the response it returned.
| API | What it does | Auth | CORS | Last verified |
|---|---|---|---|---|
| Official Joke API | Free joke API with no key: random jokes with setup and punchline, filterable by type. Perfect for beginner projects. Tested curl example and live JSON. | No key | Yes | 19 Aug 2026 |
| icanhazdadjoke | Free dad joke API with no key. Returns jokes as JSON, plain text or image depending on the Accept header. Search supported. Tested curl example included. | No key | Yes | 19 Aug 2026 |
| chucknorris.io | Free Chuck Norris jokes API with no key. Random jokes, 16 categories and full-text search. CORS enabled. Tested curl example and live JSON response. | No key | Yes | 19 Aug 2026 |
| Advice Slip | Free advice API with no key. Returns random advice slips as JSON, with search and id lookup. CORS enabled. Tested curl example and live response. | No key | Yes | 19 Aug 2026 |
| YesNo.wtf | Free yes/no API with no key: returns a random yes, no or maybe with a matching animated GIF. The simplest possible API for teaching fetch. Tested example. | No key | Yes | 19 Aug 2026 |
| ZenQuotes | Free quotes API with no key: random, daily and bulk inspirational quotes with author attribution and pre-formatted HTML. Tested curl example and live JSON. | No key | No | 19 Aug 2026 |
xkcd is an independent third-party service and is not affiliated with ByteTools or ByteVancer. Details on this page were verified on 19 Aug 2026; always check the official documentation before relying on this API in production, as terms and limits can change.