# Stack0 > Application products for building, deploying, staffing, and understanding software. Includes the Pylon framework, Stack0 Build, Stack0 Cloud, Stack0 Agents, Stack0 Analytics, Stack0 SEO, Stack0 Feedback, Stack0 Studio, and managed Stack0 APIs. ## Machine-readable resources Every entry point an agent needs, at a stable URL. | Resource | URL | Format | | --- | --- | --- | | This file | https://www.stack0.dev/llms.txt | Markdown | | OpenAPI specification | https://www.stack0.dev/openapi.json | OpenAPI 3.1 (JSON) | | OpenAPI specification (API host) | https://api.stack0.dev/openapi.json | OpenAPI 3.1 (JSON) | | MCP endpoint (APIs) | https://api.stack0.dev/mcp | MCP, Streamable HTTP, API key | | MCP endpoint (products) | https://cloud.stack0.dev/mcp | MCP, Streamable HTTP, OAuth | | MCP server card | https://www.stack0.dev/.well-known/mcp.json | SEP-1649 (JSON) | | MCP manifest | https://www.stack0.dev/.well-known/mcp | SEP-1960 (JSON) | | MCP manifest (IETF) | https://www.stack0.dev/.well-known/mcp-server | draft-serra (JSON) | | Sitemap | https://www.stack0.dev/sitemap.xml | XML | | Documentation | https://www.stack0.dev/docs | HTML and Markdown | | MCP server guide | https://www.stack0.dev/docs/mcp | HTML and Markdown | | CLI guide | https://www.stack0.dev/docs/cli | HTML and Markdown | | Authentication | https://www.stack0.dev/docs/authentication | HTML and Markdown | | Rate limits | https://www.stack0.dev/docs/rate-limits | HTML and Markdown | | Versioning and deprecation | https://www.stack0.dev/docs/versioning | HTML and Markdown | | Error reference | https://www.stack0.dev/docs/errors | HTML and Markdown | | Webhooks | https://www.stack0.dev/docs/api-reference | HTML and Markdown | | Service status | https://www.stack0.dev/status | HTML and Markdown | | About | https://www.stack0.dev/about | HTML and Markdown | | Contact | https://www.stack0.dev/contact | HTML and Markdown | ### Markdown content negotiation Every page on www.stack0.dev serves a Markdown representation from the same URL. Send `Accept: text/markdown`, or append `.md` to any path. Responses carry `Content-Type: text/markdown; charset=utf-8` and `Vary: Accept`. ```bash curl -H "Accept: text/markdown" https://www.stack0.dev/docs/quickstart curl https://www.stack0.dev/docs/quickstart.md ``` ### Packages Published on npm: | Package | Install | What it is | | --- | --- | --- | | `@stack0/sdk` | `npm install @stack0/sdk` | TypeScript SDK for every product | | `@stack0/cli` | `npm install -g @stack0/cli` | Command-line tool, installs the `stack0` binary | | `@stack0/elements` | `npm install @stack0/elements` | React components for uploads, avatars, and galleries | The Python, Ruby, Go, and PHP SDKs are open source but are not yet on PyPI, RubyGems, pkg.go.dev, or Packagist. Install them from source: | Language | Repository | | --- | --- | | Python | https://github.com/stack0dev/sdk-python | | Ruby | https://github.com/stack0dev/sdk-ruby | | Go | https://github.com/stack0dev/sdk-go | | PHP | https://github.com/stack0dev/sdk-php | ## What is Stack0? Stack0 is one platform of six products for building, deploying, staffing, and understanding web applications. One account and one subscription ($20/month, including $10 of monthly usage credits) cover every product; usage beyond the credits is metered per service. Pylon is free and MIT licensed to self-host. Naming notes: Mast (mastagents.com) is now Stack0 Agents. Revtrail is now Stack0 Analytics. Pylon Cloud is now Stack0 Cloud. Apps deployed through Stack0 Cloud run at `.stack0.app`. ## Products | Product | Overview | Purpose | | --- | --- | --- | | Pylon | https://www.stack0.dev/products/pylon | Open-source realtime full-stack TypeScript framework with a Rust core. It includes a database, authentication, row-level policies, APIs, and live queries. | | Stack0 Build | https://www.stack0.dev/products/build | Application builder that turns a plain-language description into a normal Pylon project. You can edit, export, or deploy the source. | | Stack0 Cloud | https://www.stack0.dev/products/cloud | Managed hosting and operations for Pylon applications. Deployed apps run at `.stack0.app`. | | Stack0 Agents | https://www.stack0.dev/products/agents | A team of agents that works in Google (Gmail, Calendar, Drive, Sheets), runs routines on a schedule, and waits for approval past the limits you write. Runs at agents.stack0.dev. Formerly Mast (mastagents.com). | | Stack0 Analytics | https://www.stack0.dev/products/analytics | Product and revenue analytics with cookieless tracking by default. | | Stack0 SEO | https://www.stack0.dev/products/seo | Google Search Console reports with a label on every search, keyword volume and difficulty (DataForSEO, billed as usage at cost plus 50%), index tracking for sitemap pages, and a weekly site audit. Runs at seo.stack0.dev. MCP tools: seo_list_sites, seo_get_search_report, seo_get_index_report, seo_get_audit, seo_start_crawl. | | Stack0 Feedback | https://www.stack0.dev/products/feedback | Public feedback boards, voting, roadmaps, and changelogs. Runs at feedback.stack0.app. | | Stack0 Studio | https://www.stack0.dev/products/studio | Short videos for a brand, written from its website, photos, and footage, with a voiceover and music. Runs at studio.stack0.dev. Videos are bought in packs. | | Stack0 Launch | https://www.stack0.dev/launch | Done-for-you website service for small businesses. Stack0 rebuilds an existing website on Pylon, hosts it on Stack0 Cloud, and makes changes on request. $200/month including $25 of usage. Start at https://launch.stack0.dev/start; the customer pays after a price is sent. | | Stack0 APIs | https://www.stack0.dev/products/apis | Managed APIs for email, files, video, screenshots, extraction, workflows, and integrations. | API detail pages remain under `https://www.stack0.dev/apis/{product}`. ## Stack0 APIs Stack0 APIs provide managed infrastructure services for web applications: - **Email Service**: Send transactional and marketing emails with templates, tracking, and analytics - **CDN**: Asset storage and delivery with on-the-fly image transformations - **Integrations**: Unified API to connect your users' third-party apps (CRM, storage, communication, productivity) - **Webdata**: Screenshots, AI extraction, recursive **crawl**, URL **map**, PDF/DOCX **documents** parsing, **actions** (click/type/scroll), **stealth** mode - **Workflows**: Multi-step AI pipelines with sequential/parallel execution and variable passing - **Domain Management**: Custom domain verification and DNS management The $20/month subscription covers every product and includes $10 of monthly usage credits; usage beyond the credits is metered per service. ## Quick Start ### 1. Create an Account Sign up at https://app.stack0.dev and create your first organization. ### 2. Get Your API Key Navigate to Settings → API Keys in your dashboard and generate a new API key. ### 3. Install the SDK ```bash npm install @stack0/sdk # or bun add @stack0/sdk ``` ### 4. Install Elements (Optional) Pre-built React components for file uploads, avatars, and image galleries: ```bash # Install the package npm install @stack0/elements # Or with shadcn CLI (recommended) npx shadcn@latest add https://www.stack0.dev/r/file-upload npx shadcn@latest add https://www.stack0.dev/r/avatar-upload npx shadcn@latest add https://www.stack0.dev/r/logo-upload npx shadcn@latest add https://www.stack0.dev/r/image-gallery npx shadcn@latest add https://www.stack0.dev/r/image ``` ### 5. Send Your First Email ```typescript import { Stack0 } from '@stack0/sdk'; const stack0 = new Stack0({ apiKey: process.env.STACK0_API_KEY, }); await stack0.mail.send({ from: 'hello@yourdomain.com', to: 'user@example.com', subject: 'Welcome to our app!', html: '

Thanks for signing up!

