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
Configure credentials
Configure the client with a single key. Environment variables are recommended on the server.Call a model
Leverage the queue for long-running tasks. Optionally listen to queue updates.Tag requests with metadata
Attach your own flat string map to a request — job ids, environments, batch labels — by passingmetadata next to input. It’s supported on run, subscribe, queue.submit, and stream:
metadata is sent as a reserved top-level sibling of your input fields — never nested inside input, and never forwarded to the model. It’s stored on the request so you can filter your history by it later; the client itself has no read-back or filtering API, so read tags back through the request lifecycle metadata filter or the MCP list_my_requests tool.
The client validates metadata before dispatching, mirroring the API:
A violation throws a
ValidationError ("Invalid metadata", status 400) before any request is sent — every offending key is reported at once and is addressable with error.getFieldErrors("<key>"). Omitting metadata leaves the body untouched; an explicit {} is valid and is sent as-is.
Get called back with webhooks
Instead of holding asubscribe open, pass a webhookUrl and ModelRunner POSTs the result to you when the request settles. Nothing is lost if your process restarts mid-request, which is what makes this the right choice for long video and training jobs.
webhookUrl also works on subscribe, if you want both a callback and in-process updates. See the webhooks guide for the events, the retry schedule, and the full payload shape.
Verify a delivery
Every delivery is signed. Fetch your signing secret once and keep it in your server environment — never in a browser:verify is async because it uses the Web Crypto API, which is what lets the same code run in Node, serverless runtimes and edge workers. It returns the parsed payload and throws WebhookVerificationError on any failure.
Two more things your endpoint must do, both easy to get wrong:
- Return
2xxdirectly. Redirects are not followed, so a301— a missing trailing slash, anhttp→httpsupgrade — is recorded as a failed attempt and you see nothing but silence. - Deduplicate on the
webhook-idheader. Delivery is at-least-once and that id is stable across retries of the same delivery.
Rotate the secret
Rotating twice inside that window ends it early and breaks receivers still holding the original secret, so this call is never retried automatically. Rotate once, deploy, then rotate again if you need to.
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).url to your model input:

