Functions
library.filters.register
function library.filters.register(input: LibraryFilterDeclaration): void;
Adds a filter to the library's filter bar, driven by a column of one of your tables. Only mods call it, only from setup, and the table must be one your mod registered. The filter is published as <modId>/<id>; the kind of the column (number or text) is the kind of the filter. A chart takes part only if its row has the given version (at least 1): an older row is stale and ignored.
name is the label, 1 to 64 characters; unit is a suffix of at most 16 characters. A mod registers at most 32 filters. The mod id host is reserved for the game's own filters.
tables.register({ id: "my_rating", columns: [{ name: "overall", kind: "number", indexed: true }] });
library.filters.register({ id: "overall", name: "My rating", table: "my_rating", column: "overall", version: 1, unit: "MSD" });
Errors you will see: filter must reference a registered column of its mod, filter table is not registered by this mod, filter version must be positive, filter id is registered twice, a mod registers at most 32 library filters, host is reserved for neutral library filters, filter unit must have at most 16 characters and no control characters. See Library filters.
metron.catalog
function metron.catalog(input: void): MetronCatalog;
Lists the native calculators Metron offers: 10 entries today (osu-2016, osu-2018, osu-current, etterna-515, quaver-2025, interlude-2025, daniel-2026, sunnyxxy-2024, prism, prismcalc-1). Each has its id, its version and performance, which is true when metron.performance can compute a performance for it (osu-2018, etterna-515 and prism). It reads no state and returns at once, from setup or an event handler, never at the top level of the file.
Read the version from here when you register a rating: it changes when a calculator's behavior changes.
for (const calculator of metron.catalog().calculators) {
log.info(`${calculator.id} v${calculator.version}${calculator.performance ? " (performance)" : ""}`);
}
metron.difficulty
function metron.difficulty(input: CalculatorRequest): number | null;
Returns the difficulty of the chart being played under one calculator, or null when the chart has no rating for it or no chart is playing. It reads the ratings the library already computed (the same values as game.song().ratings), so it is instant and costs nothing. calculator is an id of metron.catalog(); an unknown id throws unknown Metron calculator "x". The unit depends on the calculator: stars for the osu! family, MSD for the MinaCalc ones.
const stars = metron.difficulty({ calculator: "osu-2018" });
if (stars !== null) log.info(`osu! 2018: ${stars.toFixed(2)}`);
metron.performance
function metron.performance(input: PerformanceRequest): number | null;
Starts the calculation of the performance (the pp or SSR) of the chart being played at a given accuracy. Only mods call it, from an event handler once a chart plays. It returns a request number, or null when the workers are busy (2 outstanding requests per mod, 64 in total). The answer comes as a metron.performanceResult event with the same requestId: value (or error) and unit, pp for osu-2018 and prism, SSR for etterna-515.
accuracy is a fraction from 0 to 1, not a percentage. Only the calculators whose performance flag is true in metron.catalog() work. The result is meaningful when the accuracy comes from the calculator's own judgement; the game labels other mixes nonstandard.
ctx.on("game.songStart", () => {
metron.performance({ calculator: "prism", accuracy: 0.98 });
});
ctx.on("metron.performanceResult", (result) => {
if (result.value != null) log.info(`98%: ${result.value.toFixed(1)} ${result.unit}`);
});
Errors you will see: Metron has no performance calculator for osu-2016, accuracy must be a fraction from 0 to 1, no decoded chart is playing, only mods request Metron performance, native score workers are unavailable.
ratings.backfill
function ratings.backfill(input: BackfillRequest): number | null;
Asks the host to calculate a registered rating for the charts that lack a current row. Without charts it looks at the whole library; with charts (at most 8192 library chart ids, for example from library.chartsAdded) it looks only at those charts. Only mods call it, from setup or an event handler (library.ready is the usual place). It returns a request number, or null when the workers are busy: a mod may keep 16 backfills outstanding and all mods together 64, so call it again at the next check.
The work runs on the library's workers, never on the mods thread. Progress comes back to your mod as ratings.progress events carrying the same requestId (done, total, failed, finished, error, ahead); the game also shows the request in its processing window.
ctx.on("library.ready", () => {
if (ratings.backfill({ id: "prismcalc-1" }) === null) log.warn("the rating workers are busy");
});
ctx.on("ratings.progress", (progress) => {
if (progress.finished) log.info(`${progress.done}/${progress.total} rated, ${progress.failed} failed`);
});
Errors you will see: unknown registered rating (the id names a rating of this mod, not a calculator), too many charts in one scoped backfill, invalid chart id, rating table is unavailable, library workers are unavailable, only mods calculate library ratings.
ratings.register
function ratings.register(input: RatingDeclaration): void;
Declares a rating: a Metron calculator whose result is stored in a column of one of your tables and shown in the library and the chart panel. Only mods call it, only from setup, and the table must have been registered before by tables.register in the same mod. The rating is published as <modId>/<id>. The host computes the values (see ratings.backfill); your script never writes a row.
calculator is an id from metron.catalog() (10 of them today, among them osu-2018, etterna-515, prism, prismcalc-1). version must equal the calculator's version from the same catalog: a mismatch is refused, and a stored row with an older version is stale. column must be a numeric column. panels (at most 4) draw the chart panel: metrics, bars and radar take fields (1 to 16, 3 to 12 for a radar) that read a numeric column or a neutral chart metric, timeline takes 1 or 2 series (density, bpm). patterns (at most 12) name numeric columns that score one pattern each; short is 1 to 5 characters and color is #rgb, #rrggbb or a theme role. colors gives a color scale with up to 16 increasing stops; an invalid scale is dropped with a warning and the rating still registers.
| Limit | Value |
|---|---|
| Ratings per mod | 16 |
id |
a-z, 0-9, -, 1 to 32 characters |
name |
1 to 64 characters; unit 1 to 16 characters |
| Panels | at most 4; title 1 to 64 characters; field decimals 0 to 3; max in (0, 1000000] |
| Patterns | at most 12; label up to 32 characters |
tables.register({ id: "prism_rating", columns: [{ name: "overall", kind: "number", indexed: true }] });
const calculator = metron.catalog().calculators.find((entry) => entry.id === "prismcalc-1");
if (calculator) {
ratings.register({
id: "prismcalc-1",
name: "PrismCalc",
calculator: calculator.id,
unit: "MSD",
table: "prism_rating",
column: "overall",
version: calculator.version,
});
}
Errors you will see: rating table is not registered, rating must reference a registered numeric column of its mod, rating version must match the native calculator version, unknown Metron calculator "x", a mod registers at most 16 ratings, rating `x` is registered twice, a rating has at most 4 panels, panel must have 3 to 12 fields, a rating declares at most 12 patterns. See Writing a rating.
tables.register
function tables.register(input: TableDefinition): void;
Declares a table the host keeps in the library database, one row per chart, owned by your mod. Only mods call it, only from setup. It is the storage behind ratings.register and library.filters.register; no function writes rows from a script, the host fills the rating column when ratings.backfill runs. The table survives restarts, and registering it again with the same columns is harmless.
id and every column name match ^[a-z][a-z0-9_]{0,31}$. A column is number or text; indexed: true adds an index (set it on the columns you filter on). A table has 1 to 32 columns. The names chart_id, calc_version, chart_stamp, chart_size and error are reserved: the host adds them to every table. A mod keeps at most 16 tables, and a table id is unique per mod. Changing the type of a column that already exists is refused.
tables.register({
id: "my_rating",
columns: [
{ name: "overall", kind: "number", indexed: true },
{ name: "label", kind: "text" },
],
});
Errors you will see: table and column ids must use lowercase ASCII letters, digits and underscores (1–32 characters), a mod table has 1–32 columns, duplicate or reserved mod column, a mod registers at most 16 uniquely named tables, and, as a mod message, chart table registration failed: cannot change an existing column type.
Types
Definitions read from the SDK. A type used here that is defined on another page is listed under Defined elsewhere.
type LibraryFilterDeclaration = {
id: string;
name: string;
table: string;
column: string;
version: number;
unit?: string;
};
type MetronCatalog = { calculators: MetronCalculator[]; };
type MetronCalculator = {
id: string;
performance: boolean;
version: number;
};
type CalculatorRequest = { calculator: string; };
type PerformanceRequest = { calculator: string; accuracy: number; };
type BackfillRequest = { id: string; charts?: number[] | null; };
type RatingDeclaration = {
id: string;
name: string;
calculator: string;
unit: string;
table: string;
column: string;
version: number;
panels?: RatingPanel[];
colors?: RatingColors | null;
patterns?: RatingPattern[];
};
type RatingPanel = { kind: "metrics"; title: string; fields: RatingField[]; } | { kind: "bars"; title: string; fields: RatingField[]; max?: number | null; } | { kind: "radar"; title: string; fields: RatingField[]; max?: number | null; } | { kind: "timeline"; title: string; series: RatingSeries[]; };
type RatingField = {
label: string;
source: RatingFieldSource;
unit?: string;
decimals?: number;
};
type RatingFieldSource = { kind: "column"; column: string; } | { kind: "chart"; metric: ChartMetric; };
type ChartMetric = "notes" | "holds" | "holdPercent" | "averageNps" | "peakNps" | "bpmMin" | "bpmMax" | "duration";
type RatingSeries = {
label: string;
source: RatingSeriesSource;
unit: string;
};
type RatingSeriesSource = "density" | "bpm";
type RatingColors = { scale?: number | null; stops: RatingColorStop[]; };
type RatingColorStop = { at: number; color: string; };
type RatingPattern = {
column: string;
label: string;
short: string;
color?: string | null;
};
type TableDefinition = { id: string; columns: ColumnDefinition[]; };
type ColumnDefinition = {
name: string;
kind: ColumnKind;
indexed?: boolean;
};
type ColumnKind = "number" | "text";