', }); ``` ### 6. Upload Your First Asset ```typescript const asset = await stack0.cdn.upload({ projectSlug: 'my-project', file: imageBuffer, filename: 'hero.jpg', mimeType: 'image/jpeg', }); console.log(asset.cdnUrl); // https://cdn.stack0.dev/... ``` ### 7. Capture Your First Screenshot ```typescript const screenshot = await stack0.screenshots.captureAndWait({ url: 'https://example.com', format: 'png', fullPage: true, blockAds: true, }); console.log(screenshot.imageUrl); // https://cdn.stack0.dev/screenshots/... ``` ### 8. Extract Data with AI ```typescript const extraction = await stack0.extraction.extractAndWait({ url: 'https://example.com/product', mode: 'schema', schema: { type: 'object', properties: { title: { type: 'string' }, price: { type: 'number' }, }, }, }); console.log(extraction.extractedData); // { title: '...', price: 29.99 } ``` ### 9. Connect Your Users' Apps (Integrations) ```typescript // List contacts from any connected CRM (HubSpot, Salesforce, Pipedrive) const contacts = await stack0.integrations.crm.listContacts({ connectionId: 'conn_abc123', // User's connection ID }); // Upload a file to user's Google Drive, Dropbox, or OneDrive await stack0.integrations.storage.uploadFile({ connectionId: 'conn_def456', name: 'report.pdf', content: fileBuffer, folderId: 'folder_123', }); // Send a message to user's Slack channel await stack0.integrations.communication.sendMessage({ connectionId: 'conn_ghi789', channelId: 'C1234567890', text: 'Hello from your app!', }); ``` ### 10. Run an AI Workflow ```typescript // Run a multi-step AI pipeline const result = await stack0.workflows.runAndWait({ projectSlug: 'my-project', workflowId: 'content-pipeline', variables: { topic: 'AI in Healthcare', }, }); console.log(result.output); // Generated content from all steps ``` ## Elements - React Components `@stack0/elements` provides pre-built React components for common file handling patterns when working with Stack0 CDN. ### Installation ```bash # Using npm npm install @stack0/elements # Using pnpm pnpm add @stack0/elements # Using bun bun add @stack0/elements # Using shadcn CLI (recommended - copies components to your project) npx shadcn@latest add https://www.stack0.dev/r/file-upload npx shadcn@latest add https://www.stack0.dev/r/avatar-upload npx shadcn@latest add https://www.stack0.dev/r/logo-upload npx shadcn@latest add https://www.stack0.dev/r/image-gallery npx shadcn@latest add https://www.stack0.dev/r/image ``` Required peer dependencies: ```bash npm install class-variance-authority clsx tailwind-merge lucide-react ``` ### Available Components - **FileUpload**: Drag-and-drop file upload with progress tracking and multi-file support - **AvatarUpload**: Circular avatar upload with preview, fallback initials, and remove functionality - **LogoUpload**: Rectangular logo upload with multiple aspect ratios and SVG support - **ImageGallery**: Responsive image grid with lightbox, selection, and action support - **Image**: next/image wrapper optimized for Stack0 CDN with built-in transforms ### Upload Handler Pattern Elements use a handler pattern that works with any backend. Your server handles authentication and returns presigned URLs: ```typescript // Client-side usage import { FileUpload, createStack0Handler } from '@stack0/elements' const handler = createStack0Handler({ endpoint: '/api/upload', // Your API endpoint }) ``` ```typescript // Server-side API route (Next.js App Router) // app/api/upload/route.ts import { stack0 } from '@stack0/sdk' export async function POST(request: Request) { const { filename, mimeType, size, folder } = await request.json() const result = await stack0.cdn.createUpload({ filename, mimeType, size, folder, public: true, }) return Response.json({ uploadUrl: result.uploadUrl, assetId: result.assetId, }) } ``` ### Custom Upload Handler Create your own handler for any backend: ```typescript import { FileUpload, type UploadHandler } from '@stack0/elements' const customHandler: UploadHandler = { getUploadUrl: async (file) => { const response = await fetch('/api/upload', { method: 'POST', body: JSON.stringify({ filename: file.name, mimeType: file.type, size: file.size, }), }) const data = await response.json() return { uploadUrl: data.uploadUrl, assetId: data.assetId, } }, onUploadComplete: async (assetId, file) => { await fetch(`/api/upload/${assetId}/confirm`, { method: 'POST' }) return { url: `https://cdn.example.com/${assetId}` } }, onError: (error, file) => { console.error(`Upload failed for ${file.name}:`, error) }, } ``` ### Component Examples #### FileUpload ```tsx import { FileUpload, createStack0Handler } from '@stack0/elements' const handler = createStack0Handler({ endpoint: '/api/upload' }) console.log(files)} /> ``` #### AvatarUpload ```tsx import { AvatarUpload, createStack0Handler } from '@stack0/elements' const handler = createStack0Handler({ endpoint: '/api/upload', folder: '/avatars' }) updateUser({ avatarUrl: url })} fallback={user.initials} size="lg" /> ``` #### Image (CDN-optimized) ```tsx import { Image } from '@stack0/elements' Photo ``` ## CDN API Reference The CDN API enables you to upload, manage, and transform assets. All CDN operations are project-scoped using `projectSlug`. ### Upload File Upload files directly with the high-level `upload` method: ```typescript const asset = await stack0.cdn.upload({ projectSlug: 'my-project', file: fileBuffer, // Blob, Buffer, or ArrayBuffer filename: 'photo.jpg', mimeType: 'image/jpeg', folder: '/images/avatars', // Optional folder path metadata: { userId: 'user_123' }, // Optional custom metadata }); // Response { id: 'asset_abc123', filename: 'photo.jpg', originalFilename: 'photo.jpg', mimeType: 'image/jpeg', size: 102400, type: 'image', cdnUrl: 'https://cdn.stack0.dev/...', width: 1920, height: 1080, status: 'ready', folder: '/images/avatars', createdAt: Date } ``` Note: after upload, the file's bytes are verified against the declared `mimeType`. If they contradict it (e.g. a JPEG uploaded as `video/mp4`), the asset's `type` and `mimeType` are corrected automatically. Files declared as video or audio that cannot be decoded are marked `status: 'failed'`. ### Upload with Watermark Automatically apply a watermark to images during upload: ```typescript const asset = await stack0.cdn.upload({ projectSlug: 'my-project', file: photoBuffer, filename: 'branded-photo.jpg', mimeType: 'image/jpeg', watermark: { assetId: 'logo-asset-id', // Reference another CDN asset // Or use url: 'https://example.com/logo.png' for external images position: 'bottom-right', // 9 position options opacity: 50, // 0-100 sizingMode: 'relative', // 'relative' or 'absolute' width: 15, // 15% of image width (relative mode) offsetX: 20, // 20px from edge offsetY: 20, }, }); ``` #### Watermark Options - `assetId`: Reference to another CDN asset (your logo, etc.) - `url`: Direct URL to watermark image (alternative to assetId) - `position`: Placement on image - `top-left`, `top-center`, `top-right` - `center-left`, `center`, `center-right` - `bottom-left`, `bottom-center`, `bottom-right` - `offsetX`, `offsetY`: Pixel offset from position (default: 0) - `sizingMode`: How to interpret width/height - `absolute`: Width/height in exact pixels - `relative`: Width/height as percentage of main image (1-100) - `width`, `height`: Size of watermark (based on sizingMode) - `opacity`: Transparency 0-100 (default: 100 = fully opaque) - `rotation`: Rotation angle -360 to 360 degrees (default: 0) - `tile`: Repeat watermark across image (default: false) - `tileSpacing`: Spacing between tiles in pixels (default: 100) - `borderRadius`: Corner radius in pixels (default: 0) #### Manual Upload Flow For more control, use the presigned URL flow: ```typescript // 1. Get presigned upload URL const { uploadUrl, assetId, expiresAt } = await stack0.cdn.getUploadUrl({ projectSlug: 'my-project', filename: 'document.pdf', mimeType: 'application/pdf', size: 1048576, // File size in bytes folder: '/documents', }); // 2. Upload directly to S3 await fetch(uploadUrl, { method: 'PUT', body: file, headers: { 'Content-Type': 'application/pdf' }, }); // 3. Confirm upload completed const asset = await stack0.cdn.confirmUpload(assetId); ``` ### Upload from URL (Server-Side) Upload a file by providing a source URL. The server fetches and stores the file directly, so the client never downloads the bytes. Ideal for serverless environments with tight memory limits. ```typescript const asset = await stack0.cdn.uploadFromUrl({ projectSlug: 'my-project', sourceUrl: 'https://replicate.delivery/output/video.mp4', filename: 'video.mp4', mimeType: 'video/mp4', folder: '/ai-generated', metadata: { source: 'replicate' }, }); console.log(asset.cdnUrl); // https://cdn.stack0.dev/... ``` ### List Assets Query assets with filters and pagination: ```typescript const { assets, total, hasMore } = await stack0.cdn.list({ projectSlug: 'my-project', type: 'image', // 'image' | 'video' | 'audio' | 'document' | 'other' status: 'ready', // 'pending' | 'processing' | 'ready' | 'failed' folder: '/images', search: 'avatar', // Search in filename tags: ['profile', 'user'], sortBy: 'createdAt', // 'createdAt' | 'filename' | 'size' | 'type' sortOrder: 'desc', // 'asc' | 'desc' limit: 20, offset: 0, }); ``` ### Get Asset Retrieve a single asset by ID: ```typescript const asset = await stack0.cdn.get('asset_abc123'); console.log(asset.filename); console.log(asset.cdnUrl); console.log(asset.width, asset.height); // For images/videos console.log(asset.duration); // For videos/audio (seconds) ``` ### Update Asset Update asset metadata: ```typescript const asset = await stack0.cdn.update({ id: 'asset_abc123', filename: 'renamed-photo.jpg', folder: '/images/archived', tags: ['nature', 'sunset'], alt: 'A beautiful sunset over the ocean', metadata: { category: 'landscape' }, }); ``` ### Delete Assets ```typescript // Delete single asset await stack0.cdn.delete('asset_abc123'); // Delete multiple assets const { deletedCount } = await stack0.cdn.deleteMany([ 'asset_abc123', 'asset_def456', 'asset_ghi789', ]); ``` ### Move Assets Move assets to a different folder: ```typescript await stack0.cdn.move({ assetIds: ['asset_abc123', 'asset_def456'], folder: '/images/archive', // Use null for root folder }); ``` ### Image Transformations Generate optimized and transformed image URLs client-side (no API call required): ```typescript // Using asset's cdnUrl directly (recommended) const url = stack0.cdn.getTransformUrl(asset.cdnUrl, { width: 800, height: 600, fit: 'cover', // 'cover' | 'contain' | 'fill' | 'inside' | 'outside' format: 'webp', // 'webp' | 'jpeg' | 'png' | 'avif' | 'auto' quality: 80, // 1-100 }); // Or using s3Key when cdnUrl is configured in Stack0 options const stack0 = new Stack0({ apiKey: process.env.STACK0_API_KEY, cdnUrl: 'https://cdn.yourproject.stack0.dev', }); const url = stack0.cdn.getTransformUrl(asset.s3Key, { width: 400 }); // Use transformed URL // Optimized image ``` #### Transformation Options - `width`: Target width in pixels (snapped to optimal sizes for caching) - `height`: Target height in pixels - `fit`: How to fit the image - `cover`: Crop to fill dimensions (default) - `contain`: Fit within dimensions, preserving aspect ratio - `fill`: Stretch to fill dimensions - `inside`: Fit inside dimensions - `outside`: Cover dimensions while preserving aspect ratio - `format`: Output format (webp recommended for web, 'auto' for browser detection) - `quality`: Compression quality (1-100) - `crop`: Smart crop position ('attention', 'entropy', 'center', etc.) - `blur`: Blur sigma (0.3-100) - `sharpen`: Sharpen sigma - `brightness`: Brightness adjustment (-100 to 100) - `saturation`: Saturation adjustment (-100 to 100) - `grayscale`: Convert to grayscale (boolean) - `rotate`: Rotation angle (0, 90, 180, 270) - `flip`: Flip vertically (boolean) - `flop`: Flip horizontally (boolean) ### Folders Organize assets with virtual folders: ```typescript // Get folder tree const tree = await stack0.cdn.getFolderTree({ projectSlug: 'my-project', maxDepth: 3, }); // Tree structure [ { id: 'folder_123', name: 'images', path: '/images', assetCount: 42, children: [ { id: 'folder_456', name: 'avatars', path: '/images/avatars', assetCount: 15, children: [] } ] } ] // Create folder const folder = await stack0.cdn.createFolder({ projectSlug: 'my-project', name: 'avatars', parentId: 'folder_123', // Optional, null for root }); // Delete folder await stack0.cdn.deleteFolder('folder_123'); await stack0.cdn.deleteFolder('folder_123', true); // Delete with contents ``` ### Asset Types Assets are automatically categorized by MIME type: - `image`: jpeg, png, gif, webp, svg, etc. - `video`: mp4, webm, mov, avi, etc. - `audio`: mp3, wav, ogg, etc. - `document`: pdf, doc, docx, txt, etc. - `other`: All other file types ### Storage Usage Total everything stored under a project or folder in one call, including derived objects. Paging `list()` and summing `size` counts uploads only — an HLS ladder typically runs 1.5-3x its source, and a watermarked image is a second stored copy. This is the number to meter a plan limit against. ```typescript const usage = await stack0.cdn.getStorageUsage({ projectSlug: 'my-project', folder: '/customers/acme', // Optional: this folder and everything nested under it }); console.log(`${usage.totalFormatted} across ${usage.objectCount} objects`); console.log(` uploads: ${usage.breakdown.originals.bytesFormatted}`); console.log(` derived: ${usage.breakdown.derived.bytesFormatted}`); console.log(` video: ${usage.byType.video?.bytesFormatted}`); // A nonzero count means some derivatives have not been measured, so totalBytes is a floor. if (usage.unmeasuredAssets > 0) { console.warn(`${usage.unmeasuredAssets} assets not yet measured`); } ``` What counts toward the total: - Uploaded files (`breakdown.originals`) - Video renditions, HLS segments, and manifests - Video thumbnails and generated GIFs - Watermarked copies, which are stored as their own assets On-the-fly image transformations are not counted. They live in a separate cache that expires objects after 90 days rather than accumulating against your storage. ### Bandwidth Usage Serving stats for a period, org-wide, per project, or scoped to a folder. Bandwidth comes from CloudFront access logs, so it covers every viewer-delivered byte, cache hits included. Folder scoping matches `getStorageUsage`: when each of your tenants uploads under its own folder, one call meters that tenant's bandwidth for re-billing. ```typescript const usage = await stack0.cdn.getUsage({ projectSlug: 'my-project', folder: '/customers/acme', // Optional: this folder and everything nested under it periodStart: new Date('2026-08-01'), periodEnd: new Date(), }); console.log(`Bandwidth: ${usage.bandwidthFormatted} over ${usage.requests} requests`); ``` Folder-scoped stats read a per-asset grain that only covers assets that still exist — deleting an asset removes its serving history, so treat a shrinking period total as an asset deletion, not a usage drop. Zip bundles are counted once at build time against the assets they contain; repeat downloads of the same bundle are not counted. ## Video Streaming API Reference The Video Streaming API enables you to transcode videos into HLS adaptive streaming and MP4 formats for optimal playback across devices. Video-only inputs are supported; Stack0 omits audio selectors and audio outputs when the source has no audio stream. ### Transcode Video Start a transcoding job to convert video to HLS or MP4: ```typescript const job = await stack0.cdn.transcode({ projectSlug: 'my-project', assetId: 'video-asset-id', outputFormat: 'hls', // 'hls' for adaptive streaming, 'mp4' for progressive download variants: [ { quality: '720p', codec: 'h264' }, { quality: '1080p', codec: 'h264' }, ], webhookUrl: 'https://your-app.com/webhook', // Optional: get notified when complete }); // Response { id: 'job_abc123', assetId: 'asset_xyz', status: 'pending', outputFormat: 'hls', variants: [{ quality: '720p', codec: 'h264' }, { quality: '1080p', codec: 'h264' }], progress: 0, createdAt: Date } ``` #### Transcode Options - `assetId` (required): ID of the video asset to transcode - `outputFormat` (required): `hls` for adaptive streaming or `mp4` for progressive download - `variants` (required): Array of quality variants (1-10) - `quality`: `360p`, `480p`, `720p`, `1080p`, `1440p`, `2160p` - `codec`: `h264` (default) or `h265` - `bitrate`: Custom bitrate in kbps (optional) - `maxFramerate`: Maximum frame rate (optional) - `watermark`: Burn an image or text watermark into every rendition (optional). The original asset stays clean. - `type`: `image` (default) or `text` - `assetId` / `url`: Source logo for an image watermark (one is required) - `text`, `fontFamily`, `fontSize`, `fontColor`: Text watermark options (`text` required when `type` is `text`) - `position`: `top-left`, `top-center`, `top-right`, `center-left`, `center`, `center-right`, `bottom-left`, `bottom-center`, `bottom-right` (default `bottom-right`) - `offsetX`, `offsetY`: Inset from the anchored edge in pixels (default 20) - `sizingMode`: Image watermark sizing: `relative` (percent of video width) or `absolute` (default `relative`) - `scale`: Image watermark size as a percent of the video width (default 15) - `width`, `height`: Image watermark size in pixels (when `sizingMode` is `absolute`) - `opacity`: 0-100 (default 80) - `tile`: Repeat the watermark across the frame, e.g. for copyright protection (default false) - `tileSpacingX`, `tileSpacingY`: Spacing between tiles in pixels (default 100) - `rotation`: Degrees, -360 to 360 (default 0) - `borderRadius`: Clip the logo to rounded corners, 0-500 (image watermark only, default 0) - `trim`: Trim video (optional) - `start`: Start time in seconds - `end`: End time in seconds - `webhookUrl`: URL to receive completion notification ### Get Transcoding Job Status ```typescript const job = await stack0.cdn.getJob('job_abc123'); console.log(`Status: ${job.status}`); console.log(`Progress: ${job.progress}%`); if (job.status === 'failed') console.error(job.errorMessage); // Status values: 'pending' | 'queued' | 'processing' | 'completed' | 'failed' | 'cancelled' ``` #### Storage written by the job Completed jobs report the bytes they actually wrote, measured from storage rather than estimated from bitrate: ```typescript const job = await stack0.cdn.getJob('job_abc123'); // Renditions, HLS segments and manifests together — you are billed for every object. console.log(`Total output: ${job.totalOutputBytes} bytes`); for (const variant of job.variants) { console.log(`${variant.quality}: ${variant.sizeBytes} bytes`); } ``` `totalOutputBytes` and `variant.sizeBytes` are `null`/`undefined` until the job completes, and stay unset if the measurement failed. Unset means unmeasured, never zero. ### List Transcoding Jobs ```typescript const { jobs, total, hasMore } = await stack0.cdn.listJobs({ projectSlug: 'my-project', assetId: 'video-asset-id', // Optional: filter by asset status: 'processing', // Optional: filter by status limit: 20, offset: 0, }); ``` ### Cancel Transcoding Job ```typescript await stack0.cdn.cancelJob('job_abc123'); ``` ### Get Streaming URLs After transcoding completes, get URLs for playback: ```typescript const urls = await stack0.cdn.getStreamingUrls('asset-id'); // HLS adaptive streaming (recommended for web/mobile) console.log(`HLS Master Playlist: ${urls.hlsUrl}`); // MP4 direct download URLs by quality for (const mp4 of urls.mp4Urls) { console.log(`${mp4.quality}: ${mp4.url}`); } // Generated thumbnails for (const thumb of urls.thumbnails) { console.log(`Thumbnail at ${thumb.timestamp}s: ${thumb.url}`); } ``` ### Generate Thumbnails Extract thumbnail images from video at specific timestamps. Works for any ready video asset, including plain uploads — `GET /cdn/video/thumbnail/{assetId}` returns the frame if it exists and otherwise queues generation and returns `status: "pending"` (poll until `"ready"`). Uploaded videos also get automatic thumbnails at 0s, 5s, and the last frame during ingest. ```typescript // Blocking helper: generates on miss and polls until ready const thumbnail = await stack0.cdn.getThumbnailAndWait({ assetId: 'video-asset-id', timestamp: 10.5, // 10.5 seconds into the video width: 320, // Optional: resize width format: 'webp', // 'jpg', 'png', 'webp' }); console.log(`Thumbnail URL: ${thumbnail.url}`); // Non-blocking: returns { status: 'pending', url: null } while generating const maybe = await stack0.cdn.getThumbnail({ assetId: 'video-asset-id', timestamp: 0 }); // Force a fresh capture, then wait for it await stack0.cdn.regenerateThumbnail({ assetId: 'video-asset-id', timestamp: 5 }); const fresh = await stack0.cdn.getThumbnailAndWait({ assetId: 'video-asset-id', timestamp: 5 }); ``` ### Extract Audio Extract audio track from video as MP3, AAC, or WAV: ```typescript const { jobId, status } = await stack0.cdn.extractAudio({ projectSlug: 'my-project', assetId: 'video-asset-id', format: 'mp3', // 'mp3', 'aac', 'wav' bitrate: 192, // Optional: kbps }); ``` ### Generate GIF Create an animated GIF from a video segment: ```typescript const gif = await stack0.cdn.generateGif({ projectSlug: 'my-project', assetId: 'video-asset-id', startTime: 5, // Start at 5 seconds into the video duration: 3, // 3 second GIF (max 30 seconds) width: 480, // Output width in pixels (100-800) fps: 10, // Frames per second (5-30) optimizePalette: true, // Two-pass palette optimization for smaller file size }); // Response { id: 'gif_abc123', assetId: 'asset_xyz', startTime: 5, duration: 3, fps: 10, url: null, // null until completed status: 'pending', createdAt: Date } ``` #### GIF Generation Options - `assetId` (required): ID of the video asset - `startTime`: Start position in seconds (default: 0) - `duration`: Duration in seconds, 0.5-30 (default: 5) - `width`: Output width 100-800px (default: 480, height auto-calculated) - `fps`: Frames per second 5-30 (default: 10, lower = smaller file) - `optimizePalette`: Use two-pass palette generation for better quality and smaller file size (default: true) #### Get GIF Status ```typescript const gif = await stack0.cdn.getGif('gif_abc123'); if (gif?.status === 'completed') { console.log(`GIF URL: ${gif.url}`); console.log(`Size: ${gif.sizeBytes} bytes`); console.log(`Frames: ${gif.frameCount}`); } // Status values: 'pending' | 'processing' | 'completed' | 'failed' ``` #### List GIFs for a Video ```typescript const gifs = await stack0.cdn.listGifs({ assetId: 'video-asset-id' }); for (const gif of gifs) { console.log(`${gif.startTime}s-${gif.startTime + gif.duration}s: ${gif.url}`); } ``` #### GIF Best Practices - **Duration**: Keep GIFs under 10 seconds for reasonable file sizes - **Width**: 480px is a good balance of quality and file size - **FPS**: 10 fps is sufficient for most use cases; use 15-20 for smoother motion - **File Size**: A 5-second 480px GIF at 10fps is typically 1-5MB depending on content ### Video Player Integration Use HLS.js for cross-browser HLS playback: ```typescript import Hls from 'hls.js'; const urls = await stack0.cdn.getStreamingUrls('asset-id'); const video = document.getElementById('video') as HTMLVideoElement; if (Hls.isSupported() && urls.hlsUrl) { const hls = new Hls(); hls.loadSource(urls.hlsUrl); hls.attachMedia(video); } else if (video.canPlayType('application/vnd.apple.mpegurl')) { // Safari native HLS support video.src = urls.hlsUrl!; } ``` ### Video Transcoding Status Flow 1. **pending**: Job created, waiting to be queued 2. **queued**: Job queued for processing 3. **processing**: Video being transcoded 4. **completed**: Transcoding finished, streaming URLs available 5. **failed**: Transcoding failed (check `errorMessage`) 6. **cancelled**: Job was cancelled ## Video Merge API Reference The Video Merge API enables you to combine multiple videos and images into a single video with optional audio overlay. Perfect for creating slideshows, video compilations, or adding background music. Input content is verified before processing: a video input whose bytes are actually a still image or audio-only file fails the job with a descriptive error (instead of silently producing a broken clip), and the audio track must contain an audio stream. Asset types are determined at upload from the file's actual bytes, so image assets always honor `duration` in merges. Audio assets cannot appear in the `inputs` sequence — pass them as `audioTrack` to overlay them on the merged video. ### Create Merge Job Combine multiple assets (videos, images) into a single video: ```typescript const job = await stack0.cdn.createMergeJob({ projectSlug: 'my-project', inputs: [ { assetId: 'intro-video-id' }, // Full video { assetId: 'image-id', duration: 5 }, // Image for 5 seconds { assetId: 'main-video-id', startTime: 10, endTime: 60 }, // Trimmed video ], audioTrack: { assetId: 'background-music-id', loop: true, // Loop if audio is shorter than video fadeIn: 2, // 2 second fade in fadeOut: 3, // 3 second fade out }, output: { format: 'mp4', // 'mp4' or 'webm' quality: '1080p', // '360p', '480p', '720p', '1080p', '1440p', '2160p' aspectRatio: 'auto', // 'auto' (default), '16:9', '9:16', '1:1' filename: 'final-video.mp4', }, webhookUrl: 'https://your-app.com/webhook', }); // Response { id: 'merge_abc123', status: 'pending', progress: 0, outputFormat: 'mp4', outputQuality: '1080p', createdAt: Date } ``` #### Merge Input Options Each input item in the `inputs` array supports: - `assetId` (required): UUID of the video or image asset - `duration`: Display duration in seconds (required for images, max 3600) - `startTime`: Trim start point in seconds (videos only) - `endTime`: Trim end point in seconds (videos only) - `textOverlay`: Text caption configuration (see below) - `composite`: Composite this input into a region of a background asset (see below) #### Composite Options (overlay a clip into a region of a background) Place the input clip (the overlay — e.g. an app screen recording) into a defined region of a background asset (e.g. a shot of someone holding a phone). The chroma-keyed or masked background is layered on top of the placed overlay, so the overlay shows through only in the keyed region and real foreground (fingers, hands) occludes it. The composited segment then flows through the normal merge sequence, so it can be concatenated with other clips in the same job. - `backgroundAssetId` (required): UUID of the background image or video - `quad`: Perspective corner-pin destination — where the overlay's corners land, in background pixels: `{ topLeft: {x,y}, topRight: {x,y}, bottomLeft: {x,y}, bottomRight: {x,y} }`. Requires `chromaKey` or `maskAssetId`. - `rect`: Axis-aligned destination `{ x, y, width, height }` in background pixels. Without a key/mask this is a simple picture-in-picture (overlay drawn on top). - `fit`: How the overlay fills the destination region's aspect ratio — `cover` (default, center-crop), `contain` (letterbox), `fill` (stretch) - `chromaKey`: `{ color: "#F500FA", similarity: 0.34, blend: 0.06 }` — the keyed color in the background becomes transparent (similarity 0.01-1, default 0.3; blend 0-1, default 0.1) - `maskAssetId`: Grayscale mask image asset as an alternative to chroma key — white keeps the background, black reveals the overlay Provide exactly one of `quad` or `rect`, and at most one of `chromaKey` or `maskAssetId`. The input's `startTime`/`endTime` (videos) or `duration` (images) governs the composited segment length; the overlay's audio is kept (falling back to a video background's audio, else silence). Output resolution matches the background. #### Text Overlay Options Add text captions/overlays to images and videos, perfect for TikTok/Instagram style content: - `text` (required): The text to display (1-500 characters) - `position`: Vertical position - `top`, `center`, `bottom` (default: `bottom`) - `fontSize`: Font size in pixels (12-200, default: 48) - `fontFamily`: Font family (default: `Liberation Sans`) - `fontWeight`: `normal` or `bold` (default: `bold`) - `color`: Text color in hex format (default: `#FFFFFF`) - `backgroundColor`: Background color (e.g., `rgba(0,0,0,0.5)`) - `padding`: Padding from edges in pixels (0-100, default: 20) - `maxWidth`: Maximum width as percentage of video width (10-100, default: 90) - `shadow`: Shadow configuration - `color`: Shadow color in hex (default: `#000000`) - `offsetX`: Horizontal offset (0-20, default: 2) - `offsetY`: Vertical offset (0-20, default: 2) - `stroke`: Stroke/outline configuration - `color`: Stroke color in hex (default: `#000000`) - `width`: Stroke width in pixels (1-10, default: 2) #### Audio Track Options - `assetId` (required): UUID of the audio file - `loop`: Loop audio if shorter than video (default: false) - `fadeIn`: Fade in duration (0-10 seconds) - `fadeOut`: Fade out duration (0-10 seconds) #### Output Options - `format`: Output format - `mp4` (default) or `webm` - `quality`: Quality preset - `360p`, `480p`, `720p` (default), `1080p`, `1440p`, `2160p` - `aspectRatio`: Output canvas orientation - `auto` (default), `16:9`, `9:16`, `1:1`. With `auto`, the output matches the orientation of the first visual input: portrait inputs produce portrait output (e.g. 1080x1920 at `1080p`), so vertical Reels/TikTok content posts full-frame with no letterboxing. Explicit values force the canvas; quality sets the short edge (`1080p` + `9:16` = 1080x1920, `1080p` + `1:1` = 1080x1080). Mixed-orientation inputs are fitted to the canvas and padded. - `filename`: Custom filename for the output (max 255 chars) ### Get Merge Job Status ```typescript const job = await stack0.cdn.getMergeJob('merge_abc123'); console.log(`Status: ${job.status}`); console.log(`Progress: ${job.progress}%`); if (job.status === 'completed' && job.outputAsset) { console.log(`Output video: ${job.outputAsset.cdnUrl}`); console.log(`Duration: ${job.outputAsset.duration}s`); console.log(`Size: ${job.outputAsset.size} bytes`); } // Status values: 'pending' | 'queued' | 'processing' | 'completed' | 'failed' | 'cancelled' ``` ### List Merge Jobs ```typescript const { jobs, total, hasMore } = await stack0.cdn.listMergeJobs({ projectSlug: 'my-project', status: 'completed', // Optional: filter by status limit: 20, offset: 0, }); ``` ### Cancel Merge Job ```typescript await stack0.cdn.cancelMergeJob('merge_abc123'); ``` ### Merge Job Status Flow 1. **pending**: Job created, waiting to be queued 2. **queued**: Job queued for processing 3. **processing**: Video being merged 4. **completed**: Merge finished, output asset available 5. **failed**: Merge failed (check `errorMessage`) 6. **cancelled**: Job was cancelled ### Use Cases #### Composite an App Recording onto a Held Phone ("POV holding my phone") ```typescript const job = await stack0.cdn.createMergeJob({ projectSlug: 'my-project', inputs: [ { assetId: 'reaction-clip' }, { assetId: 'app-screen-recording', // the overlay composite: { backgroundAssetId: 'holding-phone-shot', // image or video, screen painted #F500FA quad: { topLeft: { x: 320, y: 480 }, topRight: { x: 760, y: 500 }, bottomLeft: { x: 300, y: 1400 }, bottomRight: { x: 740, y: 1440 }, }, fit: 'cover', chromaKey: { color: '#F500FA', similarity: 0.34, blend: 0.06 }, }, }, ], output: { quality: '1080p', aspectRatio: '9:16' }, }); ``` #### Photo Slideshow with Music ```typescript const job = await stack0.cdn.createMergeJob({ projectSlug: 'my-project', inputs: [ { assetId: 'photo-1', duration: 3 }, { assetId: 'photo-2', duration: 3 }, { assetId: 'photo-3', duration: 3 }, ], audioTrack: { assetId: 'background-music', fadeIn: 1, fadeOut: 2, }, output: { format: 'mp4', quality: '1080p', }, }); ``` #### TikTok/Instagram Style Video with Text Captions ```typescript const job = await stack0.cdn.createMergeJob({ projectSlug: 'my-project', inputs: [ { assetId: 'intro-image', duration: 3, textOverlay: { text: 'Welcome to my story!', position: 'bottom', fontSize: 64, fontWeight: 'bold', color: '#FFFFFF', stroke: { color: '#000000', width: 2 }, shadow: { color: '#000000', offsetX: 2, offsetY: 2 }, }, }, { assetId: 'main-content-video', startTime: 0, endTime: 15, textOverlay: { text: 'This is the main part', position: 'bottom', fontSize: 48, color: '#FFFFFF', backgroundColor: 'rgba(0,0,0,0.5)', padding: 20, }, }, { assetId: 'outro-image', duration: 3, textOverlay: { text: 'Follow for more!', position: 'center', fontSize: 72, fontWeight: 'bold', color: '#FFD700', stroke: { color: '#000000', width: 3 }, }, }, ], audioTrack: { assetId: 'trending-sound', loop: true, fadeOut: 2, }, output: { format: 'mp4', quality: '1080p', }, }); ``` #### Video Compilation with Trimming ```typescript const job = await stack0.cdn.createMergeJob({ projectSlug: 'my-project', inputs: [ { assetId: 'intro-video' }, { assetId: 'main-footage', startTime: 30, endTime: 90 }, // 60 second clip { assetId: 'title-card-image', duration: 5 }, { assetId: 'outro-video', endTime: 10 }, // First 10 seconds only ], output: { format: 'mp4', quality: '1080p', filename: 'highlight-reel.mp4', }, }); ``` ### Merge Limits - Maximum inputs per job: 100 - Maximum image duration: 3600 seconds (1 hour) - Maximum fade duration: 10 seconds ## Video Render API Reference The Video Render API turns a declarative video spec into a finished video. Use it when the video needs real layout and animation — a chat thread, an app demo, a stat block, an animated before/after — rather than the cut-and-composite operations the Merge API covers. You do not write compositions and you do not upload code. The spec is data: scenes, layers, timing and media. Stack0 owns the renderer. That makes the spec a natural thing for an LLM to generate and for an agent to iterate on against a reference video. `@stack0/video-spec` ships the schema, the timing engine and worked examples. Validate locally before you POST and a round trip becomes a type error. ### The shape A spec is a canvas, a list of scenes played back to back, and audio that spans the whole thing. A scene is a stack of layers. ```typescript { canvas: { width: 1080, height: 1920, fps: 30, background: '#000000' }, // all optional audio: [{ src, volume, fadeIn, fadeOut, loop }], scenes: [ { id, duration, background, layers: [ ... ] } ] } ``` ### Layers | Type | What it is | Owns its own length? | | --- | --- | --- | | `image` | Full-bleed image, with an optional `zoom` push-in | no | | `video` | Video, with `trimStart`, `muted`, `volume` | no | | `solid` | Flat colour fill | no | | `caption` | Burned-in text with stroke and shadow | no | | `appMockup` | A phone showing an app: photo loaded, prompt typed, send tapped | yes | | `messageThread` | An iMessage-style thread with typing, compose and delivery | yes | Every layer takes `start` and `duration` in seconds, relative to its scene. A scene's `duration` is optional. Omit it and the scene runs as long as its longest self-timing layer needs. A scene with neither is an error that names the scene. ### Message thread timing `messageThread` paces itself, and that is the point. Each message holds for as long as it takes to read; a reply is preceded by a typing bubble; a sent message is preceded by watching it get typed character by character; the last message holds far longer because it is the payoff. Messages marked `history: true` are on screen from the first frame and cost no time. Override a single message with `hold` (seconds), or the whole block with the scene's `duration`. A message whose text is exactly `[IMAGE]` renders the thread's `imageSrc` instead of a bubble. ### Create Render Job ```typescript const job = await stack0.cdn.createRenderJob({ projectSlug: 'my-project', spec: { scenes: [ { id: 'hook', duration: 2.5, layers: [ { type: 'image', src: afterImageAssetId, zoom: { from: 1, to: 1.06 } }, { type: 'caption', text: 'i told my mom\nthe kitchen exploded', position: 'upperThird' }, ], }, { id: 'demo', duration: 4, background: '#F4F4F6', layers: [ { type: 'appMockup', photo: beforeImageAssetId, prompt: 'make the kitchen look destroyed' }, ], }, { id: 'payoff', layers: [ { type: 'messageThread', recipient: 'Mom', imageSrc: afterImageAssetId, messages: [ { sender: 'recipient', text: 'you home?', history: true }, { sender: 'user', text: '[IMAGE]' }, { sender: 'recipient', text: 'WHAT IS THAT' }, ], }, ], }, ], }, output: { format: 'mp4' }, webhookUrl: 'https://your-app.com/webhook', }); // Known before a single frame renders console.log(job.width, job.height, job.fps, job.durationInFrames); ``` ### Media Every `src`, `photo` and `imageSrc` is either a Stack0 asset id or an absolute `https://` URL on an allowed CDN host. Nothing else is accepted. The renderer is a browser, so any URL in a spec is a URL it will request from inside Stack0's network. Restricting it to assets you own is what stops a spec being used to reach addresses it should not. The cost is that third-party media has to be uploaded first. ### Output Options | Field | Values | Default | Notes | | --- | --- | --- | --- | | `format` | `mp4`, `webm` | `mp4` | mp4 muxes h264, webm muxes vp8 | | `scale` | 0.1 - 4 | 1 | Multiplies the canvas. Cost scales with the square of this. | | `filename` | string | `render-{jobId}.{format}` | | There is no quality or aspect ratio option: the spec's canvas declares width, height and fps. ### Get, List and Cancel ```typescript const job = await stack0.cdn.getRenderJob('job_abc123'); if (job.status === 'completed' && job.outputAsset) { console.log(job.outputAsset.cdnUrl); } const { jobs, total, hasMore } = await stack0.cdn.listRenderJobs({ projectSlug: 'my-project', status: 'processing', }); await stack0.cdn.cancelRenderJob('job_abc123'); ``` Cancelling stops a render that is already running, not just a queued one. ### Render Job Status Flow 1. **pending**: Spec validated, job queued 2. **processing**: Rendering 3. **completed**: Output asset available 4. **failed**: Render failed (check `errorMessage`) 5. **cancelled**: Cancelled before or during the render ### Render Endpoints - `POST /cdn/video/render` — create a render job from a spec - `GET /cdn/video/render` — list render jobs - `GET /cdn/video/render/{jobId}` — get a render job - `POST /cdn/video/render/{jobId}/cancel` — cancel a render job ### Render Limits - Maximum 60 scenes, 24 layers per scene, 80 messages per thread, 4 audio tracks - Maximum canvas 3840x3840, maximum 60 fps - Maximum 600 seconds per render ### Validation errors A spec is validated before anything is queued, and every problem is reported at once with the path to the field, so a generated spec can be fixed in one pass: ``` Video spec has 2 problems: scenes.1.duration: This scene has no duration and no layer that provides one. Set "duration" in seconds, or add a messageThread or appMockup layer, which derive their own length. scenes.0.layers.0.src: Media reference points at "example.com", which is not an allowed media host (cdn.stack0.dev). Upload the file to Stack0 and reference the asset id you get back. ``` ### Asset Status Flow 1. **pending**: Upload URL generated, waiting for upload 2. **processing**: File uploaded, being processed (thumbnails, metadata extraction) 3. **ready**: Asset ready for use 4. **failed**: Processing failed ### CDN URL Structure Assets are served from the CDN with the following URL patterns: - Original: `https://cdn.stack0.dev/{s3Key}` - Transformed: `https://cdn.stack0.dev/{s3Key}?w=800&h=600&fit=cover&f=webp&q=80` ### Private Files Private files are stored in a separate secure bucket with no public CDN access. They can only be accessed through presigned download URLs with configurable expiration times (1 hour to 7 days). #### Upload Private File ```typescript // High-level upload (handles presigned URL flow) const file = await stack0.cdn.uploadPrivate({ projectSlug: 'my-project', file: fileBuffer, // Blob, Buffer, or ArrayBuffer filename: 'confidential.pdf', mimeType: 'application/pdf', folder: '/contracts', description: 'Q4 Sales Contract', metadata: { clientId: 'client_123' }, }); // Response { id: 'file_abc123', filename: 'confidential.pdf', mimeType: 'application/pdf', size: 102400, status: 'ready', folder: '/contracts', createdAt: Date } ``` #### Manual Upload Flow ```typescript // 1. Get presigned upload URL const { uploadUrl, fileId, expiresAt } = await stack0.cdn.getPrivateUploadUrl({ projectSlug: 'my-project', filename: 'report.xlsx', mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', size: 204800, }); // 2. Upload directly to S3 await fetch(uploadUrl, { method: 'PUT', body: file, headers: { 'Content-Type': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }, }); // 3. Confirm upload completed const privateFile = await stack0.cdn.confirmPrivateUpload(fileId); ``` #### Generate Download URL Create a temporary presigned download URL: ```typescript const { downloadUrl, expiresAt } = await stack0.cdn.getPrivateDownloadUrl({ fileId: 'file_abc123', expiresIn: 86400, // 24 hours (1hr to 7 days supported) }); // Use the URL for secure downloads // URL is valid only until expiresAt ``` #### List Private Files ```typescript const { files, total, hasMore } = await stack0.cdn.listPrivateFiles({ projectSlug: 'my-project', folder: '/contracts', status: 'ready', search: 'contract', sortBy: 'createdAt', sortOrder: 'desc', limit: 20, offset: 0, }); ``` #### Update Private File ```typescript const file = await stack0.cdn.updatePrivateFile({ fileId: 'file_abc123', description: 'Updated description', folder: '/contracts/archived', tags: ['contract', '2024'], }); ``` #### Delete Private Files ```typescript // Single file await stack0.cdn.deletePrivateFile('file_abc123'); // Multiple files const { deletedCount } = await stack0.cdn.deletePrivateFiles([ 'file_abc123', 'file_def456', ]); ``` ### Download Bundles Download bundles allow you to create zip archives containing multiple public assets and/or private files. Bundles are created asynchronously via background jobs. #### Create Bundle ```typescript const { bundle } = await stack0.cdn.createBundle({ projectSlug: 'my-project', name: 'Project Assets - Dec 2024', description: 'All project media files', assetIds: ['asset_1', 'asset_2'], // Public CDN assets privateFileIds: ['file_1', 'file_2'], // Private files expiresIn: 86400, // Bundle expires in 24 hours }); // Response { id: 'bundle_abc123', name: 'Project Assets - Dec 2024', status: 'pending', // 'pending' | 'processing' | 'ready' | 'failed' | 'expired' createdAt: Date } ``` #### Check Bundle Status ```typescript const bundle = await stack0.cdn.getBundle('bundle_abc123'); if (bundle.status === 'ready') { console.log(`Bundle ready: ${bundle.fileCount} files, ${bundle.size} bytes`); } ``` #### Download Bundle ```typescript const { downloadUrl, expiresAt } = await stack0.cdn.getBundleDownloadUrl({ bundleId: 'bundle_abc123', expiresIn: 3600, // 1 hour }); // Download the zip file window.location.href = downloadUrl; // or const response = await fetch(downloadUrl); ``` #### List Bundles ```typescript const { bundles, total, hasMore } = await stack0.cdn.listBundles({ projectSlug: 'my-project', status: 'ready', search: 'Dec 2024', limit: 20, }); ``` #### Delete Bundle ```typescript await stack0.cdn.deleteBundle('bundle_abc123'); ``` ### Bundle Status Flow 1. **pending**: Bundle created, job queued 2. **processing**: Background worker creating zip archive 3. **ready**: Bundle ready for download 4. **failed**: Bundle creation failed (check error) 5. **expired**: Bundle download link expired ## Mail API Reference The Mail SDK provides a complete email platform including transactional emails, templates, audiences, contacts, campaigns, automated sequences, and event tracking. ### Core Email Operations #### Send Email ```typescript const result = await stack0.mail.send({ from: 'noreply@yourdomain.com', to: 'user@example.com', subject: 'Hello World', html: '

