What is a Large Language Model (LLM)?
An LLM is a neural network trained on vast amounts of text to predict and generate human-like language - the technology behind ChatGPT, Claude, and Gemini.
AILLM
Overview
A Large Language Model (LLM) is a type of AI model trained on enormous text datasets to learn statistical patterns in language. Given a sequence of text (a "prompt"), an LLM predicts what text should come next - token by token. Through this simple objective trained at massive scale, LLMs develop the ability to write code, answer questions, summarise documents, translate languages, and reason through problems.
Key Points
- •LLMs are trained by predicting the next token - a process called self-supervised learning on internet-scale text.
- •The "large" refers to billions or trillions of parameters (learned weights) in the neural network.
- •Training is extremely expensive (millions of dollars); inference (using the model) is much cheaper.
- •Popular LLMs: GPT-4o (OpenAI), Claude 3.5 Sonnet (Anthropic), Gemini 1.5 (Google), LLaMA 3 (Meta, open weights).
- •LLMs do not "know" facts - they learned statistical patterns. This is why they can confidently produce wrong answers (hallucinations).
- •Modern LLMs are fine-tuned with RLHF (Reinforcement Learning from Human Feedback) to follow instructions and be helpful.
Examples
Calling an LLM via API (OpenAI SDK)
typescriptimport OpenAI from 'openai';
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const response = await client.chat.completions.create({
model: 'gpt-4o',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain what a transformer is in 2 sentences.' },
],
});
console.log(response.choices[0].message.content);Calling an LLM via API (Anthropic SDK)
typescriptimport Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const message = await client.messages.create({
model: 'claude-sonnet-4-6',
max_tokens: 1024,
messages: [
{ role: 'user', content: 'Explain what a transformer is in 2 sentences.' }
],
});
console.log(message.content[0].text);Streaming responses token by token
typescriptconst stream = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Write a short poem.' }],
stream: true,
});
for await (const chunk of stream) {
const delta = chunk.choices[0]?.delta?.content ?? '';
process.stdout.write(delta); // prints tokens as they arrive
}Streaming makes responses feel faster because the UI can display tokens as they are generated, rather than waiting for the full response.
Pro Tip
When building on top of LLMs, think of them as probabilistic text completion engines, not databases. They are best at transformation tasks (rewrite, summarise, translate, format) and reasoning tasks with clear instructions. Always validate outputs for factual claims or data extraction.