LLM APIs Integration in ChatBot

Build your first AI chat application using free LLM APIs. Learn modern web development while creating something amazing in Malaysia.

100% Free APIs
Currently No Login Required
Beginner Friendly

AI Assistant

Online

How do I create a JavaScript function?

Here's how to create a JavaScript function:

function greetUser(name) {
  return `Hello, ${name}!`;
}
3+
Free APIs
Fast Setup
🎓
Educational
🚀
Production Ready
How It Works

Follow the journey of a single message through our AI chat system in just 4 simple steps

1

User Input

User types a message in the chat interface. The message is captured by the JavaScript event listener.

Event Listener
messageInput.addEventListener('keydown')
💡 Learn: DOM Event Handling
2

API Request

Your message is formatted into a JSON payload and sent to the LLM API endpoint using the Fetch API.

HTTP Request
fetch(endpoint, { method: 'POST', ... })
🌐 Learn: HTTP & JSON
3

LLM Processing

The AI model (like Llama 3.1 or Mixtral) processes your message and generates an intelligent response.

Model Config
model: "llama-3.1-8b-instant"
🤖 Learn: AI Models
4

Display Response

The AI's response is extracted from the API response and displayed in the chat interface with formatting.

DOM Update
addMessage('assistant', response)
Learn: Dynamic UI

API Setup Guide

Choose from multiple free LLM APIs - no credit card required!

OpenRouter

Access to many models

Multiple free models available
Easy model switching
OpenAI-compatible API
Great for experimentation

Setup Steps:

  1. Visit openrouter.ai
  2. Create a free account
  3. Navigate to "Keys" section
  4. Generate a new API key
  5. Copy and use in the app
Get OpenRouter Key

Hugging Face

Thousands of models

Largest model library
Free inference API
Great for learning
Research-friendly

Setup Steps:

  1. Visit huggingface.co
  2. Create a free account
  3. Go to Settings → Access Tokens
  4. Create a new token (Read permissions)
  5. Copy and use in the app
Get HF Token

Quick Comparison

Feature Groq OpenRouter Hugging Face
Response Speed ⚡ Fastest Fast Moderate
Free Tier 14,400 req/day Limited free models Rate limited
Setup Difficulty ⭐ Easiest Easy Easy
Model Selection 5+ models 100+ models 1000+ models
Credit Card Required ❌ No ❌ No ❌ No

What You'll Learn

Master essential web development and AI integration concepts

API Integration

Learn how to make HTTP requests, handle responses, and integrate external APIs into your applications.

Async JavaScript

Master asynchronous programming with Promises, async/await, and the Fetch API for modern web development.

DOM Manipulation

Dynamically create and update page elements, handle user interactions, and build responsive UIs.

Error Handling

Implement robust error handling, user feedback, and graceful failure recovery in your applications.

Canvas API

Create beautiful animations and interactive graphics using HTML5 Canvas and JavaScript animation loops.

API Security

Understand API key management, security best practices, and protecting sensitive credentials.

Data Persistence

Use localStorage and browser storage APIs to save user preferences and application state.

Modern CSS

Build beautiful UIs with modern CSS techniques, animations, custom properties, and responsive design.