Email content here

', text: 'Email content here', // Optional plaintext }); // With display name const result = await stack0.mail.send({ from: { email: 'noreply@yourdomain.com', name: 'My App' }, to: { email: 'user@example.com', name: 'User' }, subject: 'Hello World', html: '

Email content here

', }); // With threading (for replies) const result = await stack0.mail.send({ from: 'support@yourdomain.com', to: 'user@example.com', subject: 'Re: Your question', html: '

Here is my reply...

', inReplyTo: '', references: '', }); ``` #### Send Batch (up to 100 emails) ```typescript await stack0.mail.sendBatch({ emails: [ { from: 'noreply@example.com', to: 'user1@example.com', subject: 'Hello', html: '

Hi User 1

' }, { from: 'noreply@example.com', to: 'user2@example.com', subject: 'Hello', html: '

Hi User 2

' }, ] }); ``` #### Send Broadcast (same content, up to 1000 recipients) ```typescript await stack0.mail.sendBroadcast({ from: 'newsletter@yourdomain.com', to: ['user1@example.com', 'user2@example.com'], subject: 'Newsletter', html: '

Content

', }); ``` #### Get, List, Resend, Cancel ```typescript const email = await stack0.mail.get('email_id'); const { emails } = await stack0.mail.list({ status: 'delivered', limit: 50 }); await stack0.mail.resend('email_id'); await stack0.mail.cancel('email_id'); // For scheduled emails ``` #### Analytics ```typescript const analytics = await stack0.mail.getAnalytics(); const timeSeries = await stack0.mail.getTimeSeriesAnalytics({ days: 30 }); const hourly = await stack0.mail.getHourlyAnalytics(); const { senders } = await stack0.mail.listSenders(); ``` ### Domains (stack0.mail.domains) Manage sending domains with DNS verification. ```typescript // List domains const domains = await stack0.mail.domains.list({ projectSlug: 'my-project' }); // Add and verify domain const { dnsRecords } = await stack0.mail.domains.add({ domain: 'yourdomain.com' }); const records = await stack0.mail.domains.getDnsRecords('domain_id'); const { verified } = await stack0.mail.domains.verify('domain_id'); // Set default and delete await stack0.mail.domains.setDefault('domain_id'); await stack0.mail.domains.delete('domain_id'); ``` ### Templates (stack0.mail.templates) Create and manage reusable email templates with variable substitution. ```typescript // CRUD operations const template = await stack0.mail.templates.create({ name: 'Welcome Email', slug: 'welcome', subject: 'Welcome {{name}}!', html: '

