Using the SDK
@snapnedit/sdk wraps the raw HTTP flow described in API Authentication — upload, create job, poll until done, download the result — into a single run() call.
Setup
import { createClient } from '@snapnedit/sdk';
const client = createClient({
baseUrl: 'https://api.snapnedit.com',
apiKey: 'sk_your_key_here',
});
Running an operation
const fileBytes = new Uint8Array(await file.arrayBuffer());
const { output, mime } = await client.run('remove-background', fileBytes, {
mime: 'image/png',
});
// output: Uint8Array — the resulting image
// mime: string — the resulting image's mime type
run() uploads the input, creates the job with the given operation id and params, polls job status until it reaches a terminal state, and downloads the output for you. It throws SnapneditApiError if any request fails, or SnapneditTimeoutError if the job doesn't finish within the poll timeout.
Operation ids and params
run()'s first argument is one of the operation ids listed in API Authentication; its third argument (params) is operation-specific — most operations need no extra params beyond the input image, while mask-guided operations (magic-eraser, generative-fill) also take a maskAssetId.
Lower-level access
If you need more control than run() gives you (e.g. to show upload progress separately from job progress), the client also exposes upload(), createJob(), and getJob() individually — the same three calls run() composes internally.