Replicate

Official JavaScript/TypeScript client for running and managing machine learning models on Replicate's cloud API.

SDK
npm
v1.4.0
598stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
54/100Fair
Development Activity0
Maintenance48
Community76
Maturity52
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture78
Code Quality85
Innovation82
Learning Curve80

Replicate is the official Node.js/JavaScript client for Replicate, the platform for running open-source machine learning models in the cloud via API. It wraps every major Replicate HTTP endpoint — predictions, models, deployments, trainings, files, hardware, and collections — behind a typed, promise-based interface, so applications can run models like Stable Diffusion or Flux, poll or stream their progress, and handle file inputs/outputs without hand-rolling HTTP calls.

The client is built to work identically across Node.js, Bun, Deno, and edge runtimes such as Cloudflare Workers and Vercel Functions, with dedicated integration test suites verifying each target. It ships first-class TypeScript definitions, automatic retry-with-backoff for rate-limited or failed requests, webhook signature verification, and a FileOutput abstraction that streams generated files (images, audio, etc.) directly as Blob/ReadableStream without requiring callers to write custom polling or download logic.

What You Get

  • A Replicate client class covering predictions, models, deployments, trainings, files, hardware, collections, and webhooks in one object
  • A high-level run() method that creates a prediction, blocks or polls until completion, and returns typed output — including automatic FileOutput wrapping for URLs/data URIs
  • A stream() async generator that yields Server-Sent Events for real-time prediction progress instead of polling
  • Built-in automatic retries with exponential backoff for 429/5xx responses, plus webhook signature validation via validateWebhook
  • Full TypeScript type definitions (index.d.ts) and verified compatibility across Node.js, Bun, Deno, Cloudflare Workers, and browser bundles

Common Use Cases

  • Backend services that run a hosted model (e.g. Stable Diffusion, Flux, Whisper) and return the result to a web or mobile client
  • Streaming partial model output to a frontend in real time using replicate.stream() instead of polling for completion
  • Serverless/edge functions (Vercel, Cloudflare Workers, AWS Lambda) that call Replicate models without a persistent server
  • Webhook-driven pipelines that receive prediction status updates instead of polling, verified with validateWebhook

Under The Hood

Architecture The client class (index.js) instantiates namespaced sub-clients (this.predictions, this.models, this.deployments, etc.) each bound from separate lib/*.js modules via .bind(this), giving each module access to the shared request() method without inheritance. request() centralizes URL building, header injection (auth bearer token, content-type, user-agent), body serialization (JSON or FormData), and retry logic via withAutomaticRetries in lib/util.js. The high-level run() orchestrates predictions.create → wait/poll → transform(output), using ModelVersionIdentifier.parse (lib/identifier.js) to distinguish an “owner/name” ref from an “owner/name:version” ref, and stream() follows an analogous path but yields SSE events from lib/stream.js’s createReadableStream, which conditionally polyfills TextDecoderStream and pulls in a vendored event-source parser. This is a flat, function-composition architecture with no class hierarchy beyond ApiError and Replicate itself — straightforward to extend by adding a new lib/*.js module and binding it in the constructor. Because every resource module depends on this.request(), a breaking change to that one method would ripple across the entire API surface.

Tech Stack TypeScript is used only for type declarations and compile-time checking (tsc), while the implementation itself is plain CommonJS JavaScript, formatted and linted with Biome and validated for package correctness with publint. Tests run through Jest with ts-jest. Runtime dependencies are minimal — only readable-stream as an optional polyfill — with everything else relying on platform-native fetch, ReadableStream, and TextDecoderStream, backed by vendored polyfills (vendor/eventsource-parser, vendor/streams-text-encoding) for environments that lack them. There is no web or ORM framework involved; this is a headless HTTP client targeting Node.js 18+, explicitly tested against Bun and Deno as well.

Code Quality Testing is extensive: the main index.test.ts suite mocks Replicate’s HTTP API with nock across thousands of lines, and seven separate integration-test projects verify real runtime compatibility for Deno, Bun, Cloudflare Workers, browser bundles, ESM, CommonJS, and TypeScript consumption. Error handling is explicit and typed — a dedicated ApiError class carries the original Request/Response objects and is thrown uniformly by request() rather than swallowed, while user-facing validation errors (invalid webhook URL, missing model/version) throw plain Errors with clear messages. Naming is consistent (camelCase methods mirroring REST resource names), JSDoc annotates nearly every exported function with parameter and return types, and CI runs lint (Biome + publint) plus the full test suite on every change.

API Design The library’s core ergonomic win is collapsing Replicate’s async job-based API (create a prediction, poll, fetch the result) into a single await replicate.run(ref, { input }) call, while still exposing the low-level primitives (predictions.create/get/cancel) for callers who need more control. stream() lets consumers for await real-time SSE progress using the same ref/input shape as run(). The FileOutput object’s .blob()/.url() duality avoids forcing every caller to write custom download logic for binary outputs, and the wait: { mode: "block" | "poll", timeout, interval } option gives fine-grained control over blocking behavior via Replicate’s Prefer: wait HTTP header. Documentation and JSDoc are thorough, and onboarding requires only new Replicate({ auth }) plus one .run() call to get a working example — about as low-boilerplate as this class of API-wrapper library gets.

Used by 6 apps in this directory

Rust
53%
Other

Cap

Team Chat · Video Conferencing

21,859

Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.

View details
89
Repo Health
81
Technical
64
Dependency
Built with
Rust53%
TypeScript43%
Updated yesterday
TypeScript
84%
Apache 2.0

Continue

Developer Tools · AI Development · AI Code Assistants

35,808

Open-source coding agent for VS Code, JetBrains, and CLI with support for 30+ LLM providers.

View details
81
Repo Health
88
Technical
62
Dependency
Built with
TypeScript84%
Updated yesterday
TypeScript
62%
Other

Flowise

Developer Tools · Automation · No Code Platforms

55,427

Drag-and-drop visual builder for AI agents, RAG pipelines, and multi-agent systems—deploy anywhere in minutes.

View details
86
Repo Health
77
Technical
63
Dependency
Built with
TypeScript62%
JavaScript27%
Updated 3 weeks ago
TypeScript
99%
Other

LobeHub

AI Assistants · Productivity · Automation

82,273

Your Chief Agent Operator — build, schedule, and collaborate with an entire AI team in one self-hostable workspace.

View details
92
Repo Health
81
Technical
69
Dependency
Built with
TypeScript99%
Updated today
TypeScript
58%
AGPL 3.0

Puter

File Storage · Developer Tools

43,424

A self-hostable, web-based internet OS with desktop GUI, cloud storage, AI drivers, and a developer SDK — all running in your browser.

View details
88
Repo Health
88
Technical
70
Dependency
Built with
TypeScript58%
JavaScript38%
Updated yesterday
TypeScript
96%
Other

Refly

No Code Platforms · AI Development · Automation

7,502

Build deterministic, versioned agent skills from natural language—run them anywhere from Claude Code to Slack.

View details
64
Repo Health
76
Technical
63
Dependency
Built with
TypeScript96%
Updated 1 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search