AI
Pass

Build a Photo to Cartoon App with AI Pass SDK

Build a Photo to Cartoon App with AI Pass SDK

Learn how to build a photo-to-cartoon transformation application using the AI Pass platform. This tutorial covers everything from signup to deployment.

Prerequisites

  • Basic knowledge of HTML, CSS, and JavaScript
  • A code editor (VS Code, Sublime Text, etc.)
  • A modern web browser

Step 1: Sign Up for AI Pass

  1. Go to AI Pass
  2. Click "Sign Up" and create your account
  3. You'll receive $1 free credit on signup to test the platform

Step 2: Get Your Client ID

  1. Navigate to the Developer Dashboard
  2. Go to OAuth2 Clients section
  3. Click "Create New Client"
  4. Give your app a name (e.g., "My Photo to Cartoon")
  5. Copy your Client ID — you'll need this for the SDK

Important: Keep your Client ID secure. In production, use environment variables.

Step 3: Include the AI Pass SDK

Add the AI Pass SDK to your HTML file:

<script src="https://aipass.one/aipass-sdk.js"></script>

Step 4: Initialize the SDK

Initialize the SDK with your Client ID and enable user authentication:

// Initialize AI Pass SDK
const client = new AiPass({
  clientId: 'YOUR_CLIENT_ID',
  requireLogin: true  // Requires users to log in to use your app
});

// Check if user is authenticated
client.on('ready', () => {
  console.log('SDK ready, user authenticated:', client.isAuthenticated());
});

Step 5: Create the Photo-to-Cartoon Function

Use the AI Pass API to transform photos into cartoons:

async function cartoonizePhoto(imageFile, cartoonStyle) {
  try {
    // Check user credits before processing
    const credits = await client.getUserCredits();
    if (credits.available < 1) {
      alert('Not enough credits. Please upgrade your plan.');
      return null;
    }

    // Convert image to base64
    const reader = new FileReader();
    const base64Image = await new Promise((resolve) => {
      reader.onload = () => resolve(reader.result);
      reader.readAsDataURL(imageFile);
    });

    // Call the cartoon transformation model via AI Pass
    const result = await client.generateCompletion({
      model: 'gpt-5-mini',
      temperature: 1,
      max_tokens: 16000,
      messages: [
        {
          role: 'system',
          content: 'You are an artistic image processing assistant specializing in photo-to-cartoon transformation. Convert photographs into high-quality cartoon-style artwork. Styles available: classic-comic (bold outlines, flat colors, traditional comic look), modern-anime (soft shading, vibrant colors, anime aesthetic), caricature (exaggerated features, fun and expressive), minimalist (simple shapes, clean lines, minimal detail), retro-cartoon (vintage animation style, warm tones, nostalgic feel).'
        },
        {
          role: 'user',
          content: `Transform this photo to ${cartoonStyle} cartoon style: ${base64Image}`
        }
      ]
    });

    return result;
  } catch (error) {
    console.error('Error cartoonizing photo:', error);
    throw error;
  }
}

Critical: Always include temperature: 1 and max_tokens: 16000 when using GPT-5 models. The SDK defaults (temperature: 0.7, max_tokens: 1000) are incompatible with GPT-5's reasoning process and will result in empty responses.

Step 6: Build the User Interface

Create a simple HTML interface:

<!DOCTYPE html>
<html>
<head>
  <title>Photo to Cartoon</title>
  <style>
    body { font-family: Arial, sans-serif; max-width: 600px; margin: 50px auto; padding: 20px; }
    .upload-area { border: 2px dashed #ccc; padding: 40px; text-align: center; cursor: pointer; }
    .upload-area:hover { border-color: #007bff; }
    .controls { margin: 20px 0; }
    select, button { padding: 10px; margin: 5px; }
    #result { margin-top: 20px; }
    .comparison { display: flex; gap: 10px; }
    .comparison img { flex: 1; max-width: 50%; }
  </style>
</head>
<body>
  <h1>Photo to Cartoon</h1>
  <div class="upload-area" onclick="document.getElementById('fileInput').click()">
    <p>Click to upload a photo</p>
    <input type="file" id="fileInput" accept="image/*" style="display: none" onchange="handleFileUpload(event)">
  </div>

  <div class="controls">
    <select id="cartoonStyle">
      <option value="classic-comic">Classic Comic</option>
      <option value="modern-anime">Modern Anime</option>
      <option value="caricature">Caricature</option>
      <option value="minimalist">Minimalist</option>
      <option value="retro-cartoon">Retro Cartoon</option>
    </select>
    <button onclick="processImage()">Cartoonize</button>
  </div>

  <div id="result"></div>

  <script src="https://aipass.one/aipass-sdk.js"></script>
  <script>
    const client = new AiPass({
      clientId: 'YOUR_CLIENT_ID',
      requireLogin: true
    });

    let uploadedImage = null;

    function handleFileUpload(event) {
      uploadedImage = event.target.files[0];
      if (uploadedImage) {
        document.getElementById('result').innerHTML = `
          <p>Original:</p>
          <img src="${URL.createObjectURL(uploadedImage)}" alt="Original">
        `;
      }
    }

    async function processImage() {
      if (!uploadedImage) {
        alert('Please upload an image first');
        return;
      }

      const style = document.getElementById('cartoonStyle').value;
      const resultDiv = document.getElementById('result');
      resultDiv.innerHTML = '<p>Cartoonizing...</p>';

      try {
        const result = await cartoonizePhoto(uploadedImage, style);
        const styleName = document.getElementById('cartoonStyle').options[document.getElementById('cartoonStyle').selectedIndex].text;
        resultDiv.innerHTML = `
          <div class="comparison">
            <div>
              <p>Original:</p>
              <img src="${URL.createObjectURL(uploadedImage)}" alt="Original">
            </div>
            <div>
              <p>${styleName}:</p>
              <img src="${result.data.cartoonImage}" alt="Cartoon">
            </div>
          </div>
          <br>
          <a href="${result.data.cartoonImage}" download="cartoon-${style}.png">Download Cartoon</a>
        `;
      } catch (error) {
        resultDiv.innerHTML = `<p>Error: ${error.message}</p>`;
      }
    }

    async function cartoonizePhoto(imageFile, cartoonStyle) {
      // ... (function from Step 5)
    }
  </script>
</body>
</html>

Step 7: Deployment Options

Option A: Self-Host Anywhere

Deploy your app to any web hosting service:

  • Netlify - Drag and drop your HTML file
  • Vercel - Connect your Git repository
  • GitHub Pages - Free hosting for static sites
  • Your own server - Nginx, Apache, or any web server

Option B: Publish on AI Pass Catalog

Publish your app to the AI Pass marketplace and earn revenue:

  1. In the Developer Dashboard, go to My Apps
  2. Click "Publish to Catalog"
  3. Set your pricing (per-use or subscription)
  4. Submit for review
  5. Once approved, your app appears in the catalog

Earning Opportunity: You earn 50% commission on all revenue generated through the AI Pass catalog. This includes revenue from users who discover your app through the marketplace.

Step 8: Test Your App

  1. Open your app in a browser
  2. Sign in with your AI Pass account (or create one)
  3. Upload a photo (portraits work best)
  4. Select a cartoon style
  5. Verify the transformation works
  6. Test different styles and image types

Complete Example Code

For a complete working example, check out the AI Pass SDK documentation.

Next Steps

  • Add batch processing for multiple photos
  • Implement cartoon style customization
  • Add face detection and enhancement
  • Create avatar generation mode
  • Publish to the catalog to earn revenue
  • Explore other AI Pass models and APIs

Turn your photos into fun cartoons! 🎨🖼️