Hi {{name}}

Thanks for joining!

', }); const { templates } = await stack0.mail.templates.list({ search: 'welcome' }); const template = await stack0.mail.templates.get('template_id'); const template = await stack0.mail.templates.getBySlug('welcome'); await stack0.mail.templates.update({ id: 'template_id', subject: 'New subject' }); await stack0.mail.templates.delete('template_id'); // Preview with variables const preview = await stack0.mail.templates.preview({ id: 'template_id', variables: { name: 'John' }, }); ``` ### Audiences (stack0.mail.audiences) Organize contacts into lists for targeted email campaigns. ```typescript // CRUD const audience = await stack0.mail.audiences.create({ name: 'Newsletter Subscribers' }); const { audiences } = await stack0.mail.audiences.list({ search: 'newsletter' }); const audience = await stack0.mail.audiences.get('audience_id'); await stack0.mail.audiences.update({ id: 'audience_id', name: 'New Name' }); await stack0.mail.audiences.delete('audience_id'); // Manage contacts in audience const { contacts } = await stack0.mail.audiences.listContacts({ id: 'audience_id' }); await stack0.mail.audiences.addContacts({ id: 'audience_id', contactIds: ['c1', 'c2'] }); await stack0.mail.audiences.removeContacts({ id: 'audience_id', contactIds: ['c1'] }); ``` ### Contacts (stack0.mail.contacts) Manage individual contacts with metadata. ```typescript // CRUD const contact = await stack0.mail.contacts.create({ email: 'user@example.com', firstName: 'John', lastName: 'Doe', metadata: { company: 'Acme' }, }); const { contacts } = await stack0.mail.contacts.list({ search: 'john', status: 'subscribed' }); const contact = await stack0.mail.contacts.get('contact_id'); await stack0.mail.contacts.update({ id: 'contact_id', firstName: 'Jane' }); await stack0.mail.contacts.delete('contact_id'); // Bulk import const result = await stack0.mail.contacts.import({ audienceId: 'audience_id', contacts: [ { email: 'a@example.com', firstName: 'Alice' }, { email: 'b@example.com', firstName: 'Bob' }, ], }); ``` ### Campaigns (stack0.mail.campaigns) Create and send email campaigns to audiences. ```typescript // CRUD const campaign = await stack0.mail.campaigns.create({ name: 'Product Launch', subject: 'Introducing Our New Product', fromEmail: 'news@yourdomain.com', audienceId: 'audience_id', templateId: 'template_id', }); const { campaigns } = await stack0.mail.campaigns.list({ status: 'draft' }); const campaign = await stack0.mail.campaigns.get('campaign_id'); await stack0.mail.campaigns.update({ id: 'campaign_id', subject: 'New Subject' }); await stack0.mail.campaigns.delete('campaign_id'); // Lifecycle await stack0.mail.campaigns.send({ id: 'campaign_id', sendNow: true }); await stack0.mail.campaigns.send({ id: 'campaign_id', scheduledAt: new Date('2025-01-15') }); await stack0.mail.campaigns.pause('campaign_id'); await stack0.mail.campaigns.cancel('campaign_id'); const duplicate = await stack0.mail.campaigns.duplicate('campaign_id'); // Statistics const stats = await stack0.mail.campaigns.getStats('campaign_id'); ``` ### Sequences (stack0.mail.sequences) Create automated email sequences. Supported triggers: 'contact_created', 'contact_updated' (set triggerConfig.propertyName, optional propertyValue), 'contact_added_to_list' (set triggerConfig.audienceId), and 'event_received' (set triggerConfig.eventName). Contacts can also be enrolled manually with addContact(). ```typescript // CRUD const sequence = await stack0.mail.sequences.create({ name: 'Onboarding Flow', triggerType: 'event_received', triggerConfig: { eventName: 'user_signup' }, }); const { sequences } = await stack0.mail.sequences.list({ status: 'active' }); const sequence = await stack0.mail.sequences.get('sequence_id'); // Includes nodes, connections, and avgCompletionMs (avg time to complete, ms) // Lifecycle await stack0.mail.sequences.publish('sequence_id'); await stack0.mail.sequences.pause('sequence_id'); await stack0.mail.sequences.resume('sequence_id'); await stack0.mail.sequences.archive('sequence_id'); const duplicate = await stack0.mail.sequences.duplicate('sequence_id'); // Node management const node = await stack0.mail.sequences.createNode({ id: 'sequence_id', nodeType: 'email', name: 'Welcome Email', positionX: 100, positionY: 200, }); await stack0.mail.sequences.setNodeEmail('sequence_id', { nodeId: 'node_id', subject: 'Welcome!', templateId: 'template_id', }); await stack0.mail.sequences.setNodeTimer('sequence_id', { nodeId: 'node_id', delayAmount: 3, delayUnit: 'days', }); // Connections between nodes await stack0.mail.sequences.createConnection({ id: 'sequence_id', sourceNodeId: 'node_1', targetNodeId: 'node_2', }); // Contact entries (paginated + searchable by email/name) const { entries } = await stack0.mail.sequences.listEntries({ id: 'sequence_id', search: 'jane@', status: 'active', limit: 25, offset: 0 }); await stack0.mail.sequences.addContact({ id: 'sequence_id', contactId: 'contact_id' }); await stack0.mail.sequences.removeContact({ id: 'sequence_id', entryId: 'entry_id' }); // Analytics const analytics = await stack0.mail.sequences.getAnalytics('sequence_id'); ``` ### Events (stack0.mail.events) Define and track custom events to trigger sequences and segment contacts. ```typescript // Define events const event = await stack0.mail.events.create({ name: 'purchase_completed', description: 'Triggered when a user completes a purchase', propertiesSchema: { properties: [ { name: 'amount', type: 'number', required: true }, { name: 'product_id', type: 'string' }, ], }, }); const { events } = await stack0.mail.events.list(); const event = await stack0.mail.events.get('event_id'); // Track events (triggers sequences) await stack0.mail.events.track({ eventName: 'purchase_completed', contactEmail: 'user@example.com', properties: { amount: 99.99, product_id: 'prod_123' }, }); // Batch tracking await stack0.mail.events.trackBatch({ events: [ { eventName: 'page_viewed', contactEmail: 'a@example.com', properties: { page: '/pricing' } }, { eventName: 'page_viewed', contactEmail: 'b@example.com', properties: { page: '/features' } }, ], }); // View occurrences and analytics const { occurrences } = await stack0.mail.events.listOccurrences({ eventId: 'event_id' }); const analytics = await stack0.mail.events.getAnalytics('event_id'); ``` ### Agent Mailboxes (stack0.mail.mailboxes) Create email accounts for AI agents that can send AND receive. Inbound emails are delivered via webhook. #### Create a Mailbox ```typescript const mailbox = await stack0.mail.mailboxes.create({ address: 'remi', // local part (auto-generated if omitted) displayName: 'Remi', domain: 'agents.mastagents.com', // must be a verified domain webhookUrl: 'https://mastagents.com/api/webhooks/inbound-email', metadata: { agentId: 'abc123' }, maxInboundPerDay: 1000, // rate limit (default: 1000) }); // mailbox.address = "remi@agents.mastagents.com" ``` #### Send as the Agent Use the standard `mail.send()` with the mailbox address: ```typescript await stack0.mail.send({ from: { email: 'remi@agents.mastagents.com', name: 'Remi' }, to: 'craig@company.com', subject: 'Daily briefing', html: '

