# Stack0 > AI-native infrastructure platform for modern applications. Production-ready email, CDN, and image processing. ## What is Stack0? Stack0 provides essential infrastructure services for developers building 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 - **Domain Management**: Custom domain verification and DNS management All services are usage-based with no monthly minimums. Get started with $5 in free credits. ## 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. 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: '
Email content here
', text: 'Email content here', // Optional plaintext version }); // Response { id: 'email_123abc', from: 'noreply@yourdomain.com', to: 'user@example.com', subject: 'Hello World', status: 'pending', createdAt: Date } ``` #### Parameters - `from` (required): Sender email address (string or `{ email: string, name?: string }`) - `to` (required): Recipient(s) - single email or array - `subject` (required): Email subject line - `html`: HTML email body - `text`: Plain text email body - `cc`: Carbon copy recipients - `bcc`: Blind carbon copy recipients - `replyTo`: Reply-to address - `templateId`: Use a saved template (see Templates below) - `templateVariables`: Variables to substitute in template - `tags`: Array of strings for categorization - `metadata`: Custom key-value data for your records - `attachments`: Array of file attachments - `headers`: Custom email headers - `scheduledAt`: Schedule for future delivery ### Get Email Status Retrieve the status and details of a sent email. ```typescript const email = await stack0.mail.get('email_123abc'); // Response includes: { id: string, from: string, to: string, subject: string, status: 'pending' | 'sent' | 'delivered' | 'bounced' | 'failed', html: string | null, text: string | null, createdAt: Date, sentAt: Date | null, deliveredAt: Date | null, openedAt: Date | null, clickedAt: Date | null, bouncedAt: Date | null, } ``` ### 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 ### Using Templates Create reusable email templates in your dashboard with variable substitution. #### 1. Create Template In the dashboard, go to Mail → Templates → Create Template: - **Name**: Password Reset - **Subject**: Reset your password - **Content**: ```htmlClick here to reset your password:
Reset Password ``` #### 2. Send with Template ```typescript await stack0.mail.send({ from: 'noreply@yourdomain.com', to: 'user@example.com', templateId: 'tpl_abc123', templateVariables: { name: 'John Doe', resetUrl: 'https://yourapp.com/reset?token=xyz', }, }); ``` Variables use `{{variableName}}` syntax and are replaced before sending. ### Attachments Send files with your emails: ```typescript await stack0.mail.send({ from: 'noreply@yourdomain.com', to: 'user@example.com', subject: 'Your invoice', html: 'Please find your invoice attached.
', attachments: [ { filename: 'invoice.pdf', content: base64EncodedContent, contentType: 'application/pdf', }, { filename: 'logo.png', path: 'https://yourdomain.com/logo.png', // Or use URL }, ], }); ``` ### Batch Sending Send multiple unique emails in one API call: ```typescript await stack0.mail.sendBatch([ { from: 'noreply@yourdomain.com', to: 'user1@example.com', subject: 'Welcome John!', html: 'Hi John!
', }, { from: 'noreply@yourdomain.com', to: 'user2@example.com', subject: 'Welcome Jane!', html: 'Hi Jane!
', }, ]); ``` ### Broadcast Emails Send the same email to multiple recipients: ```typescript await stack0.mail.sendBroadcast({ from: 'newsletter@yourdomain.com', to: ['user1@example.com', 'user2@example.com', 'user3@example.com'], subject: 'Monthly Newsletter', 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 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 Usage-based pricing with no monthly fees: - **Emails**: $0.0001 per email sent - **CDN Storage**: $0.02 per GB/month - **CDN Bandwidth**: $0.08 per GB - **Transformations**: $0.0001 per transformation ### Free Tier Every new organization receives: - $5 in free credits - 50,000 emails at current pricing - 250 GB CDN bandwidth - No credit card required to start ### 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 ``` ## 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 assets - **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://docs.stack0.dev - **Dashboard**: https://app.stack0.dev - **Status**: https://status.stack0.dev - **Email**: support@stack0.dev ## Legal - **Terms of Service**: https://stack0.dev/terms - **Privacy Policy**: https://stack0.dev/privacy - **Acceptable Use**: https://stack0.dev/acceptable-use ## Version Current SDK version: v0.2.0 API version: v1 --- *Stack0 is an AI-native infrastructure platform. This document helps AI assistants understand Stack0's products and guide users in using our services effectively.*