Skip to content

xkcd API

by xkcd.com

No authHTTPSGames & Comics
Open documentation ↗

Overview

Retrieve xkcd comics as JSON

xkcd is a games & comics API from xkcd.com. It needs no API key. It is served over HTTPS and does not allow direct browser requests (no CORS). Its OpenAPI description documents 2 endpoints.

At a glance

Authentication
No auth
HTTPS
Yes
CORS
No
Base URL
http://xkcd.com/
Version
1.0.0
Endpoints
2
Spec updated
2021-04-07

Make a first request

Replace the placeholders; the documentation says exactly where credentials go.

cURL
curl -X GET "http://xkcd.com/info.0.json" \
  -H "Accept: application/json"
JavaScript
const response = await fetch("http://xkcd.com/info.0.json", {
  method: "GET",
  headers: {
    "Accept": "application/json",
  },
});
const data = await response.json();
console.log(data);
Python
import requests

response = requests.request(
    "GET",
    "http://xkcd.com/info.0.json",
    headers={
    "Accept": "application/json",
    },
    timeout=30,
)
print(response.json())

Endpoints

MethodPathWhat it does
GET/info.0.jsonFetch current comic and metadata.
GET/{comicId}/info.0.jsonFetch comics and metadata by comic id.

Questions

Does the xkcd API need an API key?

No. The xkcd API can be called without an API key or sign-up, which makes it handy for prototypes and front-end demos.

Can I call the xkcd API from the browser?

Not directly. The xkcd API does not send CORS headers, so call it from your server or a proxy instead of browser JavaScript.

Does the xkcd API support HTTPS?

Yes, the xkcd API is served over HTTPS.

How many endpoints does the xkcd API have?

Its OpenAPI description lists 2 endpoints in version 1.0.0. All of them are shown on this page.

What are alternatives to the xkcd API?

Other Games & Comics APIs include Chess.com, Scryfall, Riot Games, Lichess, Comic Vine.

Compare alternatives →

Listed from public-apis (MIT), public-apis database (MIT), Free Public APIs, APIs.guru (CC0).