Tool documentation

How Bluesky counts the length of a post

Why Bluesky counts graphemes, not characters: the 300-grapheme and 3,000-byte limits of a post, with examples and code to count them in TypeScript and Python.

Two limits, one post

The text of a Bluesky post is the text field of an app.bsky.feed.post record. Its lexicon sets two limits on it, and a post must respect both:

  • maxGraphemes: 300: at most 300 graphemes, the limit people see in the app;
  • maxLength: 3000: at most 3,000 bytes once the text is encoded in UTF-8.

The second limit rarely matters: 300 graphemes of Latin text take about 300 to 600 bytes. It only shows up with long emoji sequences or with scripts that take several bytes per character.

What a grapheme is

A grapheme (an "extended grapheme cluster" in the Unicode standard) is what a reader sees as one character. Under the hood, it can be several Unicode code points, and each code point takes 1 to 4 bytes in UTF-8:

TextGraphemesUTF-8 bytesJavaScript .length
a111
é (one code point)121
é (e and a combining accent)132
日131
👍142
👋🏽 (with a skin tone)184
🇫🇷 (a flag)184
👨‍👩‍👧‍👦 (a family)12511

This is why a counter that uses JavaScript's .length (UTF-16 code units) or Python's len() (code points) disagrees with the Bluesky app: both count an emoji as more than one character.

Count it in TypeScript

Intl.Segmenter is built into Node.js and every current browser:

ts
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });

export function postLength(text: string) {
  const graphemes = [...segmenter.segment(text)].length;
  const bytes = new TextEncoder().encode(text).length;
  return { graphemes, bytes, fits: graphemes <= 300 && bytes <= 3000 };
}

With the @atproto/api package, RichText gives the same two numbers:

ts
import { RichText } from "@atproto/api";

const rt = new RichText({ text });
rt.graphemeLength; // graphemes
rt.length; // UTF-8 bytes

Count it in Python

Python's len() counts code points. The regex package (not the built-in re) matches one grapheme with \X:

py
import regex  # pip install regex


def post_length(text: str) -> dict:
    graphemes = len(regex.findall(r"\X", text))
    size = len(text.encode("utf-8"))
    return {"graphemes": graphemes, "bytes": size, "fits": graphemes <= 300 and size <= 3000}

The Bluesky app shortens a long link in the text it posts and keeps the full address in a facet, so a link counts for its short form. A bot that posts through the API sends the text as it is: every character of the link counts, unless the bot shortens the visible text itself and adds the facet. Facets point into the text by UTF-8 byte offsets, not by characters, for the same reasons as above.

How the thread splitter cuts

When a text is too long, the counter's thread preview cuts it into posts that each respect both limits:

  1. it takes as many graphemes as fit, never cutting one in half;
  2. it goes back to the last paragraph break, else the end of a sentence, else a space, as long as that keeps at least half of the post;
  3. with numbering on, the 1/3 suffix counts toward the limits, so the parts are computed with it.

To post the parts as a thread from a bot, each post after the first replies to the one before it, with the first one as the root: see Schedule posts and Best practices.

Post character counter

Count your post the way Bluesky does.