Skip to main content

Overview

ModelRunner provides a unified JavaScript/TypeScript SDK to call any supported model with a consistent interface. Use it in Node.js, serverless runtimes, and—via a proxy—in the browser.
For client-side apps, never expose secrets. Use the proxy pattern shown below to safely forward requests.

Installation

npm i @modelrunner/client

Configure credentials

Configure the client with a single key. Environment variables are recommended on the server.
import { modelrunner } from "@modelrunner/client";

modelrunner.config({
  credentials: process.env.MODELRUNNER_KEY,
});
Get your credentials from your ModelRunner account. Keep them server-only.

Call a model

Leverage the queue for long-running tasks. Optionally listen to queue updates.
import { modelrunner } from "@modelrunner/client";

const result = await modelrunner.subscribe("bytedance/sdxl-lightning-4step", {
  input: { "prompt": "two friends cooking together" },
  onQueueUpdate(update) {
    if (update.status === "IN_QUEUE") {
      console.log(`Position in queue: ${update.position}`);
    }
  },
});

console.log(result.output);

Upload files

Upload local files to ModelRunner storage and receive a temporary URL you can pass to model inputs (for example, image or audio URLs).
import { modelrunner } from "@modelrunner/client";
import fs from "node:fs";

const fileBuffer = fs.readFileSync("./image.jpeg");
const url = await modelrunner.storage.upload(new Blob([fileBuffer]));
console.log(url);
You can then pass the returned url to your model input:
const result = await modelrunner.subscribe("swook/inspyrenet", {
  input: { image_path: url,},
});
In Node.js, Blob is available in modern runtimes (Node 18+). If you use an older version, consider upgrading or using a compatible polyfill.The storage service accepts any binary file type (images, audio, video, documents).

Using the client in browsers (via proxy)

To keep secrets safe, use the official server proxy so credentials stay on your server.
// /pages/api/modelrunner/proxy.ts
export { handler as default } from "@modelrunner/server-proxy/nextjs";
Set MODELRUNNER_KEY in your server environment. The proxy reads this value to authenticate requests. Never expose it in the browser.