How do I get a random meme from an API?
The simplest way is to call a meme search API with a randomly chosen keyword and take the first result. With memecub, use the REST API (1 credit per search), the remote MCP server at https://memecub.com/mcp, the CLI npx memecub, or the skill installed with npx skills add https://memecub.com. A keyless trial gives 20 searches a day, so you can test the loop before signing up.
Send it when your random-keyword loop returns something completely unrelated to the request.
The expanding-brain meme for anyone who thinks Math.random() counts as a random meme strategy.
Use it when someone asks why your bot keeps posting the same meme twice.
A dry jab for when the API returns a tech bro meme instead of the cat you wanted.
The face to send when your random pick finally lands and the chat reacts well.
For the moment an agent posts a meme nobody asked for and the channel goes quiet.
Good reply when someone assumes the AI wrote the meme instead of just fetching it.
A safe, friendly random pick when the search keyword is something like cat or cute.
How a random meme fetch works
A meme API usually exposes a search endpoint rather than a dedicated random endpoint. To get variety, keep a list of keywords (cat, coding, monday, deadline) and pick one at random on each call, then take a random item from the returned results.
Cache the results you get back. Repeating the same keyword every few seconds will return the same top results, and caching lets you shuffle locally without spending another search credit.
Example with memecub
The memecub REST API charges 1 credit per search call, and the keyless trial allows 20 searches a day. A minimal loop in JavaScript looks like this:
const words = ['cat', 'coding', 'deadline', 'coffee']; const q = words[Math.floor(Math.random() * words.length)]; const res = await fetch('https://memecub.com/api/search?q=' + encodeURIComponent(q)); const data = await res.json(); const meme = data.results[Math.floor(Math.random() * data.results.length)];
If you are building an AI agent rather than a script, point it at the remote MCP server at https://memecub.com/mcp, or install the skill with npx skills add https://memecub.com into Claude Code, Codex or Cursor. The CLI npx memecub is handy for quick manual checks.
Picking the right tool
Use the REST API when you need a random meme inside a web app or bot and want full control over the request.
Use the MCP server or the skill when an AI agent should decide on its own which meme fits a conversation.
Use the AI meme maker at /generate when no existing meme fits: describe a character, action and caption, and it produces an image in about 10 seconds for 500 credits. It refuses real people.
For a whole article, /match takes pasted text and picks a fitting meme for each paragraph.
Licensing and etiquette
Most memes in the library are collected from the web: fine for personal chats, with copyright staying with the original creators, and not for commercial use. If you need commercial use, turn on the filter that shows only openly licensed images from Openverse, open-source emoji and public-domain art.
In group chats, one meme per message is enough. Random picks work best when the keyword matches the conversation, so bias your keyword list toward the channel's topic.
Let your AI find the memes
REST API, remote MCP, CLI and a skill. Try 20 searches a day without a key.
More that fit
FAQ
How can I fetch a random meme using an API?
Call a meme search endpoint with a randomly chosen keyword and pick a random item from the results. memecub's REST API works this way, at 1 credit per search, with a keyless trial of 20 searches a day.
What API returns a random meme?
memecub offers a REST API, a remote MCP server at https://memecub.com/mcp, a CLI via `npx memecub` and an installable skill for coding agents. There is no separate random endpoint, so randomness comes from your keyword choice and local shuffling.
Can an AI agent fetch memes by itself?
Yes. Connect the agent to the MCP server or install the skill with `npx skills add https://memecub.com`, and it can search and pick memes as part of its normal workflow.
Can I use random memes commercially?
Not by default. Most memes are collected from the web and are for personal chats only, with rights staying with the creators. Enable the openly licensed filter to get images that can be used commercially.
What if no existing meme fits?
Use the AI meme maker at /generate: describe a character, action and caption, or start from an existing meme as reference. Each image takes about 10 seconds and costs 500 credits, and real people are refused.