/ai-infrastructure-replicate
Replicate SDK patterns for TypeScript/Node.js -- client setup, predictions, streaming, webhooks, file handling, model versioning, deployments, and training
$ npx -y skills add agents-inc/skills --skill ai-infrastructure-replicate --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/ai-infrastructure-replicate
Context preview
The summary Claude sees to decide when to auto-load this skill.
Replicate SDK patterns for TypeScript/Node.js -- client setup, predictions, streaming, webhooks, file handling, model versioning, deployments, and training
SKILL.md
ai-infrastructure-replicate.SKILL.mdname: ai-infrastructure-replicate
description: Replicate SDK patterns for TypeScript/Node.js -- client setup, predictions, streaming, webhooks, file handling, model versioning, deployments, and training
Replicate SDK Patterns
> **Quick Guide:** Use the `replicate` npm package to run open-source ML models on serverless GPUs. Use `replicate.run()` for synchronous execution that returns output directly, `replicate.stream()` for SSE-based streaming, or `replicate.predictions.create()` for async background jobs with webhook notifications. Models are referenced as `owner/model` (uses latest version) or `owner/model:version` (pinned). File outputs are `FileOutput` objects implementing `ReadableStream`. Cold starts are expected for infrequently-used models -- use deployments with `min_instances` to keep models warm.
---
<critical_requirements>
CRITICAL: Before Using This Skill
> **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants)
**(You MUST never hardcode API tokens -- always use environment variables via `process.env.REPLICATE_API_TOKEN`)**
**(You MUST handle `FileOutput` objects for models that return files -- do not assume outputs are plain strings or URLs)**
**(You MUST validate webhooks using `validateWebhook()` from the `replicate` package -- never trust unverified webhook payloads)**
**(You MUST account for cold starts when running infrequently-used models -- use deployments for latency-sensitive applications)**
**(You MUST specify model versions (`owner/model:version`) in production to ensure reproducible results -- unversioned references use the latest, which can change)**
</critical_requirements>
---
**Auto-detection:** Replicate, replicate, replicate.run, replicate.stream, replicate.predictions, replicate.deployments, replicate.trainings, replicate.models, FileOutput, validateWebhook, REPLICATE_API_TOKEN, serverless GPU, cold start, webhook_events_filter
**When to use:**
- Running open-source ML models (Llama, Stable Diffusion, Whisper, etc.) without managing GPU infrastructure
- Generating images, transcribing audio, running LLMs, or any ML inference via API
- Streaming LLM output in real-time with server-sent events
- Processing predictions asynchronously with webhook notifications
- Fine-tuning models with custom training data
- Running models on dedicated hardware with custom scaling via deployments
**Key patterns covered:**
- Client initialization and configuration (auth, user agent, file encoding)
- Running predictions (`replicate.run()`, `replicate.predictions.create()`, `replicate.wait()`)
- Streaming output (`replicate.stream()` with SSE events)
- Model versioning (`owner/model` vs `owner/model:version`)
- File input/output handling (`FileOutput`, file uploads, `Buffer` inputs)
- Webhooks (setup, event filtering, signature validation)
- Deployments (custom hardware, scaling, keeping models warm)
- Training / fine-tuning
**When NOT to use:**
- You need a unified multi-provider LLM SDK (OpenAI, Anthropic, Google) -- use a provider-agnostic SDK
- You want to run models locally -- Replicate is a cloud-only serverless platform
- You need sub-second latency guarantees without deployments -- cold starts can take minutes
---
Examples Index
- [Core: Setup, Predictions & Files](examples/core.md) -- Client init, run(), predictions.create(), wait(), file I/O, error handling
- [Streaming & Webhooks](examples/streaming-webhooks.md) -- stream(), SSE events, webhook setup, signature validation
- [Deployments & Training](examples/deployments-training.md) -- Custom hardware, scaling, fine-tuning, model management
- [Quick API Reference](reference.md) -- Method signatures, constructor options, error types, model reference format
---
<philosophy>
Philosophy
Replicate provides **serverless GPU infrastructure** for running open-source ML models. You send inputs, Replicate allocates GPU hardware, runs the model, and returns outputs. No Docker, no CUDA drivers, no GPU provisioning.
**Core principles:**
1. **Serverless execution** -- Models run on-demand on Replicate's infrastructure. You pay only for compute time. Cold starts are a trade-off for not maintaining always-on GPUs. 2. **Model marketplace** -- Thousands of community and official models available at `replicate.com/explore`. Run any public model with just its identifier. 3. **Version pinning for reproducibility** -- Models are versioned with SHA-256 hashes. Pin to a version in production (`owner/model:abc123...`) to guarantee identical behavior across deploys. 4. **Three execution modes** -- `replicate.run()` for synchronous wait, `replicate.stream()` for real-time SSE output, `replicate.predictions.create()` for fire-and-forget with webhooks. 5. **File-first I/O** -- Many models accept and produce files (images, audio, video). The SDK handles file uploads automatically and returns `FileOutput` objects for file outputs.
</philosophy>
---
<patterns>
Core Patterns
Pattern 1: Client Setup
Initialize the Replicate client. It auto-reads `REPLICATE_API_TOKEN` from the environment.
// lib/replicate.ts -- basic setup
import Replicate from "replicate";
const replicate = new Replicate();
export { replicate };// lib/replicate.ts -- explicit auth + custom user agent
import Replicate from "replicate";
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN, // Auto-reads from env if omitted
userAgent: "my-app/1.0.0",
});
export { replicate };**Why good:** Minimal setup, env var auto-detected, explicit auth optional but useful for clarity
// BAD: Hardcoded token
const replicate = new Replicate({
auth: "r8_abc123...",
});**Why bad:** Hardcoded API token is a security risk, will leak in version control
**See:** [examples/core.md](examples/core.md) for full constructor options, error handling patterns
---
Pattern 2: Runni
Read more
name: ai-infrastructure-replicate description: Replicate SDK patterns for TypeScript/Node.js -- client setup, predictions, streaming, webhooks, file handling, model versioning, deployments, and training
Replicate SDK Patterns
> **Quick Guide:** Use the `replicate` npm package to run open-source ML models on serverless GPUs. Use `replicate.run()` for synchronous execution that returns output directly, `replicate.stream()` for SSE-based streaming, or `replicate.predictions.create()` for async background jobs with webhook notifications. Models are referenced as `owner/model` (uses latest version) or `owner/model:version` (pinned). File outputs are `FileOutput` objects implementing `ReadableStream`. Cold starts are expected for infrequently-used models -- use deployments with `min_instances` to keep models warm.
---
<critical_requirements>
CRITICAL: Before Using This Skill
> **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants)
**(You MUST never hardcode API tokens -- always use environment variables via `process.env.REPLICATE_API_TOKEN`)**
**(You MUST handle `FileOutput` objects for models that return files -- do not assume outputs are plain strings or URLs)**
**(You MUST validate webhooks using `validateWebhook()` from the `replicate` package -- never trust unverified webhook payloads)**
**(You MUST account for cold starts when running infrequently-used models -- use deployments for latency-sensitive applications)**
**(You MUST specify model versions (`owner/model:version`) in production to ensure reproducible results -- unversioned references use the latest, which can change)**
</critical_requirements>
---
**Auto-detection:** Replicate, replicate, replicate.run, replicate.stream, replicate.predictions, replicate.deployments, replicate.trainings, replicate.models, FileOutput, validateWebhook, REPLICATE_API_TOKEN, serverless GPU, cold start, webhook_events_filter
**When to use:**
- Running open-source ML models (Llama, Stable Diffusion, Whisper, etc.) without managing GPU infrastructure
- Generating images, transcribing audio, running LLMs, or any ML inference via API
- Streaming LLM output in real-time with server-sent events
- Processing predictions asynchronously with webhook notifications
- Fine-tuning models with custom training data
- Running models on dedicated hardware with custom scaling via deployments
**Key patterns covered:**
- Client initialization and configuration (auth, user agent, file encoding)
- Running predictions (`replicate.run()`, `replicate.predictions.create()`, `replicate.wait()`)
- Streaming output (`replicate.stream()` with SSE events)
- Model versioning (`owner/model` vs `owner/model:version`)
- File input/output handling (`FileOutput`, file uploads, `Buffer` inputs)
- Webhooks (setup, event filtering, signature validation)
- Deployments (custom hardware, scaling, keeping models warm)
- Training / fine-tuning
**When NOT to use:**
- You need a unified multi-provider LLM SDK (OpenAI, Anthropic, Google) -- use a provider-agnostic SDK
- You want to run models locally -- Replicate is a cloud-only serverless platform
- You need sub-second latency guarantees without deployments -- cold starts can take minutes
---
Examples Index
- [Core: Setup, Predictions & Files](examples/core.md) -- Client init, run(), predictions.create(), wait(), file I/O, error handling
- [Streaming & Webhooks](examples/streaming-webhooks.md) -- stream(), SSE events, webhook setup, signature validation
- [Deployments & Training](examples/deployments-training.md) -- Custom hardware, scaling, fine-tuning, model management
- [Quick API Reference](reference.md) -- Method signatures, constructor options, error types, model reference format
---
<philosophy>
Philosophy
Replicate provides **serverless GPU infrastructure** for running open-source ML models. You send inputs, Replicate allocates GPU hardware, runs the model, and returns outputs. No Docker, no CUDA drivers, no GPU provisioning.
**Core principles:**
1. **Serverless execution** -- Models run on-demand on Replicate's infrastructure. You pay only for compute time. Cold starts are a trade-off for not maintaining always-on GPUs. 2. **Model marketplace** -- Thousands of community and official models available at `replicate.com/explore`. Run any public model with just its identifier. 3. **Version pinning for reproducibility** -- Models are versioned with SHA-256 hashes. Pin to a version in production (`owner/model:abc123...`) to guarantee identical behavior across deploys. 4. **Three execution modes** -- `replicate.run()` for synchronous wait, `replicate.stream()` for real-time SSE output, `replicate.predictions.create()` for fire-and-forget with webhooks. 5. **File-first I/O** -- Many models accept and produce files (images, audio, video). The SDK handles file uploads automatically and returns `FileOutput` objects for file outputs.
</philosophy>
---
<patterns>
Core Patterns
Pattern 1: Client Setup
Initialize the Replicate client. It auto-reads `REPLICATE_API_TOKEN` from the environment.
// lib/replicate.ts -- basic setup
import Replicate from "replicate";
const replicate = new Replicate();
export { replicate };// lib/replicate.ts -- explicit auth + custom user agent
import Replicate from "replicate";
const replicate = new Replicate({
auth: process.env.REPLICATE_API_TOKEN, // Auto-reads from env if omitted
userAgent: "my-app/1.0.0",
});
export { replicate };**Why good:** Minimal setup, env var auto-detected, explicit auth optional but useful for clarity
// BAD: Hardcoded token
const replicate = new Replicate({
auth: "r8_abc123...",
});**Why bad:** Hardcoded API token is a security risk, will leak in version control
**See:** [examples/core.md](examples/core.md) for full constructor options, error handling patterns
---
Pattern 2: Runni
Showing the first part of this file.
The official skills marketplace for Agents Inc. 150+ skills covering everything from React and Prisma to Redis, ElevenLabs, and infrastructure tooling. Pick the skills that match your stack and install them via Claude Code. Need more control?
Repo: agents-inc/skills
Other skills on agents-inc-skills.
- /ai-infrastructure-huggingface-inference
Hugging Face Inference SDK patterns for TypeScript/Node.js — InferenceClient setup, chat completion, text generation, streaming, embeddings, image generation, audio transcription, translation, summarization, and Inference Endpoints
Open skill - /ai-infrastructure-litellm
LiteLLM proxy server setup, TypeScript client patterns via OpenAI SDK, model routing, fallbacks, load balancing, spend tracking, virtual keys, and production deployment
Open skill - /ai-infrastructure-modal
Serverless GPU compute platform for AI model deployment — web endpoints, GPU functions, model serving, and TypeScript client patterns
Open skill - /ai-infrastructure-ollama
Local LLM inference with the Ollama JavaScript client -- chat, streaming, tool calling, vision, embeddings, structured output, model management, and OpenAI-compatible endpoint
Open skill - /ai-infrastructure-together-ai
Together AI SDK patterns for TypeScript — client setup, chat completions, streaming, structured output, function calling, embeddings, image generation, fine-tuning, and OpenAI-compatible endpoints
Open skill - /ai-observability-langfuse
LLM observability with Langfuse — OpenTelemetry-based tracing, evaluations, prompt management, datasets, and production best practices
Open skill

