AI
Pass

Build an AI Email Triage App - Complete SDK Tutorial

Build an AI Email Triage App - Complete SDK Tutorial

Learn how to build an AI-powered email triage app with the AI Pass SDK. Automatically categorize emails by urgency and importance in seconds.

What You'll Build

A complete email triage web app that:

  • Categorizes emails (urgent, important, newsletters, spam)
  • Prioritizes messages by importance
  • Exports sorted results
  • Works instantly with zero backend setup

Prerequisites

  • Basic HTML/JavaScript knowledge
  • An AI Pass account (free signup)
  • 5 minutes

Step 1: Get Your API Credentials

  1. Sign up at AI Pass — you'll get $1 free credit
  2. Go to Developer DashboardOAuth2 Clients
  3. Click Create New Client and give it a name
  4. Copy your Client ID (not the slug!)

The Client ID looks like: client_abc123xyz456

Step 2: Initialize the SDK

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

Step 3: Triage Emails

async function triageEmails(emails) {
  const emailText = emails.map(e => 
    `From: ${e.from}\nSubject: ${e.subject}\nBody: ${e.body}\n\n`
  ).join('---\n');

  const r = await aipass.apikey.v1.chat.completions({
    model: 'openai/gpt-4.1-mini',
    messages: [
      {
        role: 'system',
        content: `You are an expert email assistant. Categorize each email into:
1. Urgent: time-sensitive, needs immediate action
2. Important: should read but can wait
3. Newsletter: bulk content, skim later
4. Spam: can safely ignore

Analyze sender, subject, body, and urgency cues. Return JSON: {categories: [{index, category, reason}]}` 
      },
      {
        role: 'user',
        content: `Triage these emails:\n${emailText}`
      }
    ],
    temperature: 1,
    max_tokens: 16000
  });

  const result = r.choices[0].message.content;
  return JSON.parse(result);
}

Step 4: Build the UI

<!DOCTYPE html>
<html>
<head>
  <title>AI Email Triage</title>
  <script src="https://aipass.one/aipass-sdk.js"></script>
  <style>
    body { font-family: system-ui; max-width: 900px; margin: 40px auto; padding: 20px; }
    textarea { width: 100%; height: 200px; padding: 12px; font-size: 14px; }
    button { padding: 12px 24px; background: #007AFF; color: white; border: none; cursor: pointer; }
    .category { padding: 10px; margin: 10px 0; border-radius: 8px; }
    .urgent { background: #ffebee; border-left: 4px solid #f44336; }
    .important { background: #fff3e0; border-left: 4px solid #ff9800; }
    .newsletter { background: #e3f2fd; border-left: 4px solid #2196f3; }
    .spam { background: #f5f5f5; border-left: 4px solid #9e9e9e; }
  </style>
</head>
<body>
  <h1>AI Email Triage</h1>
  <p>Paste your emails (one per line, format: From|Subject|Body)</p>
  
  <textarea id="emailInput" placeholder="john@example.com|Meeting Tomorrow|Let's meet at 10am...&#10;jane@example.com|Newsletter|Weekly updates..."></textarea>
  <br><br>
  <button onclick="triage()">Triage Emails</button>
  
  <div id="results" style="margin-top: 30px;"></div>

  <script>
    const aipass = new AIPass({
      clientId: 'YOUR_CLIENT_ID',
      requireLogin: true
    });

    async function triage() {
      const input = document.getElementById('emailInput').value;
      const emails = input.split('\n').filter(e => e.trim()).map(line => {
        const [from, subject, body] = line.split('|');
        return { from, subject, body };
      });

      const result = await triageEmails(emails);
      displayResults(result);
    }

    async function triageEmails(emails) {
      const emailText = emails.map(e => 
        `From: ${e.from}\nSubject: ${e.subject}\nBody: ${e.body}\n\n`
      ).join('---\n');

      const r = await aipass.apikey.v1.chat.completions({
        model: 'openai/gpt-4.1-mini',
        messages: [
          {
            role: 'system',
            content: `Categorize emails into: urgent, important, newsletter, spam. Return JSON: {categories: [{index, category, reason}]}` 
          },
          {
            role: 'user',
            content: `Triage:\n${emailText}`
          }
        ],
        temperature: 1,
        max_tokens: 16000
      });

      return JSON.parse(r.choices[0].message.content);
    }

    function displayResults(result) {
      const container = document.getElementById('results');
      container.innerHTML = result.categories.map(c => 
        `<div class="category ${c.category.toLowerCase()}">${c.reason}</div>`
      ).join('');
    }
  </script>
</body>
</html>

Revenue Opportunity: 50% Commission

Earn 50% commission on every API call made through your app. Build once, earn forever.

Cost

  • Text classification: ~$0.001 per 100 emails
  • $1 free credit = 100,000 emails

Live Demo

AI Email Triage

Get Started

Sign up — $1 free credit