Here is your daily briefing...

', }); ``` #### Manage Mailboxes ```typescript const { mailboxes } = await stack0.mail.mailboxes.list({ domain: 'agents.mastagents.com' }); const mailbox = await stack0.mail.mailboxes.get('mailbox_id'); await stack0.mail.mailboxes.update({ id: 'mailbox_id', status: 'paused' }); await stack0.mail.mailboxes.delete('mailbox_id'); ``` #### Inbound Messages Stack0 delivers each email sent to a mailbox as a POST to its webhook URL: ```json { "id": "6f1c2d4e-...", "event": "email.inbound", "mailbox": "remi@agents.mastagents.com", "mailboxId": "...", "tag": null, "from": { "email": "craig@company.com", "name": "Craig" }, "to": "remi@agents.mastagents.com", "cc": [], "bcc": [], "replyTo": null, "subject": "Re: Daily briefing", "text": "Thanks, looks good!", "html": "

Thanks, looks good!

", "messageId": "", "inReplyTo": "", "references": [""], "headers": { "message-id": "", "received": ["from ...", "from ..."] }, "attachments": [ { "filename": "photo.jpg", "contentType": "image/jpeg", "size": 48213, "url": "https://...amazonaws.com/...", "expiresAt": "2026-04-09T11:30:00.000Z" } ], "metadata": { "agentId": "abc123" }, "receivedAt": "2026-04-09T10:30:00Z" } ``` - `id` is the same on every retry of one message. Use it to skip duplicates. - `headers` holds every header, with lowercased names. A repeated header, such as Received, is an array. - An attachment `url` works for one hour. Each retry and each `getMessage` call returns a new URL. - Failed deliveries retry after 1m, 5m, 30m, 2h, and 12h (5 attempts in total). #### Plus Addresses Mail to `remi+anything@agents.mastagents.com` goes to the mailbox `remi@agents.mastagents.com`, unless a mailbox exists for the exact address. The payload's `to` is the address the sender used, and `tag` is the part after "+" (`"anything"`). Put an id in the tag of a Reply-To address to match replies to a record. Addresses compare without case. #### Verify Webhooks Each delivery carries [Standard Webhooks](https://www.standardwebhooks.com) headers: - `webhook-id`: the payload `id` - `webhook-timestamp`: Unix seconds - `webhook-signature`: `v1,..">`, keyed by the mailbox secret, base64-decoded Refuse a timestamp more than 5 minutes from now. Always verify the raw body, not parsed and re-serialized JSON. ```typescript import { verifyInboundWebhook } from '@stack0/sdk'; export async function POST(request: Request) { const event = await verifyInboundWebhook({ payload: await request.text(), headers: request.headers, secret: process.env.STACK0_MAILBOX_SECRET!, // throws WebhookVerificationError when it does not match }); // event.id, event.tag, event.inReplyTo, event.text, ... return new Response('ok'); } ``` Any Standard Webhooks library also verifies it, with the mailbox secret as the key. `mailboxes.create` returns the secret once as `webhookSecret`, and `mailboxes.rotateSecret(id)` returns a new one. Deliveries also carry the older `X-Stack0-Signature` (hex HMAC-SHA256 of the raw body, keyed by the secret). That header does not cover a timestamp; use `webhook-signature` in new code. #### Daily Limit A mailbox accepts `maxInboundPerDay` messages in any 24 hours (default 1000). A message past the limit is stored and not delivered. Its `webhookLastError` starts with `DAILY_LIMIT_REACHED`. #### View Inbound Messages ```typescript const { messages } = await stack0.mail.mailboxes.listMessages({ mailboxId: 'mailbox_id' }); const message = await stack0.mail.mailboxes.getMessage('message_id'); // message.headers, message.tag, message.attachments[i].url ``` #### Setup Requirements To receive inbound email on a verified domain, add an MX record: - **Type**: MX - **Value**: `10 inbound-smtp.us-east-1.amazonaws.com` To keep your root domain's mail, use a subdomain (for example `mail.example.com`) for mailboxes. ### Email Status Flow 1. **pending**: Email created, queued for sending 2. **sent**: Email handed off to mail server 3. **delivered**: Email successfully delivered to recipient 4. **bounced**: Email rejected by recipient server 5. **failed**: Permanent delivery failure ## Screenshots API Reference The Screenshots API enables you to capture high-quality screenshots of any webpage with full browser rendering. ### Basic Screenshot ```typescript const { id, status } = await stack0.screenshots.capture({ url: 'https://example.com', format: 'png', // 'png' | 'jpeg' | 'webp' | 'pdf' fullPage: false, // Capture full scrollable page deviceType: 'desktop', // 'desktop' | 'tablet' | 'mobile' }); // Poll for completion const screenshot = await stack0.screenshots.get({ id }); ``` ### Capture and Wait For synchronous operations, use `captureAndWait`: ```typescript const screenshot = await stack0.screenshots.captureAndWait({ url: 'https://example.com', format: 'png', fullPage: true, blockAds: true, blockCookieBanners: true, }); // Response { id: 'scr_abc123', status: 'completed', imageUrl: 'https://cdn.stack0.dev/screenshots/...', imageWidth: 1280, imageHeight: 720, processingTimeMs: 2340, } ``` #### Screenshot Options - `url` (required): URL to capture - `format`: Output format - `png`, `jpeg`, `webp`, `pdf` - `quality`: Image quality 1-100 (for jpeg/webp) - `fullPage`: Capture full scrollable page - `deviceType`: `desktop` (1280x720), `tablet` (768x1024), `mobile` (375x667) - `viewportWidth`: Custom viewport width (320-3840) - `viewportHeight`: Custom viewport height (240-2160) - `deviceScaleFactor`: Device pixel ratio (1-3) - `waitForSelector`: CSS selector to wait for before capture - `waitForTimeout`: Additional wait time in ms (0-30000) - `blockAds`: Block advertisements - `blockCookieBanners`: Block cookie consent popups - `blockChatWidgets`: Block chat widgets - `blockTrackers`: Block tracking scripts - `darkMode`: Enable dark mode - `customCss`: Inject custom CSS (max 10KB) - `customJs`: Inject custom JavaScript (max 10KB) - `selector`: Capture specific element only - `hideSelectors`: Array of CSS selectors to hide (max 50) - `clickSelector`: Click element before capture - `clip`: Capture specific region `{ x, y, width, height }` ## Integrations API Reference The Integrations API provides a unified interface to access your users' third-party applications. Connect once, access CRM, storage, communication, and productivity tools through one consistent API. ### Supported Categories - **CRM**: HubSpot, Salesforce, Pipedrive, Attio - contacts, companies, deals - **Storage**: Google Drive, Dropbox, OneDrive - files, folders, uploads - **Communication**: Slack, Discord - channels, messages, users - **Productivity**: Notion, Google Sheets, Airtable - documents, tables, rows - **Calendar**: Google Calendar - calendars, events - **Email**: Gmail - messages, threads, labels ### Setting Up Connections Users connect their apps through the IntegrationsConnect component or via OAuth flow: ```typescript // Server-side: Create a connection session for a user const session = await stack0.integrations.createConnectionSession({ endUserId: 'user_123', // Your user's ID connectorSlug: 'hubspot', // Which app to connect redirectUrl: 'https://yourapp.com/integrations/callback', }); // Redirect user to session.authUrl to complete OAuth ``` ### List Available Connectors ```typescript const connectors = await stack0.integrations.listConnectors(); // Returns available integrations [ { slug: 'hubspot', name: 'HubSpot', category: 'crm', status: 'active' }, { slug: 'google-drive', name: 'Google Drive', category: 'storage', status: 'active' }, { slug: 'slack', name: 'Slack', category: 'communication', status: 'active' }, // ... ] ``` ### List User Connections ```typescript const connections = await stack0.integrations.listConnections({ endUserId: 'user_123', }); // Returns user's connected apps [ { id: 'conn_abc123', connectorSlug: 'hubspot', status: 'active', createdAt: Date, }, ] ``` ### CRM Operations ```typescript // List contacts const { contacts, nextCursor } = await stack0.integrations.crm.listContacts({ connectionId: 'conn_abc123', limit: 50, cursor: undefined, // For pagination }); // Create a contact const contact = await stack0.integrations.crm.createContact({ connectionId: 'conn_abc123', data: { email: 'john@example.com', firstName: 'John', lastName: 'Doe', phone: '+1234567890', }, }); // List companies const { companies } = await stack0.integrations.crm.listCompanies({ connectionId: 'conn_abc123', }); // List deals/opportunities const { deals } = await stack0.integrations.crm.listDeals({ connectionId: 'conn_abc123', }); // Create a note await stack0.integrations.crm.createNote({ connectionId: 'conn_abc123', data: { content: 'Follow up on proposal', contactId: 'contact_123', }, }); ``` ### Storage Operations ```typescript // List files in a folder const { files } = await stack0.integrations.storage.listFiles({ connectionId: 'conn_def456', folderId: 'root', // or specific folder ID }); // Upload a file const file = await stack0.integrations.storage.uploadFile({ connectionId: 'conn_def456', name: 'report.pdf', content: fileBuffer, // Buffer or base64 mimeType: 'application/pdf', folderId: 'folder_123', // Optional }); // Download a file const { content, mimeType } = await stack0.integrations.storage.downloadFile({ connectionId: 'conn_def456', fileId: 'file_abc', }); // Create a folder const folder = await stack0.integrations.storage.createFolder({ connectionId: 'conn_def456', name: 'Reports', parentId: 'root', }); ``` ### Communication Operations ```typescript // List channels const { channels } = await stack0.integrations.communication.listChannels({ connectionId: 'conn_ghi789', }); // Send a message await stack0.integrations.communication.sendMessage({ connectionId: 'conn_ghi789', channelId: 'C1234567890', text: 'Hello from your app!', }); // List users const { users } = await stack0.integrations.communication.listUsers({ connectionId: 'conn_ghi789', }); ``` ### Productivity Operations ```typescript // List documents (Notion pages, etc.) const { documents } = await stack0.integrations.productivity.listDocuments({ connectionId: 'conn_jkl012', }); // List tables (Google Sheets, Airtable bases) const { tables } = await stack0.integrations.productivity.listTables({ connectionId: 'conn_jkl012', }); // Get table rows const { rows } = await stack0.integrations.productivity.getTableRows({ connectionId: 'conn_jkl012', tableId: 'table_abc', }); // Create a table row await stack0.integrations.productivity.createTableRow({ connectionId: 'conn_jkl012', tableId: 'table_abc', data: { Name: 'New Item', Status: 'Active', Date: '2025-01-15', }, }); ``` ### Calendar Operations ```typescript // List calendars const { data: calendars } = await stack0.integrations.calendar.listCalendars('conn_abc123'); // List events with time range const { data: events } = await stack0.integrations.calendar.listEvents('conn_abc123', 'primary', { timeMin: new Date('2026-04-01'), timeMax: new Date('2026-04-30'), }); // Create event const event = await stack0.integrations.calendar.createEvent('conn_abc123', 'primary', { title: 'Team Standup', startTime: new Date('2026-04-10T09:00:00Z'), endTime: new Date('2026-04-10T09:30:00Z'), attendees: [{ email: 'teammate@company.com' }], location: 'Zoom', }); // Update / delete event await stack0.integrations.calendar.updateEvent('conn_abc123', 'primary', 'event_id', { title: 'Updated Title' }); await stack0.integrations.calendar.deleteEvent('conn_abc123', 'primary', 'event_id'); ``` ### Email Operations (Gmail) ```typescript // List messages const { data: messages } = await stack0.integrations.mail.listMessages('conn_abc123', { query: 'is:unread' }); // Get message const message = await stack0.integrations.mail.getMessage('conn_abc123', 'msg_id'); // Send email const sent = await stack0.integrations.mail.sendMessage('conn_abc123', { to: ['user@example.com'], subject: 'Hello', body: 'Email body text', }); // Threads const { data: threads } = await stack0.integrations.mail.listThreads('conn_abc123'); const thread = await stack0.integrations.mail.getThread('conn_abc123', 'thread_id'); // Labels const labels = await stack0.integrations.mail.listLabels('conn_abc123'); ``` ### Passthrough API For provider-specific features not covered by the unified API: ```typescript // Make a raw API call to the connected provider const response = await stack0.integrations.passthrough({ connectionId: 'conn_abc123', method: 'GET', path: '/crm/v3/objects/custom_object', query: { limit: '10' }, }); ``` ### Delete Connection ```typescript await stack0.integrations.deleteConnection({ connectionId: 'conn_abc123', }); ``` ### IntegrationsConnect Element Pre-built React component for connecting user apps: ```tsx // Note: Requires a backend proxy for security (API keys must stay server-side) // 1. Create API proxy route (app/api/integrations/[...path]/route.ts) export async function POST(request, { params }) { const session = await auth(); if (!session?.user) return unauthorized(); const path = params.path.join('/'); const body = await request.json(); const response = await fetch(`https://api.stack0.dev/v1/integrations/${path}`, { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.STACK0_API_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ ...body, endUserId: session.user.id }), }); return Response.json(await response.json()); } // 2. Use the component import { IntegrationsConnect } from '@stack0/elements'; { console.log('Connected:', connection.connectorSlug); }} onError={(error) => { console.error('Connection failed:', error); }} /> ``` ## AI Extraction API Reference Extract structured data from any webpage using AI. ### Basic Extraction ```typescript const { id, status } = await stack0.extraction.extract({ url: 'https://example.com/article', mode: 'markdown', // 'auto' | 'markdown' | 'schema' | 'raw' }); // Poll for completion const extraction = await stack0.extraction.get({ id }); ``` ### Extract and Wait ```typescript const extraction = await stack0.extraction.extractAndWait({ url: 'https://example.com/product', mode: 'schema', schema: { type: 'object', properties: { title: { type: 'string' }, price: { type: 'number' }, description: { type: 'string' }, inStock: { type: 'boolean' }, }, }, }); // Response { id: 'ext_abc123', status: 'completed', extractedData: { title: 'Product Name', price: 29.99, description: 'Product description...', inStock: true, }, processingTimeMs: 3200, } ``` #### Extraction Modes - `auto`: AI automatically extracts the most relevant content - `markdown`: Convert page content to clean, formatted markdown - `schema`: Extract data matching your custom JSON schema - `html`: Get the raw HTML content #### Extraction Options - `url` (required): URL to extract from - `mode`: Extraction mode - `schema`: JSON Schema for structured extraction (when mode is `schema`) - `prompt`: Custom prompt to guide AI extraction - `includeLinks`: Include links in extracted content - `includeImages`: Include image URLs in extracted content - `includeMetadata`: Include page metadata (title, description, etc.) - `waitForSelector`: CSS selector to wait for before extraction - `waitForTimeout`: Additional wait time in ms ### Get Screenshot/Extraction Status Check the status of an async operation: ```typescript // Get screenshot status const screenshot = await stack0.screenshots.get({ id: 'scr_abc123' }); // Get extraction status const extraction = await stack0.extraction.get({ id: 'ext_abc123' }); ``` ### Status Flow 1. **pending**: Request created, queued for processing 2. **processing**: Being processed by workers 3. **completed**: Successfully completed 4. **failed**: Processing failed (check `error` field) ### Batch Processing Process multiple URLs in parallel: ```typescript // Batch screenshots const batch = await stack0.screenshots.batchAndWait({ urls: [ 'https://example.com/page1', 'https://example.com/page2', 'https://example.com/page3', ], config: { format: 'png', fullPage: true, }, }); // Batch extractions const extractionBatch = await stack0.extraction.batchAndWait({ urls: ['https://example.com/article1', 'https://example.com/article2'], config: { mode: 'markdown', includeMetadata: true, }, }); ``` ### Webhooks Configure webhooks to receive notifications when jobs complete: ```typescript const { id } = await stack0.screenshots.capture({ url: 'https://example.com', webhookUrl: 'https://yourapp.com/webhook', webhookSecret: 'your-secret-key', }); ``` Webhook payload: ```json { "event": "screenshot.completed", "data": { "id": "scr_abc123", "status": "completed", "imageUrl": "https://cdn.stack0.dev/screenshots/...", "processingTimeMs": 2340 } } ``` ### Caching Enable caching to avoid re-processing identical requests: ```typescript const screenshot = await stack0.screenshots.captureAndWait({ url: 'https://example.com', cacheKey: 'homepage-v1', cacheTtl: 3600, // Cache for 1 hour }); ``` ## Crawl API Recursively crawl a website and scrape every page. Honors robots.txt and sitemap.xml. Open Firecrawl alternative. ```typescript const crawl = await stack0.crawl.startAndWait({ url: "https://docs.example.com", maxDepth: 3, maxPages: 200, formats: ["markdown", "links"], respectRobotsTxt: true, stealth: true, }); for (const page of crawl.pages ?? []) { console.log(page.url, page.markdown?.slice(0, 120)); } ``` Endpoints (prefix all with `/v1`): `POST /webdata/crawl`, `GET /webdata/crawl/{id}?includePages=true`, `GET /webdata/crawl/{crawlId}/pages`, `POST /webdata/crawl/{id}/cancel`, `DELETE /webdata/crawl/{id}`, `GET /webdata/crawl` (list). ## Map API Discover every URL on a site in seconds. Uses `sitemap.xml` with a link-crawl fallback. ```typescript const { urls } = await stack0.map.createAndWait({ url: "https://docs.example.com", search: "api", limit: 5000, }); ``` Endpoints (prefix all with `/v1`): `POST /webdata/map`, `GET /webdata/map/{id}`, `GET /webdata/map`, `DELETE /webdata/map/{id}`. ## Documents API Parse PDF and DOCX files into clean markdown. ```typescript const doc = await stack0.documents.parseAndWait({ url: "https://example.com/whitepaper.pdf", }); console.log(doc.pageCount, doc.markdown); ``` Endpoints (prefix all with `/v1`): `POST /webdata/documents`, `GET /webdata/documents/{id}`, `GET /webdata/documents`, `DELETE /webdata/documents/{id}`. ## Actions (multi-step scrapes) Pass an `actions` array on any scrape, extraction, crawl, or search request to drive the page before content is captured. Supported types: `click`, `type`, `press`, `scroll`, `wait`, `screenshot`, `execute_js`, `extract`. ```typescript await stack0.extraction.extractAndWait({ url: "https://example.com/search", mode: "markdown", actions: [ { type: "type", selector: "input[name=q]", text: "playwright" }, { type: "press", key: "Enter" }, { type: "wait", selector: ".results", timeout: 5000 }, { type: "scroll", direction: "down", pixels: 1200 }, { type: "screenshot" }, ], }); ``` ## Stealth & Proxy Every webdata request accepts `stealth: true` (default) which applies playwright-extra's evasion patches. Set `proxy: "residential" | "datacenter"` and optional `proxyLocation: "us"` to route through your configured proxy provider (configure via `WEBDATA_PROXY_SERVER` env var). ## MCP Server (webdata tools) The Stack0 MCP server exposes crawl, map, and document tools alongside screenshots and extraction: - `crawl_start`, `crawl_get`, `crawl_list`, `crawl_cancel` - `map_create`, `map_get`, `map_list` - `document_parse`, `document_get`, `document_list` Connect over Streamable HTTP at `https://api.stack0.dev/mcp` with an `Authorization: Bearer ` header. Full setup: the MCP Server section below, or https://www.stack0.dev/docs/mcp. ## Workflows API Reference The Workflows API enables you to build multi-step AI pipelines with sequential and parallel execution, variable passing between steps, and webhook notifications. ### Supported Providers - **Anthropic**: Claude models (claude-3-5-sonnet, claude-3-opus, claude-3-haiku) - **OpenAI**: GPT models (gpt-4o, gpt-4-turbo, gpt-3.5-turbo) - **Gemini**: Google AI models (gemini-1.5-pro, gemini-1.5-flash) - **Replicate**: Image/video models (SDXL, Stable Diffusion, etc.) - **Stack0**: Built-in AI capabilities ### Step Types - `llm`: Text generation with AI models - `image`: Image generation (Replicate, DALL-E) - `video`: Video generation (Kling, Replicate) - `audio`: Audio generation (ElevenLabs, etc.) - `code`: Execute custom code - `http`: Make HTTP requests - `transform`: Transform data between steps - `condition`: Conditional branching - `loop`: Iterate over arrays ### Create Workflow ```typescript const workflow = await stack0.workflows.create({ projectSlug: 'my-project', slug: 'content-pipeline', name: 'Content Generation Pipeline', description: 'Generate blog posts with AI', steps: [ { id: 'generate-outline', type: 'llm', name: 'Generate Outline', provider: 'anthropic', model: 'claude-3-5-sonnet-20241022', prompt: 'Create an outline for a blog post about {{topic}}', outputVariable: 'outline', }, { id: 'write-content', type: 'llm', name: 'Write Content', provider: 'openai', model: 'gpt-4o', prompt: 'Write a blog post based on this outline:\n\n{{steps.generate-outline.output}}', dependsOn: ['generate-outline'], outputVariable: 'content', }, ], variables: { topic: { type: 'string', required: true }, }, }); ``` ### List Workflows ```typescript const { workflows, total, hasMore } = await stack0.workflows.list({ projectSlug: 'my-project', limit: 20, offset: 0, }); ``` ### Get Workflow ```typescript const workflow = await stack0.workflows.get({ projectSlug: 'my-project', id: 'workflow_abc123', }); ``` ### Update Workflow ```typescript const workflow = await stack0.workflows.update({ projectSlug: 'my-project', id: 'workflow_abc123', name: 'Updated Pipeline Name', steps: [...updatedSteps], isActive: true, }); ``` ### Delete Workflow ```typescript await stack0.workflows.delete({ projectSlug: 'my-project', id: 'workflow_abc123', }); ``` ### Run Workflow Start a workflow execution: ```typescript const run = await stack0.workflows.run({ projectSlug: 'my-project', workflowId: 'workflow_abc123', variables: { topic: 'AI in Healthcare', }, webhook: { url: 'https://yourapp.com/webhook', secret: 'your-webhook-secret', }, metadata: { userId: 'user_123', source: 'api', }, }); // Response { id: 'run_xyz789', workflowId: 'workflow_abc123', status: 'pending', variables: { topic: 'AI in Healthcare' }, createdAt: Date, } ``` ### Run and Wait For synchronous execution, use `runAndWait`: ```typescript const result = await stack0.workflows.runAndWait({ projectSlug: 'my-project', workflowId: 'workflow_abc123', variables: { topic: 'AI in Healthcare', }, }); // Response includes completed output { id: 'run_xyz789', status: 'completed', output: { outline: '1. Introduction\n2. Current Applications...', content: 'Artificial intelligence is transforming...', }, totalDurationMs: 12500, creditsUsed: 15, } ``` ### Get Run Status ```typescript const run = await stack0.workflows.getRun({ projectSlug: 'my-project', id: 'run_xyz789', }); console.log(`Status: ${run.status}`); console.log(`Progress: ${run.completedSteps}/${run.totalSteps}`); // Check step states for (const [stepId, state] of Object.entries(run.stepStates)) { console.log(`${stepId}: ${state.status}`); } ``` ### List Runs ```typescript const { items, total, hasMore } = await stack0.workflows.listRuns({ projectSlug: 'my-project', workflowId: 'workflow_abc123', // Optional: filter by workflow status: 'completed', // Optional: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled' limit: 50, offset: 0, }); ``` ### Cancel Run ```typescript await stack0.workflows.cancelRun({ projectSlug: 'my-project', id: 'run_xyz789', }); ``` ### Variable Interpolation Use `{{variable}}` syntax to reference variables and step outputs: ```typescript // Reference input variables prompt: 'Write about {{topic}}' // Reference step outputs prompt: 'Expand on: {{steps.generate-outline.output}}' // Reference nested data prompt: 'Use this title: {{steps.generate-metadata.output.title}}' ``` ### Step Configuration Each step type has specific configuration options: #### LLM Step ```typescript { id: 'step-id', type: 'llm', name: 'Generate Text', provider: 'anthropic', // 'anthropic' | 'openai' | 'gemini' model: 'claude-3-5-sonnet-20241022', prompt: 'Your prompt here with {{variables}}', systemPrompt: 'Optional system instructions', temperature: 0.7, // 0-2 maxTokens: 4096, responseFormat: 'text', // 'text' | 'json' dependsOn: ['previous-step-id'], // Step dependencies outputVariable: 'variableName', } ``` #### Image Step ```typescript { id: 'generate-image', type: 'image', name: 'Generate Image', provider: 'replicate', model: 'stability-ai/sdxl', prompt: 'A futuristic city at sunset', width: 1024, height: 1024, outputVariable: 'generatedImage', } ``` #### HTTP Step ```typescript { id: 'fetch-data', type: 'http', name: 'Fetch External Data', method: 'POST', url: 'https://api.example.com/data', headers: { 'Authorization': 'Bearer {{apiKey}}', }, body: { query: '{{searchQuery}}', }, outputVariable: 'externalData', } ``` ### Webhook Events Configure webhooks to receive notifications: - `run.started`: Workflow run started - `run.completed`: Workflow run completed successfully - `run.failed`: Workflow run failed - `step.completed`: Individual step completed Webhook payload: ```json { "event": "run.completed", "timestamp": "2025-01-15T10:30:00Z", "data": { "id": "run_xyz789", "workflowId": "workflow_abc123", "status": "completed", "output": { ... }, "totalDurationMs": 12500, "creditsUsed": 15 } } ``` ### Run Status Flow 1. **pending**: Run created, waiting to start 2. **running**: Workflow executing steps 3. **completed**: All steps completed successfully 4. **failed**: One or more steps failed 5. **cancelled**: Run was cancelled ### Pricing - **LLM Steps**: Based on token usage (varies by provider/model) - **Image Generation**: $0.02-0.10 per image (varies by model) - **Video Generation**: $0.50-2.00 per video (varies by model/duration) - **HTTP Steps**: $0.001 per request ## Domain Verification To send emails from your custom domain, you need to verify domain ownership. ### 1. Add Domain In the dashboard, go to Mail → Domains → Add Domain and enter your domain (e.g., `yourdomain.com`). ### 2. Configure DNS Records Add the provided DNS records to your domain: - **SPF Record**: Authorizes Stack0 to send emails - **DKIM Records**: Cryptographic authentication - **DMARC Record**: Email policy and reporting - **Verification Record**: Proves domain ownership ### 3. Verify Domain Click "Verify Domain" in the dashboard. Verification typically completes within minutes but can take up to 72 hours. ### 4. Set as Default Mark your verified domain as default to use it automatically for all emails. ## Email Tracking Stack0 automatically tracks email engagement: - **Sends**: When email leaves the server - **Deliveries**: When recipient server accepts email - **Opens**: When recipient opens email (requires HTML) - **Clicks**: When recipient clicks links in email - **Bounces**: When email is rejected - **Complaints**: When recipient marks as spam View analytics in the dashboard under Mail → Analytics. ## Common Use Cases ### Transactional Emails Send emails triggered by user actions: ```typescript // Welcome email await stack0.mail.send({ from: 'welcome@yourapp.com', to: newUser.email, subject: 'Welcome to YourApp!', templateId: 'welcome-email', templateVariables: { name: newUser.name }, }); // Password reset await stack0.mail.send({ from: 'noreply@yourapp.com', to: user.email, subject: 'Reset your password', templateId: 'password-reset', templateVariables: { resetUrl: generateResetUrl(user.id), expiresIn: '1 hour', }, }); // Order confirmation await stack0.mail.send({ from: 'orders@yourapp.com', to: customer.email, subject: `Order #${order.id} confirmed`, templateId: 'order-confirmation', templateVariables: { order, customer }, }); ``` ### Marketing Emails Send newsletters and promotional content: ```typescript // Newsletter to subscribers const subscribers = await getActiveSubscribers(); await stack0.mail.sendBroadcast({ from: 'newsletter@yourapp.com', to: subscribers.map(s => s.email), subject: 'Monthly Update - October 2025', templateId: 'monthly-newsletter', tags: ['newsletter', 'october-2025'], }); // Product announcement await stack0.mail.sendBroadcast({ from: 'updates@yourapp.com', to: userSegment.emails, subject: 'Introducing Our New Feature!', html: announcementHtml, tags: ['product-update', 'feature-launch'], }); ``` ### User-Generated Content with CDN Handle user uploads in your application: ```typescript // Upload user avatar const avatar = await stack0.cdn.upload({ projectSlug: 'my-project', file: uploadedFile, filename: `avatar-${userId}.jpg`, mimeType: 'image/jpeg', folder: '/avatars', metadata: { userId }, }); // Get optimized thumbnail (client-side, no API call) const thumbnailUrl = stack0.cdn.getTransformUrl(avatar.cdnUrl, { width: 150, height: 150, fit: 'cover', format: 'webp' }); // Save to user profile await updateUser(userId, { avatarUrl: thumbnailUrl }); ``` ### Product Images Manage e-commerce product images: ```typescript // Upload product image const image = await stack0.cdn.upload({ projectSlug: 'my-project', file: productImage, filename: `product-${productId}-main.jpg`, mimeType: 'image/jpeg', folder: `/apis/${productId}`, tags: ['product', productId], metadata: { productId, isPrimary: true }, }); // Generate multiple sizes for responsive images const sizes = [ { width: 1200, name: 'large' }, { width: 800, name: 'medium' }, { width: 400, name: 'small' }, { width: 150, name: 'thumbnail' }, ]; const urls = await Promise.all( sizes.map(async ({ width, name }) => { const { url } = await stack0.cdn.getTransformUrl({ assetId: image.id, options: { width, format: 'webp', quality: 85 }, }); return { name, url }; }) ); ``` ## Error Handling The SDK throws typed errors for different scenarios: ```typescript import { Stack0, Stack0Error } from '@stack0/sdk'; try { await stack0.mail.send({ from: 'invalid@unverified-domain.com', to: 'user@example.com', subject: 'Test', html: '

