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:
| Text | Graphemes | UTF-8 bytes | JavaScript .length |
|---|---|---|---|
a | 1 | 1 | 1 |
é (one code point) | 1 | 2 | 1 |
é (e and a combining accent) | 1 | 3 | 2 |
日 | 1 | 3 | 1 |
| 👍 | 1 | 4 | 2 |
| 👋🏽 (with a skin tone) | 1 | 8 | 4 |
| 🇫🇷 (a flag) | 1 | 8 | 4 |
| 👨👩👧👦 (a family) | 1 | 25 | 11 |
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:
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:
import { RichText } from "@atproto/api";
const rt = new RichText({ text });
rt.graphemeLength; // graphemes
rt.length; // UTF-8 bytesCount it in Python
Python's len() counts code points. The regex package (not the built-in re) matches one grapheme with \X:
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}Links and mentions
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:
- it takes as many graphemes as fit, never cutting one in half;
- 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;
- with numbering on, the
1/3suffix 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.