ShipSafe AI-SaaS extends the core ShipSafe boilerplate with powerful AI capabilities, making it easy to build AI-powered SaaS products like chatbots, assistants, and AI tools.

What's Included

The AI-SaaS boilerplate provides:

  • Unified AI Client - Support for OpenAI and Anthropic models
  • Streaming Responses - Real-time AI responses using Server-Sent Events (SSE)
  • Prompt Management - System prompts, templates, and tiered prompt builders
  • Content Moderation - Built-in safety checks and injection prevention
  • Subscription Access Control - Simple subscription-based access for AI features
  • Secure API Routes - Protected endpoints with authentication and rate limiting

Architecture

The AI layer is built on top of ShipSafe core, providing:

┌─────────────────────────────────────┐ │ AI-SaaS Application │ │ (Your Product) │ └──────────────┬──────────────────────┘ │ ┌──────────────▼──────────────────────┐ │ AI Layer │ │ - Client (OpenAI/Anthropic) │ │ - Streaming │ │ - Prompts (Tiered) │ │ - Moderation │ │ - Subscription Access │ └──────────────┬──────────────────────┘ │ ┌──────────────▼──────────────────────┐ │ ShipSafe Core │ │ - Authentication │ │ - Billing │ │ - Security │ │ - Database │ └─────────────────────────────────────┘

Quick Start

  1. Set up AI API keys in your .env.local:

    OPENAI_API_KEY=sk-...
    ANTHROPIC_API_KEY=sk-ant-...  # Optional
    
  2. Use the AI client in your API routes:

    import { generateChatCompletion } from "@/lib/ai/client";
    
    const response = await generateChatCompletion({
      messages: [{ role: "user", content: "Hello!" }],
    });
    
  3. Check subscription before making requests:

    import { hasActiveSubscription } from "@/features/ai/server";
    
    const hasAccess = await hasActiveSubscription(userId);
    if (!hasAccess) {
      return NextResponse.json({ error: "Subscription required" }, { status: 403 });
    }
    

Documentation Sections

Next Steps