Test

', }); } catch (error) { if (error instanceof Stack0Error) { console.error('Stack0 Error:', error.message); console.error('Status Code:', error.statusCode); console.error('Error Code:', error.code); } } ``` Common error codes: - `INVALID_FROM`: From address not verified - `INVALID_EMAIL`: Malformed email address - `RATE_LIMIT`: Too many requests - `QUOTA_EXCEEDED`: Usage limit reached - `UNAUTHORIZED`: Invalid API key - `NOT_FOUND`: Resource not found - `PROJECT_NOT_FOUND`: Invalid project slug ## Rate Limits Default rate limits per organization: - **Emails per second**: 10 - **Emails per minute**: 100 - **Emails per hour**: 1,000 - **Emails per day**: 10,000 - **CDN uploads per minute**: 60 - **CDN requests per second**: 100 - **Screenshots per day**: 10,000 (Platform), custom (Enterprise) - **Extractions per day**: 5,000 (Platform), custom (Enterprise) Contact support for higher limits. Rate limit information is included in response headers: ``` X-RateLimit-Limit: 100 X-RateLimit-Remaining: 95 X-RateLimit-Reset: 1637000000 ``` ## Webhooks Configure webhooks to receive real-time notifications about email events. ### Available Events - `email.sent`: Email sent to mail server - `email.delivered`: Email delivered to recipient - `email.bounced`: Email bounced - `email.opened`: Recipient opened email - `email.clicked`: Recipient clicked link - `email.complained`: Recipient marked as spam ### Setup 1. Go to Mail → Webhooks → Create Webhook 2. Enter your endpoint URL 3. Select events to receive 4. Save and copy the signing secret ### Payload Example ```json { "event": "email.delivered", "timestamp": "2025-11-24T10:30:00Z", "data": { "id": "email_123abc", "from": "noreply@yourdomain.com", "to": "user@example.com", "subject": "Welcome!", "status": "delivered", "deliveredAt": "2025-11-24T10:30:00Z" } } ``` ### Verifying Webhooks Webhooks include a signature header for verification: ```typescript import { createHmac } from 'crypto'; function verifyWebhook(payload: string, signature: string, secret: string) { const hmac = createHmac('sha256', secret); const digest = hmac.update(payload).digest('hex'); return digest === signature; } ``` ## Pricing Metered usage rates, billed beyond the $10 of monthly included credits: - **Emails**: $0.50 per 1,000 emails - **CDN Storage & Bandwidth**: $0.25 per GB - **Image Transformations**: $0.50 per 1,000 transforms - **Video Transcoding**: $0.005 per minute - **Video Streaming**: $0.05 per GB - **Audio Transcoding**: $0.002 per minute - **Integrations**: $1.00 per 1,000 API calls - **Screenshots**: $1.00 per 1,000 screenshots - **AI Extractions**: $2.00 per 1,000 extractions - **Memory Store**: $1.00 per 10,000 memories - **Memory Recall**: $2.00 per 10,000 queries - **Memory Search**: $0.50 per 10,000 queries - **Memory Storage**: $0.25 per GB ### Billing Usage is calculated daily and billed monthly. View current usage in Settings → Billing. ## API Keys Create and manage API keys in Settings → API Keys. ### Types - **Standard**: Full access to all resources in organization - **Send-only**: Can only send emails, cannot read - **Read-only**: Can view data, cannot send or modify ### Security - Store API keys securely (environment variables) - Never commit keys to version control - Rotate keys regularly - Use send-only keys for client-side code - Revoke compromised keys immediately ## Environment Variables Recommended environment variable naming: ```bash # Production STACK0_API_KEY=sk_live_... # Development STACK0_API_KEY=sk_test_... # Optional: Custom API endpoint STACK0_API_URL=https://api.stack0.dev/v1 ``` ## Migration from Other Services ### From Resend Stack0's API is compatible with Resend - just change the import: ```typescript // Before import { Resend } from 'resend'; const resend = new Resend(process.env.RESEND_API_KEY); // After import { Mail as Resend } from '@stack0/sdk/mail'; const resend = new Resend({ apiKey: process.env.STACK0_API_KEY }); ``` ### From SendGrid ```typescript // Before (SendGrid) sgMail.send({ to: 'user@example.com', from: 'noreply@yourdomain.com', subject: 'Hello', html: '

