---
title: "Mastodon API: Public Posts and Hashtags as JSON"
description: "Get public Mastodon hashtag timelines as JSON: language, created_at, reblogs_count and tags per post, with a pagination cursor. 1 credit per call."
url: https://perceptlayer.com/blog/mastodon-api-json
---

[Blog](https://perceptlayer.com/blog) / [API guides](https://perceptlayer.com/blog/category/api-guides)

# Mastodon API: Public Posts and Hashtags as JSON

24 Nov 2026 Perceptlayer 8 min read

To get public Mastodon posts as JSON, call `GET /v1/mastodon/hashtag` with a `tag` and an optional `instance`: the recorded call for `#mastodon` on `mastodon.social` returned public posts with `created_at`, `language`, `replies_count`, `reblogs_count`, `favourites_count`, `tags` and media, plus a `pagination` cursor, for 1 credit. Four more endpoints cover search, single posts with their thread, account posts and profiles. All five are restricted, so this guide sticks to aggregate uses: topic volume, languages and instance-level activity.

## Key takeaways

-   The Mastodon API on Perceptlayer has five endpoints, `hashtag`, `search`, `status`, `statuses` and `profile`; all five are restricted and each costs 1 credit per successful call.
-   Restricted endpoints work after you accept the restricted-endpoint terms, which don't permit collecting personal data without a lawful basis or using it to contact people.
-   `GET /v1/mastodon/hashtag` takes a required `tag` (up to 255 characters) and optional `instance`, `limit`, `max_id`, `min_id`, `since_id`, `only_media`, `any[]`, `all[]`, `none[]`, `local` and `remote`.
-   Each post in the recording carries `language`, `created_at`, engagement counts, `tags` and a `uri` whose host names the instance it came from, which is enough for topic-level counts.
-   Polling 20 hashtags every 6 hours is 20 × 4 × 30 days × 1 credit = 2,400 credits a month, inside the Starter pack's 10,000.

## What does the Mastodon API on Perceptlayer cover?

The Mastodon API on Perceptlayer has five `GET` endpoints that return public Mastodon data as JSON: a hashtag timeline, a search, one post with its thread, an account's posts and an account profile. Every endpoint takes an optional `instance` (up to 253 characters), the Mastodon server to ask; the recordings all use `mastodon.social`. Each successful call costs 1 credit.

| Method | Path | Returns | Credits | Required | Optional |
| --- | --- | --- | --- | --- | --- |
| `GET` | `/v1/mastodon/hashtag` | Public posts with a hashtag | 1 | `tag` | `instance`, `limit`, `max_id`, `min_id`, `since_id`, `only_media`, `any[]`, `all[]`, `none[]`, `local`, `remote` |
| `GET` | `/v1/mastodon/search` | Search results | 1 | `q` | `instance`, `type`, `resolve`, `limit`, `offset`, `exclude_unreviewed` |
| `GET` | `/v1/mastodon/status` | One post's thread | 1 | `id` | `instance` |
| `GET` | `/v1/mastodon/statuses` | An account's posts | 1 | `id` | `instance`, `limit`, `max_id`, `min_id`, `since_id`, `exclude_replies`, `exclude_reblogs`, `only_media`, `pinned`, `tagged` |
| `GET` | `/v1/mastodon/profile` | One account | 1 | `acct` | `instance` |

The data is collected from publicly available sources and returned as found at the time of the call. These are Perceptlayer endpoints; this guide makes no claims about Mastodon's own developer interfaces or any server's rules, so compare them yourself and read the terms of the instances you query. The [Mastodon API page](https://perceptlayer.com/apis/mastodon) lists every endpoint and has a playground.

## What do the restricted-endpoint terms mean for a Mastodon job?

All five Mastodon endpoints are restricted. They work once you accept the [restricted-endpoint terms](https://perceptlayer.com/legal/restricted-endpoints) in your dashboard; until then a call returns `restricted_endpoint` (403) and costs nothing. The terms don't permit collecting personal data without a lawful basis, and they don't permit using the data to contact people. In the recordings, every post arrives with an embedded `account` object, so personal data reaches you whether you want it or not.

That shapes the job. Keep the question at the level of a topic, a hashtag, a language or an instance: how much a hashtag is used, in which languages, from which servers, and how much engagement it draws. Don't build records of individuals, follow particular accounts over time, or export handles for outreach. The simplest safeguard is in code: read the post-level fields you need and drop `account`, `mentions` and media descriptions before anything is stored.

## How do you get the public posts for a hashtag?

Send a `GET` request to `https://api.perceptlayer.com/v1/mastodon/hashtag` with the hashtag in `tag` (the recording passes `mastodon`, without the `#`) and your key in the `X-API-Key` header. The recording also sets `instance=mastodon.social` and `limit=5`. This is the request behind the recorded response:

```bash
curl "https://api.perceptlayer.com/v1/mastodon/hashtag?instance=mastodon.social&tag=mastodon&limit=5" \
  -H "X-API-Key: $API_KEY"
```

Keys start with `sk_live_`. Where you can't set a header, the key can go in the `api_key` query parameter; the [authentication docs](https://docs.perceptlayer.com/authentication) cover both. Successful responses carry `X-Credits-Used` and `X-Credits-Remaining`, so a polling job can log its spend per call.

### Which parameters does the hashtag endpoint take?

The hashtag endpoint takes one required parameter and eleven optional ones. The table lists each with the constraints the API documents. Nothing else is documented, including defaults, page sizes and what the boolean filters do, so try them in the playground on the [hashtag endpoint page](https://perceptlayer.com/apis/mastodon/hashtag) before a job depends on them.

| Parameter | Type | Required | Documented constraint |
| --- | --- | --- | --- |
| `tag` | string | yes | Up to 255 characters |
| `instance` | string | no | Up to 253 characters |
| `limit` | integer | no | None documented |
| `max_id` | string | no | Up to 64 characters |
| `min_id` | string | no | Up to 64 characters |
| `since_id` | string | no | Up to 64 characters |
| `only_media` | boolean | no | None documented |
| `any[]` | list of strings | no | None documented |
| `all[]` | list of strings | no | None documented |
| `none[]` | list of strings | no | None documented |
| `local` | boolean | no | None documented |
| `remote` | boolean | no | None documented |

## What does a hashtag response contain?

The response has a `data` array of posts, a `meta` block with `duration_ms` and the endpoint family, and a `pagination` block with `has_more`, `next_cursor` and `prev_cursor`. Each post carries its ID, time, language, visibility, engagement counts, HTML `content` and a plain `content_text`, tags, media and the posting account. This is the recorded response, trimmed to post-level fields with the account and text cut:

```json
{
  "success": true,
  "data": [
    {
      "id": "117603629637167653",
      "created_at": "2026-11-12T13:09:37.620Z",
      "sensitive": false,
      "spoiler_text": "",
      "visibility": "public",
      "language": "en",
      …
      "replies_count": 0,
      "reblogs_count": 0,
      "favourites_count": 1,
      "quotes_count": 0,
      …
      "account": { … },
      "media_attachments": [
        {
          "id": "117603595560812374",
          "type": "image",
          …
        }
      ],
      "tags": [
        …
        {
          "name": "gardening",
          "url": "https://mastodon.social/tags/gardening"
        }
      ],
      …
    },
    {
      "id": "117603512684170770",
      "created_at": "2026-11-12T12:39:40.000Z",
      "visibility": "public",
      "language": "ja",
      …
      "reblogs_count": 3,
      …
    }
  ],
  "meta": {
    "duration_ms": 522,
    "endpoint_family": "hashtag_timeline"
  },
  "pagination": {
    "has_more": true,
    "next_cursor": "117603441416524251",
    "prev_cursor": "117603629637167653"
  }
}
```

| Field | What an aggregate job does with it |
| --- | --- |
| `id`, `created_at` | Deduplicate posts and bucket them by hour or day |
| `language` | Count posts per language; `en` and `ja` appear in the recording |
| `replies_count`, `reblogs_count`, `favourites_count`, `quotes_count` | Sum engagement per tag and per period |
| `tags[].name` | Count which tags appear alongside the one you queried |
| `media_attachments[].type` | Share of posts with images |
| `uri` | Its host gives the instance a post came from, for instance-level counts |
| `pagination.has_more`, `next_cursor` | Whether more posts exist, and a cursor value |

In the recording, `prev_cursor` equals the first post's `id`. The endpoint takes `max_id`, `min_id` and `since_id`, but how they pair with `next_cursor` and `prev_cursor` isn't documented, so test it in the playground before you page through a timeline. Also notice that the two recorded posts come from different servers: the hashtag timeline on one instance includes posts that originated elsewhere, which is what makes instance-level counts possible.

## What do the other four endpoints return?

The other four endpoints return search results, a thread, an account's posts and a profile. Three of them are about individual accounts, so they fit a narrow set of jobs: checking an organisation's or project's public account, or reading the discussion under a specific public post. The table summarises what each recording shows; none of their excerpts appear here, because they consist mostly of account details.

| Endpoint | Recorded request | Response shape in the recording |
| --- | --- | --- |
| `search` | `q=mastodon`, `type=accounts`, `resolve=0`, `limit=5` | `data.accounts`, an array of accounts with counts and profile fields |
| `status` | A post `id` | `data.ancestors` and `data.descendants`, arrays of posts in the thread |
| `statuses` | An account `id`, `limit=5` | A `data` array of posts and the same `pagination` block as `hashtag` |
| `profile` | `acct` set to an account handle | One account under `data` |

`search` also accepts `type` values `hashtags` and `statuses`, but only an `accounts` search is recorded; run the others in the playground on the [search endpoint page](https://perceptlayer.com/apis/mastodon/search) to see their shape. For aggregate work, `hashtag` remains the main endpoint, with `status` for the replies and reblog counts around one public post.

## How do you count hashtag activity in Python?

A hashtag monitor polls a fixed list of tags on a schedule and turns each response into counts: posts per language, posts per originating instance, total engagement and co-occurring tags. It stores those numbers and the post IDs for deduplication, and drops everything about accounts. The script below does that with `requests`, `json` and `collections`, reading only fields in the recorded response.

```python
import collections
import datetime
import json
import os
import time
from urllib.parse import urlparse

import requests

API_KEY = os.environ["API_KEY"]
URL = "https://api.perceptlayer.com/v1/mastodon/hashtag"
TAGS = ["mastodon", "gardening", "opensource"]

def timeline(tag, attempts=3):
    params = {"instance": "mastodon.social", "tag": tag, "limit": 40}
    for _ in range(attempts):
        r = requests.get(URL, params=params, headers={"X-API-Key": API_KEY}, timeout=60)
        if r.status_code in (429, 503):
            time.sleep(int(r.headers.get("Retry-After", "5")))
            continue
        r.raise_for_status()
        return r.json()
    raise RuntimeError(f"gave up on {tag}")

now = datetime.datetime.now(datetime.timezone.utc).isoformat()
with open("mastodon-hashtags.jsonl", "a") as f:
    for tag in TAGS:
        posts = timeline(tag).get("data", [])
        langs, hosts, cotags = collections.Counter(), collections.Counter(), collections.Counter()
        engagement = 0
        for p in posts:
            langs[p.get("language") or "unknown"] += 1
            hosts[urlparse(p.get("uri", "")).netloc] += 1
            for t in p.get("tags", []):
                if t.get("name", "").lower() != tag:
                    cotags[t.get("name")] += 1
            engagement += sum(p.get(k, 0) for k in ("replies_count", "reblogs_count", "favourites_count", "quotes_count"))
        row = {
            "at": now, "tag": tag, "posts": len(posts),
            "post_ids": [p.get("id") for p in posts],
            "languages": langs, "instances": hosts,
            "co_tags": dict(cotags.most_common(10)), "engagement": engagement,
        }
        f.write(json.dumps(row) + "\n")
        time.sleep(1)
```

The `limit` of 40 is a request, not a documented maximum; check what comes back. The script never reads `account` or `mentions`, and it stores only counts, post IDs and instance hosts. Store `post_ids` so the next run can skip posts it has counted, and the one-second pause keeps a free account within its 1 request a second.

### What should the job do with errors?

Every error returns an HTTP status and a JSON body with `code`, `message` and `request_id`, and costs nothing. Retry `rate_limited` (429) and `temporarily_unavailable` (503) after the `Retry-After` seconds. A `restricted_endpoint` (403) means the terms haven't been accepted on the account. Requests have no idempotency key, so a client timeout can hide a call that succeeded and was billed. The [errors docs](https://docs.perceptlayer.com/errors) list every code.

## What does Mastodon data cost?

Every successful call to any of the five endpoints costs 1 credit, and failed calls cost nothing. A hashtag monitor pays 1 credit per tag per poll, so the cost depends on how many tags you follow and how often you poll. Paging further back in a timeline adds 1 credit per extra page.

| Plan | Arithmetic | Credits a month |
| --- | --- | --- |
| 20 tags every 6 hours | 20 × 4 × 30 days × 1 credit | 2,400 |
| 50 tags every 6 hours | 50 × 4 × 30 days × 1 credit | 6,000 |
| 20 tags hourly | 20 × 24 × 30 days × 1 credit | 14,400 |
| 60 tags hourly | 60 × 24 × 30 days × 1 credit | 43,200 |

The first two fit the Starter pack's 10,000 credits, and the last two fit the Build pack's 50,000. The 100 free credits on signup cover 100 calls, enough to poll 20 tags five times. Purchased credits last 12 months. See [pricing](https://perceptlayer.com/pricing) for what credits cost and the [credits docs](https://docs.perceptlayer.com/credits) for how calls are debited.

To try it, accept the restricted-endpoint terms, then run `tag=mastodon` in the playground on the hashtag endpoint page. [Get a free API key](https://perceptlayer.com/signup) if you don't have one. Other networks are on the [social media APIs](https://perceptlayer.com/verticals/social) page, and more single-source guides are in [API guides](https://perceptlayer.com/blog/category/api-guides).

## APIs in this post

-   [Mastodon **1 credit per call** · 5 endpoints](https://perceptlayer.com/apis/mastodon)

## Frequently asked questions

### Is this Mastodon's own API?

No. These are Perceptlayer endpoints that return public Mastodon data, collected from publicly available sources and returned as found at the time of the call. This guide makes no claims about Mastodon's own interfaces or any instance's rules; compare them yourself and read the terms of the servers you query before you use the data.

### Are all Mastodon endpoints restricted?

Yes. All five, `hashtag`, `search`, `status`, `statuses` and `profile`, need the restricted-endpoint terms accepted in the dashboard. Until then a call returns `restricted_endpoint` (403) and costs nothing. The terms don't permit collecting personal data without a lawful basis or using it to contact people, so keep jobs at the level of topics and instances.

### Can I choose which Mastodon server to query?

Every endpoint takes an optional `instance` parameter of up to 253 characters, and all the recordings use `mastodon.social`. The recorded hashtag timeline on that instance included a post whose `uri` points to another server, so one instance's timeline can show posts from elsewhere. Count the `uri` host to see where posts came from.

### How do I page through a hashtag timeline?

The response's `pagination` block has `has_more`, `next_cursor` and `prev_cursor`, and in the recording `prev_cursor` equals the first post's `id`. The endpoint takes `max_id`, `min_id` and `since_id`, but how those pair with the cursors isn't documented. Test it in the playground; each extra page is 1 more credit.

### How fast can I poll Mastodon hashtags?

Limits are per account, shared by all its keys, and counted per minute. A free account gets 1 request a second, 60 a minute, so a 20-tag poll finishes in under a minute. Paying accounts run at least 5 requests a second, 300 a minute, depending on the pack. The [rate limits docs](https://docs.perceptlayer.com/rate-limits) list the rate each pack includes.

mastodon fediverse hashtags social media data python

## More from the blog

1.  [API guides](https://perceptlayer.com/blog/category/api-guides) 23 Nov 2026 Perceptlayer 7 min read
    
    ## [Bluesky API: Public Posts and Feeds as JSON](https://perceptlayer.com/blog/bluesky-api-json)
    
    Search public Bluesky posts as JSON with likeCount, repostCount, replyCount and langs per post, at 1 credit a call. All 15 endpoints are restricted.
    
2.  [API guides](https://perceptlayer.com/blog/category/api-guides) 21 Nov 2026 Perceptlayer 7 min read
    
    ## [Truth Social API: Public Posts as JSON](https://perceptlayer.com/blog/truth-social-api-json)
    
    Seven Truth Social endpoints as JSON at 1 credit each: public posts with reply, reblog and favourite counts, live shows and video. All are restricted.
    
3.  [API guides](https://perceptlayer.com/blog/category/api-guides) 4 Nov 2026 Perceptlayer 9 min read
    
    ## [TikTok Scraper or API: Hashtag, Sound and Trend Data](https://perceptlayer.com/blog/tiktok-scraper-vs-api)
    
    A TikTok scraper next to 31 TikTok endpoints at 1 credit a call: trending hashtags by country, hashtag and sound posts, and 2 credits per hashtag tracked a day.
