Typed API client
The typed client retrieves public skins, Blockbench models and builds without imposing a component system. Use it for server integrations, desktop networking or an application with its own state management. Public reads do not require a key. The client returns resource metadata separately from file bytes, allowing the host to control both transfer timing and attribution.
Configure transport and credentials
createClient accepts origin, fetch, agent and key. origin selects another deployment; fetch integrates a host transport such as Electron networking. Outside a browser, agent identifies the application through User-Agent; a browser sends its own identity. A developer key belongs only on a trusted server. Browser code, a webview or a distributed desktop bundle cannot keep that key secret. The default client remains suitable for ordinary public catalogue requests.
import { createClient } from 'mosaicary';
const client = createClient({
origin: 'https://mosaicary.com',
fetch: globalThis.fetch,
agent: 'ExampleLauncher/1.0',
// key: process.env.MOSAICARY_KEY, // Trusted server only.
});Request one page at a time
skins, models and builds each expose list(query) and get(id). Lists return items, page, per, total and pages. Shared queries include search, category, tags, order and pagination; skin queries add arms and size, model queries add animation or format, and build queries select a build format. Request another page when needed instead of collecting every page in advance. Use get for the current metadata of a particular resource.
const result = await client.skins.list({
q: 'hoodie',
arms: 'slim',
size: '64',
page: 1,
per: 12,
});
if (result.items[0]) {
const item = await client.skins.get(result.items[0].id);
}
const models = await client.models.list({ animated: true });
const builds = await client.builds.list({ format: 'litematica' });Separate previews, downloads and credits
client.file(item) returns bytes and counts as a download. Pass { view: true } only for a preview. fileOf creates the appropriate URL without fetching it, while creditOf returns a display name and the resource page link. Both helpers work with skins, models and builds. A direct file request is independent of listing metadata: cache previews appropriately and retain the resource’s attribution when drawing custom results.
import { fileOf, creditOf } from 'mosaicary';
const bytes = await client.file(item, { view: true });
const previewURL = fileOf(item, { view: true });
const { name, href } = creditOf(item);Handle API refusals and network errors
MosaicaryError exposes HTTP status, API code, message and optional retryAfter in seconds. For a 429 response, schedule the next request after that interval rather than retrying continuously. Transport failures may be ordinary errors, so the error handling path must distinguish them. The client does not provide an automatic retry policy or an abort option. Applications needing cancellation can supply a transport through fetch; all actual response handling remains the client’s responsibility.
import { MosaicaryError } from 'mosaicary';
try {
await client.skins.list();
} catch (error) {
if (error instanceof MosaicaryError) {
console.log(error.status, error.code, error.retryAfter);
// For 429, schedule a later request after retryAfter seconds.
} else {
console.error(error); // Network or host transport failure.
}
}