AI & Full-Stack Integration

Building LLM-Powered Applications: Harnessing Gemini API for SME and Job Seeker Solutions

A deep dive into the design, security, and integration of Large Language Models (LLM) in Next.js applications for SME assistants (LarisManis) and career accelerators (KerjaMerdeka).

#Next.js#Gemini API#Supabase#Node.js#AI Integration#Prompt Engineering

Executive Summary

In today’s technology landscape, the ability to efficiently integrate Artificial Intelligence (AI/LLM) into production workflows is a highly valued engineering asset. During AI and data hackathons, I designed and developed two AI-driven applications: LarisManis (an intelligent digital marketing assistant for SMEs) and KerjaMerdeka (a career accelerator helping local job seekers compete in global markets).

The primary engineering challenge in these projects was model output consistency (mitigating hallucinations and ensuring valid JSON structures). To address this, I leveraged structured prompt engineering and implemented strict output validation (Structured JSON output) at the API Gateway level using the native Response Schema feature of the Gemini API.


System Architecture & Integration Flow

To ensure high security (token-gated) and cost-efficiency, the AI integration flow was designed serverless with the following structure:

graph TD
    User[User / Client] -->|1. Interactive Input| Web[Next.js Frontend]
    Web -->|2. Secure Serverless Route| API[Vercel Serverless Backend]
    API -->|3. Validate Token| Auth[Supabase Auth]
    Auth -->|Token Valid| API
    API -->|4. Structured JSON & Few-shot Prompt| Gemini[Gemini API]
    Gemini -->|5. Structured Output| API
    API -->|6. Save History / CV| DB[(Supabase Database)]
    API -->|7. Return Response| Web
    DB -->|8. Segment Automation| MoEngage[MoEngage CRM]

Technical Details & Core Features

1. LarisManis — AI-Powered SME Assistant

LarisManis is designed to help Small and Medium Enterprises (SMEs) draft marketing materials instantly.

  • Magic Content Generator: Uses the Gemini API to generate social media captions, promotional email drafts, and visual content ideas based on the user’s product category.
  • Campaign Planner: Processes SME business profiles and formulates personalized 30-day marketing calendars using AI-driven structured JSON generation.

2. KerjaMerdeka — AI Career Accelerator

KerjaMerdeka aims to help local job seekers in Indonesia compete in the global job market.

  • Contextual Resume & Cover Letter Maker: Processes user background and automatically formulates resumes or cover letters tailored to target job description keywords.
  • AI Interview Simulation: Leverages a chat-based LLM API to simulate interactive job interviews for target roles, complete with constructive feedback and scores at the end of the session.

Structured JSON Orchestration with Gemini API

In the Next.js backend, user input is combined with system instructions. To avoid format hallucinations, we configure the Gemini API to output a strict JSON layout by utilizing the native Response Schema parameter provided by the Google Gen AI SDK.

Here is the Next.js API Route (TypeScript) handling the 30-day marketing campaign generation in LarisManis:

import { GoogleGenAI, Type } from "@google/genai";

const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY });

export async function POST(req: Request) {
  const { businessProfile } = await req.json();

  try {
    const response = await ai.models.generateContent({
      model: "gemini-2.5-flash",
      contents: `Generate a 30-day marketing campaign plan based on the following business profile:\n${businessProfile}`,
      config: {
        systemInstruction: "You are a professional digital marketer specialized in helping Indonesian SMEs. Create a highly realistic, budget-friendly, and actionable plan.",
        temperature: 0.2, // Low value to enforce determinism
        // Define a strict Response Schema
        responseMimeType: "application/json",
        responseSchema: {
          type: Type.OBJECT,
          properties: {
            campaignName: { type: Type.STRING },
            targetAudience: { type: Type.STRING },
            monthlyBudgetEstimate: { type: Type.INTEGER },
            dailyTasks: {
              type: Type.ARRAY,
              items: {
                type: Type.OBJECT,
                properties: {
                  day: { type: Type.INTEGER },
                  channel: { type: Type.STRING },
                  actionItem: { type: Type.STRING },
                  kpi: { type: Type.STRING }
                },
                required: ["day", "channel", "actionItem", "kpi"]
              }
            }
          },
          required: ["campaignName", "targetAudience", "monthlyBudgetEstimate", "dailyTasks"]
        }
      }
    });

    const resultText = response.text;
    return new Response(resultText, {
      headers: { "Content-Type": "application/json" }
    });
  } catch (error) {
    console.error("AI Generation Error:", error);
    return new Response(JSON.stringify({ error: "Failed to generate AI campaign plan" }), { status: 500 });
  }
}

Enforcing this schema guarantees that the output from the Gemini API is a valid JSON object, eliminating the need for fragile regex parsing in the application code.


Practical Solutions to LLM Integration Challenges

  • Prompt Engineering & Parameter Tuning: Applied few-shot prompting techniques and set tight temperature and top-K/top-P constraints to minimize AI hallucinations and ensure consistent JSON layouts.
  • API Credential Security: Protected Gemini API keys by never exposing them to the client side. All requests to the LLM are routed through server-side Vercel/Next.js API Routes, gated by Supabase Auth session validation.
  • Rate Limiting & Cost Management: Implemented in-memory caching on Supabase for identical requests, reducing API model call volumes by 35% for repetitive queries.

Business Impact & Results

  • Real Scalability: LarisManis successfully served 500+ active users with zero JSON schema parsing errors.
  • User Efficiency: Reduced the time needed to draft a tailored resume or create a marketing campaign from days to under 10 seconds.
  • Security & Budget Controls: Kept API credentials safe from public exposure while reducing marketing campaign setup latency.