api-ai-replicate
Replicate SDK patterns for TypeScript/Node.js -- client setup, predictions, streaming, webhooks, file handling, model versioning, deployments, and training
npx skills add majiayu000/claude-skill-registry --skill api-ai-replicate --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Describes how to use the Replicate SDK for TypeScript/Node.js to interact with open-source ML models. It covers client setup, executing models synchronously with run(), streaming outputs with stream(), and asynchronous predictions with predictions.create() plus wait() or webhooks. It explains model references as owner/model (latest) or owner/model:version (pinned), and notes file outputs as FileOutput objects with inputs that can be files. It also mentions deployments for cold-start mitigation and training workflows.
How it works
The skill instructs concrete steps including:
- Initialize the Replicate client via code samples using or not using explicit auth, relying on the environment variable REPLICATE_API_TOKEN. It shows how to import Replicate and export the client instance.
- Run predictions synchronously with replicate.run(model, { input }) and handle outputs, where image models yield a FileOutput with .url() and .blob(), and text models yield a string.
- Stream outputs using replicate.stream(model, { input }) and iterate events, processing event.data when event.type is output.
- Use versioning by choosing model references as owner/model or owner/model:version to pin reproducible results.
- Handle file inputs and outputs, including FileOutput objects that must be treated as streams with .url() and .blob(), and support for uploading Buffers or ReadStreams as inputs.
- Use async predictions with replicate.predictions.create({ version, input, webhook, webhook_events_filter }) and then track prediction.id/status; process outputs when webhooks deliver results; validate webhooks with validateWebhook() and a secret.
- Deployments: create predictions on deployments to avoid cold starts and optionally wait for results, using replicate.deployments.predictions.create and replicate.wait.
- Error handling patterns noting automatic retries on 429 and 5xx with a default retry strategy, and status-code specific handling.
When to use it
- Running open-source ML models via Replicate without managing GPU infra
- Streaming real-time LLM output via SSE
- Processing asynchronous predictions with webhook notifications
- Deploying models with custom hardware for latency-sensitive apps
- Training/fine-tuning workflows
What it can touch
- The skill mentions using the Replicate SDK API surface: replicate.run(), replicate.stream(), replicate.predictions.create(), replicate.wait(), replicate.deployments.predictions.create(), and validateWebhook() from the replicate package. It references FileOutput objects for file I/O, including .url() and .blob() methods, and Buffers/ReadStreams for inputs. It relies on environment variables like REPLICATE_API_TOKEN for authentication.
Caveats
- Requires environment-based authentication via REPLICATE_API_TOKEN; token must not be hardcoded.
- Cold starts are possible for infrequently-used models; deployments with min_instances are recommended for latency-sensitive apps.
- Model references should be pinned in production to owner/model:version to ensure reproducible results.
- Webhook handling must validate signatures with validateWebhook(); outputs may arrive as FileOutput objects or other structured data.
- The skill describes serverless, cloud-based execution; local running is not supported.
# 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 MUS
- CRITICAL: Before Using This Skill
- Examples Index
- Philosophy
- Core Patterns
- Pattern 1: Client Setup
- Pattern 2: Running Predictions
- Pattern 3: Streaming
- Pattern 4: Model Versioning
- Pattern 5: File Handling
- Pattern 6: Async Predictions with Webhooks
- Pattern 7: Deployments
- Pattern 8: Error Handling
- Performance Optimization
- Cold Start Mitigation
What does the api-ai-replicate skill do?
Replicate SDK patterns for TypeScript/Node.js -- client setup, predictions, streaming, webhooks, file handling, model versioning, deployments, and training
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill api-ai-replicate --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
