xkcd API

Beginner's Pick Games & Comics / No Auth Required Beginner HTTPS
Free to Use
64 C
Measured Score 0 50 100 Speed 30/30 Consistency 8/20 Security 18/20 Browser access 0/15 Transparency 8/15 TESTED 2026-08-10

Overview

The xkcd API lets you retrieve any xkcd webcomic as structured JSON data, including the comic title, image URL, alt text, and publication date. It requires no authentication and is extremely simple to use. A perfect first API for beginners learning to make HTTP requests and parse JSON responses.

Beginner Tip

To get the latest comic, request https://xkcd.com/info.0.json. To get a specific comic by its number, use https://xkcd.com/NUMBER/info.0.json, where NUMBER is the comic's ID.

Measurement Record

What actually happened when we called this API from our own infrastructure. Every value below was recorded by the request, not copied from the provider's documentation.

Request
GET https://xkcd.com/info.0.json
Result
HTTP 200 · application/json · 395 bytes · compressed
Response time
29 ms (median of 3) · fastest 19 ms
Transport
TLSv1.2 · ECDHE-RSA-AES128-GCM-SHA256 · certificate issued by GlobalSign nv-sa
Browser CORS
No Access-Control-Allow-Origin header — call it from a server, not the browser
Served by
nginx
Recorded
2026-08-10

Fields Returned

Top-level fields present in the response we captured, with the type and value we actually received.

Field Type Value received
month string 8
num integer 3283
link string
year string 2026
news string
safe_title string Size and Lifespan
transcript string
alt string With their 13 years recording and performing …
img string (url) https://imgs.xkcd.com/comics/size_and_lifespa…
title string Size and Lifespan
day string 10

Captured Response

Captured from a real request to https://xkcd.com/info.0.json on 2026-08-10. Long arrays and nested objects are truncated to keep the shape readable.

JSON Response · Captured
{
  "month": "8",
  "num": 3283,
  "link": "",
  "year": "2026",
  "news": "",
  "safe_title": "Size and Lifespan",
  "transcript": "",
  "alt": "With their 13 years recording and performing together and two humans worth of mass, the White Stripes are sandwiched neatly between gray wolves and blue whales.",
  "img": "https://imgs.xkcd.com/comics/size_and_lifespan.png",
  "title": "Size and Lifespan",
  "day": "10"
}

Field Reference

num The unique comic number, incrementing with each new publication.
title The title of the xkcd comic strip.
img URL to the comic's image file, typically a PNG or JPEG.
alt The hover text / alt text, often containing the punchline or extra joke.
transcript Full text transcript of the comic dialogue (may be empty for newer comics).
year Four-digit year the comic was published.

Implementation Example

Calls a real endpoint of this API. Replace any placeholder credentials with your own key.

Request
const url = "https://xkcd.com/";
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.

How This API Fails

We deliberately sent this API a broken request and recorded exactly what came back on 2026-08-10. Knowing the shape of an error before you hit it makes error handling much easier to write.

HTTP 404 Requesting a path that does not exist text/html

Returned an HTML error page rather than JSON — worth knowing if your client assumes every response can be parsed as JSON.

Common Errors & Troubleshooting

Generated guidance based on this API's documentation, not observed by us. Treat it as a starting point and check against the provider's own error reference.

404 Not Found Comic number 404 does not exist intentionally (it is an xkcd joke).
Skip comic number 404 in any loop that iterates through all comics — it will always return 404.
Missing transcript field Newer comics do not always include a transcript in the JSON.
Treat transcript as optional; fall back to displaying the alt field (hover text) as alternative text.
Image not loading from URL The img URL uses HTTP and your environment enforces HTTPS.
Replace http:// with https:// in the img field value; xkcd serves images over both protocols.

Measured Score Breakdown

Live HTTP request to the API endpoint

Speed 30/30
Consistency 8/20
Security 18/20
Browser access 0/15
Transparency 8/15
Endpoint Response Time 29ms

Fully tested on Aug 10, 2026

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS NO
Category Games & Comics
Difficulty Beginner
Endpoint last called: 2026-08-10

Related Tags

Similar APIs

View All →