The Joke API

Fun API · Programming, Dark & General jokes · Safety filter

TL;DR

JokeAPI offers a well-organized collection of jokes across three main categories: Programming, Dark, and General (Misc). Each joke is tagged with a "safe" flag so you can filter out NSFW content. Jokes come in two formats — classic single-line or setup/punchline two-part. It's perfect for adding a laugh to your dev tools, chatbots, or terminal applications.

Quick start: https://v2.jokeapi.dev/joke/Programming?type=single

No API key needed — just make a request!

How to Use This API

1. Random Programming Joke (Single Line)

https://v2.jokeapi.dev/joke/Programming?type=single

Returns a single programming joke. Example: {"joke":"There are only 10 kinds of people in this world: those who know binary and those who don't.","safe":true}

2. Two-Part Joke (Setup + Delivery)

https://v2.jokeapi.dev/joke/Programming?type=twopart

Returns {"setup":"Why do programmers prefer dark mode?","delivery":"Because light attracts bugs."}

3. Safe Jokes Only (No NSFW)

https://v2.jokeapi.dev/joke/Any?safe-mode

Filters out dark, NSFW, religious, political, and racist jokes. Great for public-facing displays.

4. JavaScript — Random Joke Button

async function getJoke(category = 'Programming') {
  const resp = await fetch(
    `https://v2.jokeapi.dev/joke/${category}?safe-mode`
  );
  const joke = await resp.json();
  
  if (joke.type === 'single') {
    return joke.joke;
  } else {
    return `${joke.setup} ... ${joke.delivery}`;
  }
}

document.getElementById('joke-btn').onclick = async () => {
  document.getElementById('joke-display').textContent =
    await getJoke('Programming');
};

5. Python — Multi-Category Joke Fetcher

import requests

def get_joke(categories='Programming', safe=True):
    url = f'https://v2.jokeapi.dev/joke/{categories}'
    params = {'safe-mode': ''} if safe else {}
    params['type'] = 'single'
    resp = requests.get(url, params=params)
    data = resp.json()
    
    if data['type'] == 'single':
        return data['joke']
    else:
        return f"{data['setup']}\n{data['delivery']}"

# Get a few programming jokes
for i in range(3):
    print(f"Joke {i+1}: {get_joke()}\n")
Try a programming joke: https://v2.jokeapi.dev/joke/Programming?type=single

Frequently Asked Questions

What joke categories are available?
Programming, Dark, Miscellaneous (Misc), Pun (puns), Spooky (Halloween-themed), Christmas (holiday-themed). Use "Any" for a random mix of all categories.
How does the safety filter work?
Each joke has a safe boolean field. Add ?safe-mode to exclude jokes flagged as NSFW, religious, political, racist, or sexist. The flags object shows which flags apply.
Can I get multiple jokes in one request?
Yes! Use /joke/Any?safe-mode&amount=5 to get up to 10 jokes in a single response array.
Does it include joke IDs for referencing?
Yes, each joke has a unique id field. You can fetch a specific joke by ID: /joke/Any?idRange=42.
What language are the jokes in?
Primarily English. The joke categories are mostly English-language humor, especially the programming jokes which follow tech industry conventions.
Are there joke format options?
Two formats: single (one-line joke) and twopart (setup + delivery punchline). Omit the type parameter to get a random mix of both.

API Details

API URL
https://v2.jokeapi.dev
Documentation
sv443.net/jokeapi/v2
Category
Fun
Authentication
Not Required
Geographic Coverage
Global

What You Can Build