Content

', }); // After (Stack0) stack0.mail.send({ to: 'user@example.com', from: 'noreply@yourdomain.com', subject: 'Hello', html: '

Content

', }); ``` ### From Cloudinary/Imgix ```typescript // Before (Cloudinary) cloudinary.url('sample.jpg', { width: 300, crop: 'fill' }); // After (Stack0) const { url } = await stack0.cdn.getTransformUrl({ assetId: 'asset_abc123', options: { width: 300, fit: 'cover' }, }); ``` ## Dashboard Features Access your dashboard at https://app.stack0.dev ### Mail Dashboard - **Overview**: Key metrics and recent emails - **Logs**: Search and filter all sent emails - **Templates**: Create and manage email templates - **Domains**: Verify and manage sending domains - **Analytics**: Delivery rates, opens, clicks, bounces - **Webhooks**: Configure event notifications - **API Keys**: Generate and manage access keys ### CDN Dashboard - **Assets**: Browse, search, and manage all public CDN assets - **Private Files**: Manage private files with secure download links - **Bundles**: Create and manage zip download bundles - **Folders**: Organize assets with virtual folders - **Usage**: Monitor storage and bandwidth consumption - **Transformations**: View transformation statistics ### Organization Management - **Members**: Invite team members with role-based access - **Billing**: View usage and manage payment methods - **Settings**: Configure organization preferences - **Activity Log**: Audit trail of all actions ## Support - **Documentation**: https://www.stack0.dev/docs - **Dashboard**: https://app.stack0.dev - **Status**: https://www.stack0.dev/status - **Contact**: https://www.stack0.dev/contact - **Support email**: support@stack0.dev - **Sales email**: hello@stack0.dev - **Security email**: security@stack0.dev ## Company - **About**: https://www.stack0.dev/about - **Contact**: https://www.stack0.dev/contact - **Incorporated**: Delaware, United States - **Operations**: remote, no public office ## Legal - **Terms of Service**: https://www.stack0.dev/terms - **Privacy Policy**: https://www.stack0.dev/privacy ## MCP Server Stack0 runs a hosted MCP (Model Context Protocol) server that exposes every Stack0 product as agent tools. Connect Claude Code, Claude Desktop, Cursor, ChatGPT, or any MCP-compatible client to send email, manage CDN assets, capture screenshots, extract data, transcode video, run AI workflows, and call third-party integrations. Full guide: https://www.stack0.dev/docs/mcp ### Endpoint | Property | Value | | --- | --- | | URL | `https://api.stack0.dev/mcp` | | Transport | Streamable HTTP | | Legacy transport | `https://api.stack0.dev/mcp/sse` (SSE) | | Authentication | `Authorization: Bearer ` | | Protocol version | 2025-11-25 (also accepts 2025-06-18, 2025-03-26, 2024-11-05, 2024-10-07) | | Tools | 41 | ### Discovery | Path | Specification | | --- | --- | | `/.well-known/mcp.json` | SEP-1649 Server Card, with every tool's JSON Schema | | `/.well-known/mcp/server-card.json` | SEP-1649 Server Card | | `/.well-known/mcp` | SEP-1960 manifest | | `/.well-known/mcp-server` | IETF draft-serra-mcp-discovery-uri manifest | Available on both `https://www.stack0.dev` and `https://api.stack0.dev`. The server card is generated from the running server, so its tool list is always current. ### Connection configuration Streamable HTTP, the recommended transport: ```json { "mcpServers": { "stack0": { "type": "http", "url": "https://api.stack0.dev/mcp", "headers": { "Authorization": "Bearer sk_live_your_api_key" } } } } ``` Claude Code, from the command line: ```bash claude mcp add --transport http stack0 https://api.stack0.dev/mcp \ --header "Authorization: Bearer $STACK0_API_KEY" ``` ### MCP HTTP endpoints - `POST /mcp` — Streamable HTTP transport - `DELETE /mcp` — close a session - `GET /mcp/sse` — SSE transport for long-lived connections - `POST /mcp/messages` — SSE message endpoint - `GET /mcp/health` — health check, no authentication required - `GET /mcp/tools` — list tool names and descriptions, authentication required ### Authentication Every MCP endpoint except `/mcp/health` requires an API key, sent as either: - `Authorization: Bearer sk_live_...` - `X-API-Key: sk_live_...` Tools run against the organization that owns the key. Create one in the dashboard under Settings → API Keys. ### Available tools #### Mail (6 tools) - `mail_send` — Send a single email. Returns the email ID and status. - `mail_send_batch` — Send multiple emails in batch. Returns results for each email. - `mail_get` — Get an email by ID, including its status and tracking info. - `mail_list` — List sent emails with optional filters. - `mail_create_contact` — Create or update a contact in the mailing list. - `mail_list_contacts` — List contacts in the mailing list. #### CDN (8 tools) - `cdn_upload` — Generate a presigned URL for uploading a file to the CDN. Returns the upload URL and asset ID. - `cdn_get` — Get an asset by ID, including its CDN URLs and metadata. - `cdn_list` — List assets with optional filters and pagination. - `cdn_delete` — Delete an asset by ID. - `cdn_transform` — Get a URL for a transformed image with resize, crop, and format conversion options. - `cdn_create_folder` — Create a new folder in the CDN. - `cdn_list_folders` — List folders in the CDN. - `cdn_delete_folder` — Delete a folder by ID. #### Screenshots (4 tools) - `screenshots_capture` — Capture a screenshot of a webpage. Returns the screenshot ID for tracking. - `screenshots_get` — Get a screenshot by ID, including its status and result URL. - `screenshots_list` — List screenshots with optional filters. Returns paginated results. - `screenshots_delete` — Delete a screenshot by ID. #### Extraction (4 tools) - `extraction_extract` — Extract structured data or content from a webpage. Returns the extraction ID for tracking. - `extraction_get` — Get an extraction by ID, including its status and extracted data. - `extraction_list` — List extractions with optional filters. Returns paginated results. - `extraction_delete` — Delete an extraction by ID. #### Video (6 tools) - `video_transcode` — Start a video transcoding job to generate HLS streams or MP4 variants. - `video_get_job` — Get the status and details of a transcoding job. - `video_list_jobs` — List transcoding jobs with optional filters. - `video_cancel_job` — Cancel a pending or running transcoding job. - `video_get_streaming_url` — Get streaming URLs for a transcoded asset. - `video_extract_audio` — Extract audio track from a video asset. #### Workflows (6 tools) - `workflows_create` — Create a new AI workflow with LLM, HTTP, and transform steps. Workflows are DAGs that can process data through multiple steps. - `workflows_run` — Execute a workflow with provided input variables. Returns a run ID for tracking progress. - `workflows_list` — List all workflows in the organization. - `workflows_get_run` — Get the status and result of a workflow run. - `workflows_list_runs` — List workflow runs with optional filters. - `workflows_cancel_run` — Cancel a pending or running workflow. #### Integrations (7 tools) - `integrations_list_connectors` — List available connectors (HubSpot, Salesforce, Google Drive, etc.). - `integrations_list_connections` — List all OAuth connections for third-party integrations (CRM, storage, etc.). - `integrations_crm_create_contact` — Create a contact in a connected CRM. - `integrations_crm_update_contact` — Update a contact in a connected CRM. - `integrations_crm_list_contacts` — List contacts from a connected CRM (HubSpot, Salesforce, Pipedrive, etc.). - `integrations_storage_list_files` — List files from a connected storage provider (Google Drive, Dropbox, OneDrive). - `integrations_storage_download` — Download a file from a connected storage provider. Every tool publishes a JSON Schema for its input. Read `/.well-known/mcp.json` for the schemas. ### Example: using tools Once connected, ask the model to: - "Take a screenshot of example.com" - "Extract product data from this URL" - "Send an email to user@example.com" - "Upload this image to the CDN" - "Run my content-pipeline workflow" ### Rate limits MCP requests share the API rate limit: 200 requests per 60 seconds per IP. Responses carry the standard `RateLimit`, `RateLimit-Policy`, `RateLimit-Limit`, `RateLimit-Remaining`, and `RateLimit-Reset` headers, plus `Retry-After` on a 429. See https://www.stack0.dev/docs/rate-limits. ## Version - TypeScript SDK (`@stack0/sdk`): 0.5.18 - CLI (`@stack0/cli`): 0.1.2 - REST API: v1 — https://api.stack0.dev/v1 - MCP protocol: 2025-11-25 Within API v1 only additive changes ship. A deprecated endpoint keeps working and announces itself with an RFC 9745 `Deprecation` header, an RFC 8594 `Sunset` header, and a `Link; rel="deprecation"` pointing at the migration note. Minimum notice before sunset is 12 months for a stable endpoint. Full policy: https://www.stack0.dev/docs/versioning ## Suite apps: Analytics and Feedback Analytics and Feedback are hosted applications, not SDK modules. There is no package to install and no `@stack0/sdk` import for either. You integrate them with a script tag and plain HTTP POSTs. ### Stack0 Analytics — analytics.stack0.dev Pageviews joined to signups and payments, cookieless by default. Docs: https://www.stack0.dev/docs/products/analytics Machine-readable: https://analytics.stack0.dev/llms.txt, /openapi.json, /mcp.json Install: ``. The site key is public. Error capture and Core Web Vitals are on by default (data-errors="off", data-vitals="off"). Anywhere you control the server, relay beacons through your own origin. The Analytics CORS allowlist names its own origin, so a browser on your domain has its beacon refused by the preflight, and a refused preflight is indistinguishable from "no traffic yet". The relay also survives ad blockers and preserves visitor geography. In a Pylon app the relay is a FUNCTION, not a route: `/api/fn/*` is Pylon's own namespace, so `app/api/fn/ingestEvent/route.ts` is never matched and there is no next.config.js. Write `functions/ingestEvent.ts` as an action with auth "public" that forwards `ctx.request.rawBody` to `https://analytics.stack0.dev/api/fn/ingestEvent`, copies the user-agent, x-forwarded-for and geo headers, and returns the upstream JSON verbatim (track.js reads visitorId off it). Only actions get `ctx.request`. Serve the tracker first-party from `app/rt/track.js/route.ts`. Full code: https://www.stack0.dev/docs/products/analytics POST /api/fn/ingestEvent: { site, path, name, visitorId, clientType } for server, CLI and mobile events. Never send revenueCents, currency or customerId through it — the site key is public and cannot authenticate money. Revenue: point a Stripe webhook (checkout.session.completed, invoice.payment_succeeded) at /api/fn/stripeRevenue, or RevenueCat at /api/fn/revenueCatRevenue. ### Stack0 Feedback — feedback.stack0.app Feedback boards, votes, comments, roadmaps and changelogs. Docs: https://www.stack0.dev/docs/products/feedback Machine-readable: https://feedback.stack0.app/llms.txt Install: ``. Optional data-label and data-side. Project API (server side): a project API key (s0fb_..., Project settings > API) as Authorization: Bearer. POST JSON to /api/fn/: apiListBoards, apiListPosts { status?, boardId?, search?, limit?, offset? }, apiGetPost { postId }, apiCreatePost, apiUpdatePostStatus, apiAddComment, apiSetVote. 120 requests a minute per key. MCP: the Stack0 products server at https://cloud.stack0.dev/mcp (OAuth sign-in, no key) serves feedback_list_projects, feedback_list_boards, feedback_list_posts, feedback_get_post, feedback_create_post, feedback_update_post_status, feedback_add_comment. Public reads, no credential, POST JSON to /api/fn/: - portalView { slug, boardSlug?, status?, sort?, search?, tagIds?, limit? } — the board, its boards, tags, posts, and the project and board ids the write calls need. sort is one of top, new, trending, discussed. Returns null for an unknown, unpublished or archived portal. - portalPostView { slug, postId } — one request with its public comments and status history. - portalRoadmapView { slug } — planned, in progress, completed. - portalChangelogView { slug, limit? } — published entries only. - similarPosts { slug, title } — existing requests matching a title. These payloads are built field by field, so internal notes, submitter emails and unpublished entries are never in them. Writing on a person's behalf needs a session, not a key: POST /api/auth/guest returns { token }, then send `authorization: Bearer `. - submitPost { projectId, boardId, title, body, name?, email? } - toggleVote { postId } - addComment { postId, body, parentId?, name?, email? } Call similarPosts first and vote on a match instead of filing a duplicate. Changing a board (setPostStatus, mergePost, saveChangelogEntry, publishChangelogEntry, and the project, board and tag functions) requires a signed-in member of the owning workspace. --- *Stack0 is an AI-native infrastructure platform. This document helps AI assistants understand Stack0's products and guide users in using our services effectively.*