TypeScript SDK
Call the Masko API from Node.js or Electron main on macOS. The SDK runs the masko command for sign-in and requests, so it uses your saved login. It does not display mascots.
Install
npm install @masko/sdk@masko/sdk 0.3.0 needs Node.js 20+, an Apple Silicon Mac with macOS 14+, and the masko command 0.4.0 or later. Install it with the terminal setup, or bundle it with your app. With an older command, calls fail with sdk_update_required and the install command to run.
Use
import { Masko } from '@masko/sdk';
const client = Masko.client({ client: 'my-app/1.0' }); // Reuses your saved login.
const credits = await client.credits();
const { data: mascots, meta } = await client.studio('GET', 'mascots?limit=50');
const job = await client.studio('POST', 'mascots/MASCOT_ID/generate', {
type: 'animation',
item_id: 'ITEM_ID',
animation_model: 'standard', // 2 credits a second
animation_prompt: 'waves hello'
});Methods
| Call | Result |
|---|---|
Masko.client({ apiURL?, apiKey?, runtimePath?, client? }) | Creates a client. An apiKey stays in memory. client names your app to Masko. |
client.login({ noBrowser?, device?, apiKey? }) | Signs in with a browser or device code, or validates and saves an API key. |
client.logout() | Signs out on this Mac and revokes the saved session. |
client.whoami() | Returns the account, workspace name, access and credits. |
client.credits() | Returns the credit balance: total, subscription and top-up. |
client.studio(method, path, body?, { idempotencyKey? }) | Calls a Masko API path with GET, POST, PUT, PATCH or DELETE. Returns { data, meta? }. |
client.feedback(text) | Sends feedback to the Masko team. The first line is the summary. |
client.assets.show(id) | Returns one asset. |
client.assets.download(id, { output }) | Saves one asset as the new file output, in a folder that exists. It never overwrites a file. |
studio() takes the API's /v1 paths, such as mascots, jobs/JOB_ID?wait=true or credit-checkouts; a job's poll_url works too. Sign-in, admin and the old collections paths are rejected before any request is sent. It returns the API's response: data, plus meta.pagination for lists, where next_cursor gets the next page. See the API reference.
Every POST sends an idempotency key. To retry a failed POST without running or charging it twice, pass the key from its error as idempotencyKey.
Keys and errors
Use this SDK on a server, or in trusted tooling. Never put an API key in a shipped app or a public repository. The SDK sends an in-memory key to the runtime over stdin, never as a command argument.
Errors are MaskoError objects with code, message and the API's details (for example required and available credits). When the API answered they also carry status, requestId, docUrl and param; a failed POST carries its idempotencyKey. Account and API calls need the macOS runtime, so call them from Electron main or Node.js, never from a browser page or renderer.
Upgrading
- From 0.2.0:
studio()returns{ data, meta }instead ofdataalone, so read.data. Assets and jobs usemascot_idinstead ofcollection_id. Update themaskocommand to 0.4.0 at the same time. - From 0.1.0: version 0.2.0 removed the on-screen API (
Masko.mascot,Masko.connect,Masko.playback, andshow,state,play,position,resize). Floating mascots run in Masko for Mac.
Next steps
Read the quickstart for the REST calls behind these operations, and the authentication guide for API keys and workspaces.
