Mastodon gives you something that most social platforms took away: direct programmatic access to almost every feature through a clean REST API. No rate limits that kill your project. No hidden endpoints. No permission gates that require a review board. Just you, an access token, and the open fediverse.
If you have built anything with the Twitter API (pre or post changes), you will feel right at home. But Mastodon’s API is simpler, more consistent, and actually maintained for developers like us. Whether you want to build a cross-poster, a community bot, a moderation tool, or a custom analytics dashboard, the Mastodon API integration process is straightforward once you understand the patterns.
Mastodon’s REST API gives developers direct access to the fediverse. With standard OAuth 2.0 authentication and JSON responses, you can build custom integrations that post content, read timelines, and interact with remote servers. This guide covers the essential endpoints, authentication flow, and practical code examples. Whether you are building a bot, a cross-poster, or a dashboard, you will find everything you need to start building your own Mastodon API integration today. No prior fediverse experience required and all examples work with any Mastodon server running version 4.0 or later.
Understanding the Mastodon API Landscape
Mastodon exposes a RESTful API that maps directly to the actions you see in the web app. Post a status. Fetch a timeline. Follow a user. Search for hashtags. It is all there, documented, and versioned.
The base URL for any Mastodon instance looks like this:
https://your-instance.social/api/v1/
Every endpoint builds on that prefix. The API uses JSON for both requests and responses. Authentication happens through OAuth 2.0 Bearer tokens passed in the Authorization header.
One thing that surprises most developers is that Mastodon does not require you to register an application just to read public data. You can fetch public timelines and public profiles without any token at all. But for writing data or accessing private accounts, you need the full OAuth flow.
If you are new to the fediverse as a development platform, you might want to read our guide on getting started with decentralized web development on Mastodon before diving into the API specifics.
Key Endpoints You Will Use Most
Not every Mastodon API integration needs the full endpoint catalog. Most projects rely on a small set of core endpoints. Here is a reference table to keep you oriented.
| Endpoint | Method | Purpose |
|---|---|---|
/api/v1/statuses |
POST | Create a new post (toot) |
/api/v1/timelines/home |
GET | Fetch the home timeline |
/api/v1/timelines/public |
GET | Fetch the local or federated public timeline |
/api/v1/accounts/:id/statuses |
GET | Get posts from a specific user |
/api/v1/notifications |
GET | Retrieve notifications for the authenticated user |
/api/v1/search |
GET | Search for accounts, hashtags, or statuses |
/api/v1/media |
POST | Upload an image or video before posting |
/api/v1/streaming |
WebSocket | Stream real time events (new posts, notifications) |
Most integrations start with the statuses endpoint. You authenticate, build your JSON payload (with status, visibility, media_ids), and send it. The response gives you back the full status object including its federated ID.
Building Your First Integration
Let us walk through the process of setting up a working Mastodon API integration from scratch. We will use Python for the examples because it reads clearly, but the same steps apply to any language with an HTTP client.
-
Register your application. Go to the Preferences page on your Mastodon instance, then to the Development section. Create a new application. Give it a name, a redirect URI (use
urn:ietf:wg:oauth:2.0:oobfor a CLI tool), and the scopes you need. For a basic bot that posts statuses and reads mentions, you needread:statuses,write:statuses, andread:notifications. Save the application and copy your client key and client secret. -
Get an access token. For personal integrations, you can generate an access token directly from the application page. No OAuth flow needed. Just click the link to create a token and copy it. For multi user applications, implement the full OAuth 2.0 authorization code flow using the
oauth/authorizeandoauth/tokenendpoints. -
Test your connection. Send a GET request to
/api/v1/accounts/verify_credentialswith your token in theAuthorizationheader asBearer <token>. If you get back your account data, you are ready to go. -
Post your first status. Build a JSON payload with a
statusfield. POST it to/api/v1/statuses. The response includes the full status object with its URL, ID, and timestamps. You now have a working integration. -
Handle media uploads. If you want to attach images, first POST the file to
/api/v1/mediaas multipart form data. The response returns amedia_id. Include that ID in an array undermedia_idsin your status payload. -
Read and respond. Fetch notifications from
/api/v1/notifications. Parse the mentions. Use thein_reply_to_idfield in your status payload to reply directly to the thread.
Expert advice from the fediverse developer community: Always include an
idempotencyheader (a unique string per request) on your POST requests to the statuses endpoint. If a network timeout happens but the server actually processed the request, the idempotency key prevents duplicate posts. Mastodon honors this header natively and it will save you from accidental spam.
Common Pitfalls and How to Avoid Them
Even with a clean API, certain mistakes show up again and again in Mastodon API integration projects. Here are the ones I see most often, along with fixes.
-
Using the wrong base URL. Remember that each Mastodon instance has its own domain. Your API calls must go to the instance where the user account lives. If you are building a multi instance tool, you need to let users specify their home server.
-
Forgetting the content type. All POST and PUT requests must include
Content-Type: application/jsonin the header (except for media uploads which use multipart). The API will silently fail or return a 422 error if you omit it. -
Ignoring the character limit. Mastodon defaults to 500 characters per post, but instance admins can raise or lower that limit. Check the instance configuration from
/api/v1/instancebefore you build your character counter. -
Not handling HTML in status content. Mastodon returns status content as HTML, not plain text. If you are building a reader or a dashboard, strip the HTML tags or render them safely. The
contentfield may contain<p>,<a>, and<br>tags. -
Overlooking the streaming API for real time features. Polling the timelines endpoint every few seconds works but feels sluggish and wastes resources. The streaming API via WebSocket gives you events as they happen. Subscribe to the
userstream for new notifications and mentions.
If you want to see how these patterns apply to a real application, check out our article on building and integrating decentralized social features with Mastodon.
Going Further with Advanced Patterns
Once you have the basics working, you can layer on more sophisticated features.
Cross posting from other platforms. Many developers build tools that mirror content from a blog, a GitHub repo, or another social network into Mastodon. The pattern is simple: listen for new content on the source platform, format it for Mastodon (shorten links, strip unsupported markup), and POST it to the statuses endpoint. The idempotency header matters even more here because the same content might trigger twice.
Moderation and reporting tools. The Mastodon API includes endpoints for moderation actions (/api/v1/admin/accounts/:id/action) that let you silence, suspend, or warn users from a custom dashboard. These endpoints require elevated permissions and the admin:write scope. They work well for community managers who want a unified interface across multiple instances.
Analytics and engagement tracking. Fetch timelines and account statuses periodically, store them in a database, and compute metrics like post frequency, engagement rates, and hashtag usage. The streaming API can keep your data fresh without constant polling. For a example of how the ecosystem is evolving, read our overview of the tools and apps shaping the fediverse in 2026.
Bots that learn from replies. A bot that posts content and then reads replies can adapt its behavior. You watch the notifications stream, parse mentions for keywords or commands, and respond accordingly. Mastodon’s bot tag in the profile metadata helps other users identify automated accounts, and you should set it on any bot you deploy.
Making Your Integration Resilient
The decentralized nature of Mastodon means that instances go down, federate slowly, or reject requests for reasons you cannot control. Build your integration to handle these cases.
Add retry logic with exponential backoff for all network calls. Treat 503 responses as temporary and try again after a delay. Cache instance metadata so you do not hit the /api/v1/instance endpoint on every request. And always validate the JSON response structure before accessing nested fields.
Mastodon instances usually do not enforce strict rate limits, but they do have practical limits. If you send requests too aggressively, the server may respond with a 429 status code. Respect the Retry-After header when it appears. Spreading requests across a few seconds of delay is usually enough to stay under the radar.
The Mastodon 4.3 release added several API improvements including better pagination headers and more consistent error responses. You can read about everything that changed in the latest version to make sure your integration takes advantage of the newest features.
Your First Steps Toward a Custom Mastodon API Integration
The best way to learn this API is to build something small and personal. Register an application on your home instance. Generate a token. Write a script that posts a daily status with the weather forecast or a random quote. That single loop teaches you authentication, payload construction, error handling, and the rhythm of the API.
From there, you can expand to reading replies, uploading media, or building a multi instance dashboard. The patterns stay the same across every feature because Mastodon designed its API around consistency. One endpoint works like every other endpoint.
The fediverse runs on the work of developers who choose to build for an open network instead of a walled garden. Your Mastodon API integration, no matter how small, adds to that ecosystem. Start with a token and a script. See where it takes you.