Getting started
The AFKNest API lets you read and control your bots from anywhere: a plugin on your own Minecraft server, a Discord bot, or a script on your computer.
- Log in and open Account → Developer API.
- Press Make a key and copy it. You'll only see it once.
- Send it with every request in the
Authorizationheader.
Authorization: Bearer afk_u_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Every address starts with https://afknest.net/api/v1. Replies are JSON. Keep your key secret: anyone with it can control your bots. If it leaks, delete it on the same page and make a new one.
Player API (your bots)
These work with a player key and only ever see your own bots (and bots shared with you).
Your account: plan, how many bots your plan allows and how many you have.
{ "id": 12, "username": "steve", "plan": { "id": "plus", "name": "Plus", "bots": 3, "until": null }, "botsUsed": 2 }
All your bots and what they're doing right now.
{ "bots": [ {
"id": 7, "name": "Farm alt", "edition": "java", "state": "online", "online": true,
"username": "SteveAlt", "server": { "host": "play.example.net", "port": 25565, "version": "1.21.4" },
"ping": 42, "health": 20, "food": 18, "position": { "x": 120.5, "y": 64, "z": -33.2 },
"dimension": "overworld", "afk": { "jump": false, "hit": true, "spin": false, "crouch": false, "sneak": false, "mine": false },
"sessionStart": 1763300000000, "lastDisconnect": null
} ] }
state is one of online, connecting, reconnecting, offline or signin (the bot is waiting for a Microsoft sign-in; the code is on its card on the website).
One bot, in the same format.
The bot's latest chat, oldest first, colour codes removed. limit is 1 to 200. Pass the at of the last line you saw as since to only get new lines.
{ "chat": [ { "at": 1763300000000, "kind": "chat", "text": "<Alex> hi steve" } ] }
Actions
Do something with a bot. Send JSON with Content-Type: application/json.
| action | Also send | What it does |
|---|---|---|
say | text | Send a chat message. |
cmd | text | Run a command, e.g. "/spawn". |
connect / logoff / reconnect | Bring the bot online, take it offline, or reconnect it. | |
jump hit spin crouch sneak | on: true / false | Turn an anti-AFK switch on or off. |
mine | on: true / false | Hold left click (Java, Plus and Pro). |
POST /api/v1/bots/7/action
{ "action": "say", "text": "brb, my bot is holding my spot" }
{ "result": "...", "bot": { ...the bot, as above... } }
The same rules as the website apply: your plan's limits, blocked commands (like /op), and chat speed (one message every 2 seconds per bot, so servers don't mute it).
Examples
curl
curl -H "Authorization: Bearer $AFKNEST_KEY" https://afknest.net/api/v1/bots
curl -X POST -H "Authorization: Bearer $AFKNEST_KEY" -H "Content-Type: application/json" \
-d '{"action":"cmd","text":"/home"}' https://afknest.net/api/v1/bots/7/action
Minecraft plugin (Java, Paper/Spigot): run web requests off the main thread so the server doesn't lag.
HttpClient http = HttpClient.newHttpClient();
String key = getConfig().getString("afknest-key");
Bukkit.getScheduler().runTaskAsynchronously(this, () -> {
HttpRequest req = HttpRequest.newBuilder(URI.create("https://afknest.net/api/v1/bots/7/action"))
.header("Authorization", "Bearer " + key)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString("{\"action\":\"say\",\"text\":\"Hello from my plugin\"}"))
.build();
http.sendAsync(req, HttpResponse.BodyHandlers.ofString())
.thenAccept(res -> getLogger().info("AFKNest: " + res.body()));
});
JavaScript (Node.js, e.g. a Discord bot)
const res = await fetch('https://afknest.net/api/v1/bots', { headers: { Authorization: `Bearer ${process.env.AFKNEST_KEY}` } })
const { bots } = await res.json()
console.log(bots.map(b => `${b.name}: ${b.state}`).join('\n'))
Don't put your key in a plugin you share with others or upload to GitHub. Read it from a config file instead.
Siri & Shortcuts (iPhone, iPad, Mac)
Ask "Hey Siri, are my bots online?" or tap one button to restart a stuck bot. These two addresses answer in plain sentences that Siri can read out.
Answers like 2 of 3 bots are online. Farm alt is online. Main is offline. Add ?bot=Farm for just one bot (by name or id).
Restarts every bot that isn't online, or just one with ?bot=Farm. Answers like Restarting Main.
Make the "Are my bots online?" shortcut (about 2 minutes):
- Make a player key on Account → Developer API and copy it.
- Open the Shortcuts app → + (new shortcut). Name it Are my bots online. That name is what you say to Siri.
- Add the action Get Contents of URL. Set the URL to
https://afknest.net/api/v1/speak/status. - Tap the arrow (Show More) → Headers → Add new header: key
Authorization, valueBearer afk_u_…(your key, with the word Bearer and a space before it). - Add the action Speak Text (or Show Result if you'd rather read it). It uses the contents from the step before.
- Done. Say "Hey Siri, are my bots online", or add the shortcut to your home screen or Apple Watch.
"Restart my bots" shortcut: the same steps, but use the URL https://afknest.net/api/v1/speak/restart and set Method to POST. Name it Restart my bots.
Tip: Shortcuts → Automation can run "Are my bots online" every morning and show you the answer. Android users can do the same with apps like Tasker or HTTP Shortcuts. Anyone holding your phone can use these shortcuts, so keep your phone locked.
Admin API
For AFKNest staff only. Admin keys (afk_admin_...) can only be made by admins, are read-only, and stop working as soon as the person who made them is no longer an admin.
Is this Minecraft player using AFKNest? You can also use ?uuid=. Returns usingAfknest, onlineNow and each matching bot with its owner.
{ "query": "steve", "usingAfknest": true, "onlineNow": true,
"bots": [ { "id": 7, "state": "online", "server": { "host": "play.example.net", ... },
"owner": { "id": 12, "username": "steve", "email": "...", "plan": "plus", "status": "active" } } ] }
Every AFKNest bot set up for that server, and how many are online.
Find a customer, with their plan and bots.
Totals: active users, paying users, bots, bots online and servers.
Errors and limits
Errors come back with a normal HTTP status and { "error": "what went wrong" }.
- 401: missing, wrong or deleted key.
- 403: not allowed (plan limit, blocked command, wrong key type, suspended account).
- 404: no such bot (or it isn't yours).
- 429: too many requests. Player keys get 60 requests a minute, admin keys 120. Chat also has its own per-bot speed limit.
- 503: AFKNest is restarting or in maintenance. Try again in a minute.
Questions or ideas for the API? Open a support ticket.