BYTETOOLS

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.

No API key requiredHTTPSFree tier

Endpoint tested and returned HTTP 200 on 2026-08-19

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 2026-08-19, 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
curl 'https://xkcd.com/info.0.json'
JavaScript (fetch)
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);
Python (requests)
import requests

res = requests.get("https://xkcd.com/info.0.json", timeout=20)
res.raise_for_status()
print(res.json())
Response — HTTP 200
{
  "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

ParameterTypeRequiredDescription
info.0.jsonpathOptionalThe most recent comic. info.0.json
<num>/info.0.jsonpathOptionalA 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

xkcd is an independent third-party service and is not affiliated with ByteTools or ByteVancer. Details on this page were verified on 2026-08-19; always check the official documentation before relying on this API in production, as terms and limits can change.