/** * 🔑 Sovereign AIRA API Key Generation Gateway (Vercel Serverless - ES Module) * Generates verified API keys for Free & Pro Aira Models * Engineered for Aira Group of Technology (airaaigroup.in) * Founder & CEO: Er. Adam Eehan */ import crypto from "crypto"; const SECRET = process.env.OTP_SECRET || "aira-sovereign-otp-secret-token-2026-secure"; const HOSTINGER_MAIL_TOKEN = process.env.HOSTINGER_MAIL_TOKEN || "c25fc077cafee320ad909052ce3175dd03977fe036b26eb8037f925b639a18b8"; const MAILBOX_ID = process.env.HOSTINGER_MAILBOX_ID || "AC87b5add2c51357fcc7fa29fae989"; const BOSS_EMAIL = "adameehan34@gmail.com"; const PAID_MODELS = ["aira-3-ultra", "aira-deepmind", "aira-cyber-defender"]; const MODEL_LABELS = { "aira-flash-1.5": "Aira Flash 1.5 (Free Community)", "aira-flash-lite": "Aira Flash Lite (Free High-Speed)", "aira-3-ultra": "Aira 3 Ultra (Flagship Engine v3.6 - Pro)", "aira-deepmind": "AiraDeepMind (550B MoE Swarm - Pro)", "aira-cyber-defender": "Aira Cyber Defender AI (7B Core - Pro)" }; function getKeyDeliveryHtml(name, apiKey, model, expiryDate, tier) { const modelName = MODEL_LABELS[model] || model; return ` Your AIRA AI API Credentials
Aira Group Logo
AIRA GROUP OF TECHNOLOGY
Sovereign AI REST API Developer Console
${tier.toUpperCase()} ACTIVE
PROVISIONED API CREDENTIALS

Your API Key is Ready

Hello ${name}, your access token for ${modelName} has been provisioned on the Aira Sovereign Neural Cluster.

API Secret Key
${apiKey}
Model: ${model} Expires: ${expiryDate}
Quick Start Integration (cURL)
curl https://airaai-8ibs.onrender.com/v1/chat/completions \\
  -H "Authorization: Bearer ${apiKey}" \\
  -H "Content-Type: application/json" \\
  -d '{
    "model": "${model}",
    "messages": [{"role": "user", "content": "Hello Aira!"}]
  }'

Keep your secret key confidential. Never expose it in client-side repositories or public frontends.

Aira Group of Technology • Sovereign AI & Systems Architecture

Founder & CEO: Er. Adam Eehan • airaaigroup.in • noreply@airaaigroup.in

`; } export default async function handler(req, res) { res.setHeader("Access-Control-Allow-Origin", "*"); res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS"); res.setHeader("Access-Control-Allow-Headers", "Content-Type"); if (req.method === "OPTIONS") { return res.status(200).end(); } if (req.method !== "POST") { return res.status(405).json({ success: false, error: "Method not allowed. Use POST." }); } try { const { keyName, model, expiry, email, proof, paymentId } = req.body || {}; if (!email || !email.includes("@")) { return res.status(400).json({ success: false, error: "Verified email address is required." }); } const cleanEmail = email.trim().toLowerCase(); const cleanKeyName = (keyName && keyName.trim()) ? keyName.trim() : "Default API Client"; const selectedModel = model || "aira-flash-1.5"; const selectedExpiry = expiry || "30d"; // 1. Verify Cryptographic Proof from OTP verification if (!proof) { return res.status(401).json({ success: false, error: "Email verification proof is missing. Please verify your email with OTP." }); } const proofParts = proof.split(":"); if (proofParts.length !== 2) { return res.status(401).json({ success: false, error: "Invalid verification proof format." }); } const [proofExpiryStr, expectedSig] = proofParts; const proofExpiry = parseInt(proofExpiryStr, 10); if (Date.now() > proofExpiry) { return res.status(401).json({ success: false, error: "Email verification has expired. Please verify with OTP again." }); } const computedSig = crypto.createHmac("sha256", SECRET) .update(`${cleanEmail}:verified:${proofExpiry}`) .digest("hex"); if (computedSig !== expectedSig) { return res.status(401).json({ success: false, error: "Invalid verification signature. Please verify with OTP again." }); } // 2. Check Tier (Free vs Paid) const isPaid = PAID_MODELS.includes(selectedModel); if (isPaid && !paymentId) { return res.status(402).json({ success: false, error: "Payment required for Flagship Sovereign Models (Aira 3 Ultra, AiraDeepMind, Aira Cyber Defender). Please complete monthly subscription via UPI / QR." }); } // 3. Generate Sovereign API Key let apiKey = ""; if (isPaid) { apiKey = "airaaixak_pro_" + crypto.randomBytes(14).toString("hex"); } else { apiKey = "airaaixak" + crypto.randomBytes(14).toString("hex"); } // 4. Calculate Expiry Date string let expiryDateStr = "Never (Permanent)"; const now = new Date(); if (selectedExpiry === "30d") { const exp = new Date(now.getTime() + 30 * 24 * 60 * 60 * 1000); expiryDateStr = exp.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" }); } else if (selectedExpiry === "90d") { const exp = new Date(now.getTime() + 90 * 24 * 60 * 60 * 1000); expiryDateStr = exp.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" }); } else if (selectedExpiry === "365d") { const exp = new Date(now.getTime() + 365 * 24 * 60 * 60 * 1000); expiryDateStr = exp.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" }); } // 5. Send API Key to User's Email via Hostinger Mail API try { fetch(`https://api.mail.hostinger.com/api/v1/mailboxes/${MAILBOX_ID}/send`, { method: "POST", headers: { "Authorization": `Bearer ${HOSTINGER_MAIL_TOKEN}`, "Content-Type": "application/json", "User-Agent": "Aira-Portal/1.0" }, body: JSON.stringify({ to: [cleanEmail], displayName: "Aira Group of Technology", subject: `🚀 Your AIRA AI API Credentials [${selectedModel}]`, html: getKeyDeliveryHtml(cleanKeyName, apiKey, selectedModel, expiryDateStr, isPaid ? "Pro" : "Free") }) }).catch(err => console.warn("[Key Delivery] Email error:", err.message)); } catch (_) {} // 6. Alert Er. Adam Eehan try { fetch("https://formsubmit.co/ajax/" + BOSS_EMAIL, { method: "POST", headers: { "Content-Type": "application/json", "Accept": "application/json" }, body: JSON.stringify({ _subject: `🔑 New API Key Issued: ${selectedModel} (${isPaid ? "PRO PAID" : "FREE"})`, KeyName: cleanKeyName, Email: cleanEmail, Model: selectedModel, Tier: isPaid ? "PRO Monthly Subscription" : "Free Community", PaymentRef: paymentId || "N/A (Free)", Expiry: expiryDateStr, ApiKeyPreview: apiKey.substring(0, 15) + "..." }) }).catch(() => {}); } catch (_) {} return res.status(200).json({ success: true, apiKey: apiKey, keyName: cleanKeyName, model: selectedModel, tier: isPaid ? "pro" : "free", expiryDate: expiryDateStr, email: cleanEmail, endpoint: "https://airaai-8ibs.onrender.com/v1/chat/completions" }); } catch (err) { console.error("[Generate Key Error]:", err); return res.status(500).json({ success: false, error: "Internal server error: " + err.message }); } }