Skip to content

SDK

@layer_ai/sdk is Layer’s official JavaScript and TypeScript SDK, published to npm. It reaches the same models, workspaces, and Creative Unit balance as the app, from Node, a build script, a game-tooling service, or an agent.

Terminal window
npm install @layer_ai/sdk

Then generate:

import { Layer } from '@layer_ai/sdk'
const layer = new Layer({ apiKey: process.env.LAYER_API_KEY })
const run = await layer.inferences.generate({
prompt: 'a crystal sword icon, transparent background',
})
console.log(run.outputs?.[0]?.url)

generate() prices the run, submits it, and polls until it finishes. Leave base_model_id off and Layer picks the recommended model for the modality; the finished run reports which one it used.

Pin the version in CI so a release cannot change a build under you:

Terminal window
npm install @layer_ai/sdk@1.0.0

Node 20.6 and up, or any runtime with a global fetch — Bun, Deno, Cloudflare Workers, and modern browsers included. The package is ESM only, ships its own TypeScript types, and has no dependencies.

Running in a browser puts your credential in the browser. Use a short-lived OAuth access token there, never a Personal Access Token; see authentication.

Every namespace maps to a resource of the v2 REST API.

Namespace What it reaches
layer.inferences Generation: estimate, create, wait, cancel
layer.baseModels The model catalogue, Layer’s defaults, and per-model parameter schemas
layer.referenceSets Trained subjects, styles, and characters
layer.trainingRuns Training a reference set, and the model it produces
layer.files Direct-to-storage uploads and per-file quality scores
layer.workflows Saved multi-step Blueprints and their runs
layer.projects Projects and their members
layer.workspaces Workspaces, balance, and usage
layer.scores Output scoring rules, and running them over files

Anything the SDK has no method for is still one call away through the transport, which keeps the authentication, retries, and error handling:

await layer.http.get('/v2/workspaces/…/groups')