ai-image-gen
AI image generation with Replicate and fal.ai — text-to-image, image-to-image, inpainting with multiple model support. Use this skill when the user says "add image generation", "setup ai images", "add replicate", "text to image", or "ai image gen".
What this skill does
# AI Image Generation
Multi-provider AI image generation using [Replicate](https://replicate.com) and [fal.ai](https://fal.ai). Supports text-to-image, image-to-image, and inpainting across models like Flux, SDXL, and Ideogram. Generated images are stored permanently via the `storage` skill.
## Prerequisites
- Next.js app with App Router (with `src/` directory)
- `db` skill applied (Drizzle + Postgres)
- `env-config` skill applied
- `auth` skill applied
- `storage` skill applied (for permanent image storage)
## Installation
```bash
bun add replicate @fal-ai/client
```
## Environment Variables
Add to `.env.local`:
```env
# Image Generation Providers
REPLICATE_API_TOKEN=r8_...
FAL_KEY=fal_...
```
### Load from 1Password
If `REPLICATE_API_TOKEN` or `FAL_KEY` are empty or placeholders in `.env.local`, load them from 1Password:
```bash
# Load from 1Password (uses env-from-1password skill)
op item get "Dev Environment" --account=my.1password.com --fields label=notesPlain | tr -d '"' > /tmp/op-env.txt
grep -E "REPLICATE_API_TOKEN|FAL_KEY" /tmp/op-env.txt >> .env.local && rm /tmp/op-env.txt
```
Or use the `/env-from-1password` skill to load all keys at once — it writes `FAL_KEY`, `REPLICATE_API_TOKEN`, and other service keys to `.env.local`.
Add to `env.ts` server schema:
```typescript
REPLICATE_API_TOKEN: z.string().optional(),
FAL_KEY: z.string().optional(),
```
## What Gets Created
```
src/
├── app/
│ └── api/
│ └── ai/
│ └── images/
│ ├── route.ts # POST generate, GET list generations
│ └── [id]/
│ └── route.ts # GET generation status/result
├── lib/
│ ├── ai/
│ │ └── image-gen/
│ │ ├── types.ts # ImageGenRequest, ImageGenResult, ModelConfig
│ │ ├── models.ts # Model registry: name → provider + model ID + defaults
│ │ ├── providers/
│ │ │ ├── replicate.ts # Replicate API client
│ │ │ └── fal.ts # fal.ai client
│ │ └── generate.ts # Unified generate() — picks provider, submits, stores
│ └── db/
│ └── schema/
│ └── generations.ts # Drizzle schema: generations table
```
## Setup Steps
### Step 1: Create `src/lib/db/schema/generations.ts`
```typescript
import { pgTable, text, integer, timestamp, jsonb, uuid } from "drizzle-orm/pg-core";
export const generations = pgTable("generations", {
id: uuid("id").primaryKey().defaultRandom(),
userId: text("user_id").notNull(),
type: text("type", {
enum: ["text-to-image", "image-to-image", "inpainting"],
}).notNull(),
status: text("status", {
enum: ["pending", "processing", "completed", "failed"],
}).notNull().default("pending"),
provider: text("provider").notNull(),
model: text("model").notNull(),
prompt: text("prompt").notNull(),
negativePrompt: text("negative_prompt"),
width: integer("width").default(1024),
height: integer("height").default(1024),
seed: integer("seed"),
inputImageUrl: text("input_image_url"),
maskImageUrl: text("mask_image_url"),
resultUrl: text("result_url"),
providerJobId: text("provider_job_id"),
metadata: jsonb("metadata"),
error: text("error"),
createdAt: timestamp("created_at", { withTimezone: true }).defaultNow().notNull(),
completedAt: timestamp("completed_at", { withTimezone: true }),
});
export type Generation = typeof generations.$inferSelect;
export type NewGeneration = typeof generations.$inferInsert;
```
### Step 2: Add export to `src/lib/db/schema/index.ts`
```typescript
export * from "./generations";
```
### Step 3: Create `src/lib/ai/image-gen/types.ts`
```typescript
export type ImageProvider = "replicate" | "fal";
export type ImageGenRequest = {
prompt: string;
negativePrompt?: string;
model?: string;
width?: number;
height?: number;
seed?: number;
inputImageUrl?: string;
maskImageUrl?: string;
numOutputs?: number;
guidanceScale?: number;
};
export type ImageGenResult = {
url: string;
seed?: number;
width: number;
height: number;
provider: ImageProvider;
model: string;
providerJobId: string;
};
export type ModelConfig = {
provider: ImageProvider;
modelId: string;
name: string;
description: string;
defaults: {
width: number;
height: number;
guidanceScale: number;
};
capabilities: ("text-to-image" | "image-to-image" | "inpainting")[];
};
```
### Step 4: Create `src/lib/ai/image-gen/models.ts`
```typescript
import type { ModelConfig } from "./types";
export const IMAGE_MODELS: Record<string, ModelConfig> = {
"flux-schnell": {
provider: "replicate",
modelId: "black-forest-labs/flux-schnell",
name: "Flux Schnell",
description: "Fast generation, good quality",
defaults: { width: 1024, height: 1024, guidanceScale: 3.5 },
capabilities: ["text-to-image"],
},
"flux-dev": {
provider: "replicate",
modelId: "black-forest-labs/flux-dev",
name: "Flux Dev",
description: "High quality, slower",
defaults: { width: 1024, height: 1024, guidanceScale: 3.5 },
capabilities: ["text-to-image", "image-to-image"],
},
"flux-pro": {
provider: "fal",
modelId: "fal-ai/flux-pro/v1.1",
name: "Flux Pro",
description: "Best quality Flux model",
defaults: { width: 1024, height: 1024, guidanceScale: 3.5 },
capabilities: ["text-to-image", "image-to-image"],
},
"sdxl": {
provider: "replicate",
modelId: "stability-ai/sdxl:7762fd07cf82c948538e41f63f77d685e02b063e37e496e96eefd46c929f9bdc",
name: "Stable Diffusion XL",
description: "Versatile, supports inpainting",
defaults: { width: 1024, height: 1024, guidanceScale: 7.5 },
capabilities: ["text-to-image", "image-to-image", "inpainting"],
},
};
export const DEFAULT_MODEL = "flux-schnell";
export function getModelConfig(modelName?: string): ModelConfig {
const name = modelName ?? DEFAULT_MODEL;
const config = IMAGE_MODELS[name];
if (!config) {
throw new Error(`Unknown model: ${name}. Available: ${Object.keys(IMAGE_MODELS).join(", ")}`);
}
return config;
}
```
### Step 5: Create `src/lib/ai/image-gen/providers/replicate.ts`
```typescript
import Replicate from "replicate";
const replicate = new Replicate();
export async function generateWithReplicate(params: {
modelId: string;
prompt: string;
negativePrompt?: string;
width?: number;
height?: number;
seed?: number;
inputImageUrl?: string;
maskImageUrl?: string;
guidanceScale?: number;
numOutputs?: number;
}): Promise<{ urls: string[]; predictionId: string }> {
const input: Record<string, unknown> = {
prompt: params.prompt,
width: params.width ?? 1024,
height: params.height ?? 1024,
num_outputs: params.numOutputs ?? 1,
};
if (params.negativePrompt) input.negative_prompt = params.negativePrompt;
if (params.seed !== undefined) input.seed = params.seed;
if (params.guidanceScale !== undefined) input.guidance_scale = params.guidanceScale;
if (params.inputImageUrl) input.image = params.inputImageUrl;
if (params.maskImageUrl) input.mask = params.maskImageUrl;
const prediction = await replicate.predictions.create({
model: params.modelId as `${string}/${string}`,
input,
});
// Poll for completion
let result = prediction;
while (result.status !== "succeeded" && result.status !== "failed") {
await new Promise((resolve) => setTimeout(resolve, 1000));
result = await replicate.predictions.get(prediction.id);
}
if (result.status === "failed") {
throw new Error(`Replicate prediction failed: ${result.error}`);
}
const output = result.output;
const urls = Array.isArray(output) ? (output as string[]) : [String(output)];
return { urls, predictionId: prediction.id };
}
```
### Step 6: Create `src/lib/ai/image-gen/providers/fal.ts`
```typescript
import { fal } from "@fal-ai/client";
export async function generateWithFal(paramsRelated in Image & Video
watch
IncludedWatch a video (URL or local path). Downloads with yt-dlp, extracts auto-scaled frames with ffmpeg, pulls the transcript from captions (or Whisper API fallback), and hands the result to Claude so it can answer questions about what's in the video.
physical-ai-defect-image-generation
IncludedUse when the user wants to orchestrate defect image generation, run associated setup, or handle outputs on OSMO. The Day 0 path handles cold-start with USD-to-ROI, image-edit augmentation, and AnomalyGen to create initial PCBA datasets. The Day 1 path performs inference and labeling on real images. This skill helps with first-time asset setup, creation of finetuning checkpoints, and configuring deployment. Trigger keywords: defect image generation, dig workflow, dig pipeline, defect image detection workflow, aoi pipeline, aoi anomalygen, usd2roi anomalygen, day 0 pcba, day 1 pcba, day 1 real-photo alignment, day 1 manual roi, metal surface anomaly, glass defect, anomalygen finetune, setup_pcb, setup_metal, setup_glass, setup_pretrained, dig setup, dig datasets, dig pretrained checkpoint, dig image-edit endpoint.
accelint-react-best-practices
IncludedReact performance optimization and best practices. ALWAYS use this skill when working with any React code - writing components, hooks, JSX; refactoring; optimizing re-renders, memoization, state management; reviewing for performance; fixing hydration mismatches; debugging infinite re-renders, stale closures, input focus loss, animations restarting; preventing remounting; implementing transitions, lazy initialization, effect dependencies. Even simple React tasks benefit from these patterns. Covers React 19+ (useEffectEvent, Activity, ref props). Triggers - useEffect, useState, useMemo, useCallback, memo, inline components, nested components, components inside components, re-render, performance, hydration, SSR, Next.js, useDeferredValue, combined hooks.
elevenlabs-agents
IncludedBuild conversational AI voice agents with ElevenLabs Platform using React, JavaScript, React Native, or Swift SDKs. Configure agents, tools (client/server/MCP), RAG knowledge bases, multi-voice, and Scribe real-time STT. Use when: building voice chat interfaces, implementing AI phone agents with Twilio, configuring agent workflows or tools, adding RAG knowledge bases, testing with CLI "agents as code", or troubleshooting deprecated @11labs packages, Android audio cutoff, CSP violations, dynamic variables, or WebRTC config. Keywords: ElevenLabs Agents, ElevenLabs voice agents, AI voice agents, conversational AI, @elevenlabs/react, @elevenlabs/client, @elevenlabs/react-native, @elevenlabs/elevenlabs-js, @elevenlabs/agents-cli, elevenlabs SDK, voice AI, TTS, text-to-speech, ASR, speech recognition, turn-taking model, WebRTC voice, WebSocket voice, ElevenLabs conversation, agent system prompt, agent tools, agent knowledge base, RAG voice agents, multi-voice agents, pronunciation dictionary, voice speed control, elevenlabs scribe, @11labs deprecated, Android audio cutoff, CSP violation elevenlabs, dynamic variables elevenlabs, case-sensitive tool names, webhook authentication
humanizer
IncludedHumanize AI-generated text by detecting and removing patterns typical of LLM output. Rewrites text to sound natural, specific, and human. Uses 28 pattern detectors, 560+ AI vocabulary terms across 3 tiers, and statistical analysis (burstiness, type-token ratio, readability) for comprehensive detection. Use when asked to humanize text, de-AI writing, make content sound more natural/human, review writing for AI patterns, score text for AI detection, or improve AI-generated drafts. Covers content, language, style, communication, and filler categories.
generating-mermaid-diagrams
IncludedSalesforce architecture diagrams using Mermaid with ASCII fallback. Use this skill when generating text-based diagrams for Salesforce architecture, OAuth flows, ERDs, integration sequences, or Agentforce structure. TRIGGER when: user says "diagram", "visualize", "ERD", or asks for sequence diagrams, flowcharts, class diagrams, or architecture visualizations in Mermaid. DO NOT TRIGGER when: user wants PNG/SVG image output (use generating-visual-diagrams), or asks about non-Salesforce systems.