n4nAI

Foundation models explained: the GPT-5 and Claude era

A technical definition of foundation models in the GPT-5 and Claude era, covering architecture, training paradigms, and practical implications for engineers building LLM systems.

n4n Team7 min read1,446 words

Audio narration

Coming soon — every post will get a voice note here.

A foundation model is a large neural network trained on broad data at scale that can be adapted to a wide range of downstream tasks without task-specific architecture changes. The term, coined by the Stanford Center for Research on Foundation Models in 2021, distinguishes these models from narrow AI systems built for single purposes. In the GPT-5 and Claude era, this definition has practical teeth: the same base model now powers coding assistants, legal document review, and creative writing through lightweight adaptation rather than retraining.

What makes a model a foundation model

Three properties define the category. First, scale — parameter counts in the hundreds of billions to trillions, trained on terabytes of text, code, and increasingly multimodal data. Second, broad pretraining — the objective is usually next-token prediction on a diverse corpus, not a labeled dataset for a specific task. Third, adaptability — the model exhibits emergent capabilities that transfer to tasks it never explicitly saw during training, accessible through prompting, few-shot examples, or lightweight fine-tuning.

The architecture is almost always a transformer variant. GPT-5 and Claude 4/Opus use decoder-only transformers with modifications: grouped-query attention, rotary positional embeddings, and various normalization schemes (RMSNorm, QKNorm) that stabilize training at scale. The innovation isn’t architectural novelty — it’s the engineering that makes training at this scale reliable: pipeline parallelism, tensor parallelism, sequence parallelism, activation checkpointing, and mixed-precision training with loss scaling.

The training pipeline: pretrain, post-train, align

Understanding foundation models requires distinguishing three phases. Pretraining consumes the vast majority of compute — 95%+ of FLOPs. The model learns statistical regularities of language, code, and reasoning by predicting the next token on a curated corpus (Common Crawl, GitHub, books, arXiv, Wikipedia, plus proprietary data). Data quality filtering, deduplication, and curriculum scheduling matter more than raw volume.

Post-training (sometimes called supervised fine-tuning or SFT) teaches the model to follow instructions and converse. This uses a much smaller, high-quality dataset of (prompt, response) pairs — often 10K–100K examples written by contractors or generated by earlier models. The model learns format, style, and basic instruction following.

Alignment (RLHF, RLAIF, DPO, or variants) optimizes for human preferences. A reward model scores model outputs; the policy is optimized against this reward via PPO, DPO, or simpler contrastive methods. This phase reduces hallucination, improves refusal behavior, and calibrates tone. The distinction matters: a base model completes text; an aligned model assists.

# Conceptual training flow (not runnable)
def train_foundation_model():
    # Phase 1: Pretrain — next-token prediction on massive corpus
    base_model = pretrain(
        corpus=curated_web_corpus(tokens=15_000_000_000_000),
        architecture=TransformerDecoder(
            n_layers=128, d_model=16384, n_heads=128,
            attention="grouped_query", pos_emb="rope"
        ),
        optimizer="AdamW", lr_schedule="cosine_warmup",
        parallelism="3D_parallel", precision="bf16"
    )

    # Phase 2: SFT — instruction following
    sft_model = supervised_finetune(
        base_model,
        dataset=instruction_pairs(n=50_000, quality="expert"),
        epochs=1, lr=1e-5
    )

    # Phase 3: Alignment — preference optimization
    aligned_model = dpo_align(
        sft_model,
        preference_pairs=human_feedback(n=100_000),
        beta=0.1
    )
    return aligned_model

Base vs instruct vs chat: the deployment variants

Engineers interact with foundation models through three common variants, each serving a different integration pattern.

Base models (sometimes called “completion models”) are the raw output of pretraining. They complete whatever prefix you give them. Feed “The quick brown fox” and get “jumps over the lazy dog.” Feed a code snippet and get continuation. They have no concept of “user” or “assistant” — they model the training distribution. Base models are useful when you need maximum controllability (e.g., building your own instruction hierarchy) or when prompting with few-shot examples that don’t fit a chat template.

Instruct models are base models post-trained on instruction-response pairs. They recognize instruction formats: “Write a function that…” → code completion. They don’t necessarily maintain multi-turn conversation state. The instruction format varies by provider: OpenAI uses a chat template with system/user/assistant roles; Anthropic uses a similar but distinct format; open models (Llama, Qwen, Mistral) publish their own chat templates in tokenizer configs.

Chat models are instruct models further optimized for multi-turn dialogue. They track conversation history, maintain persona, and handle context-dependent references (“summarize what I just said”). The distinction between instruct and chat blurs in practice — most released “instruct” checkpoints are chat-capable — but the training emphasis differs.

// Example chat template (Llama 3 style)
{
  "system": "You are a helpful coding assistant.",
  "messages": [
    {"role": "user", "content": "Write a Python decorator for retry logic"},
    {"role": "assistant", "content": "Here's a retry decorator with exponential backoff..."},
    {"role": "user", "content": "Make it async-compatible"}
  ]
}

Why this matters for engineers building systems

The foundation model paradigm shifts the cost structure of AI development. Pretraining is a fixed cost — amortized across all downstream uses. Adaptation is marginal cost — prompting, few-shot, or LoRA fine-tuning on your data. This means:

  • Prototyping is fast. You validate product concepts with prompt engineering before committing to fine-tuning infrastructure.
  • Specialization doesn’t require retraining. A single foundation model serves coding, summarization, extraction, and reasoning tasks through context engineering.
  • Model swaps are viable. If you build against a standard interface (OpenAI-compatible chat completions), you can evaluate GPT-5, Claude Opus, and open-weight alternatives without rewriting application logic.

This is where an inference gateway becomes practical. n4n.ai provides one OpenAI-compatible endpoint addressing 240+ models with automatic fallback when a provider is rate-limited or degraded, per-token usage metering, and forwarding of provider cache-control hints — so you can swap foundation models behind a stable contract.

Concrete example: building a code review agent

Consider a PR review agent that summarizes changes, flags security issues, and suggests tests. Three years ago, this required: a fine-tuned classifier for issue types, a separate summarization model, a retrieval system for security patterns, and orchestration glue. Today, a single foundation model handles all three with structured prompting:

SYSTEM_PROMPT = """You are a senior security engineer reviewing a pull request.
Output a JSON object with exactly these keys:
- summary: 3-bullet summary of changes
- security_issues: list of {file, line, severity, description, cwe_id}
- suggested_tests: list of {test_name, rationale, code_snippet}
Be precise. Cite line numbers. If nothing applies, return empty lists."""

def review_pr(diff: str, context_files: dict[str, str]) -> dict:
    prompt = f"{SYSTEM_PROMPT}\n\nDIFF:\n{diff}\n\nCONTEXT:\n{json.dumps(context_files)}"
    response = client.chat.completions.create(
        model="gpt-5",  # or "claude-opus-4", "llama-3.1-405b-instruct"
        messages=[{"role": "user", "content": prompt}],
        response_format={"type": "json_object"},
        temperature=0.1
    )
    return json.loads(response.choices[0].message.content)

The same prompt works across GPT-5, Claude Opus, and Llama 3.1 405B Instruct with minor temperature and formatting adjustments. You evaluate once, pick the best cost/latency/quality tradeoff, and deploy. When a better foundation model releases, you swap the model string and re-evaluate — no retraining pipeline required.

Common misconceptions

“Foundation models are just big transformers.” Scale enables emergence, but the training recipe — data curation, curriculum, post-training, alignment — determines capability. Two models with identical architecture and parameter count can differ drastically in coding ability, reasoning, and refusal behavior based on data mix and RLHF quality.

“You need to fine-tune for your domain.” For most tasks, prompt engineering + few-shot + RAG outperforms fine-tuning a smaller model, and matches fine-tuning the foundation model at lower cost. Fine-tune when: (a) you need consistent style/format at scale, (b) the task requires knowledge not in the training corpus and RAG latency is unacceptable, or (c) you’re distilling a larger model into a smaller one for edge deployment.

“Context windows solve everything.” A 1M-token context doesn’t eliminate the need for retrieval. It shifts the tradeoff: you can stuff more context, but attention is quadratic (or linear with approximations), so latency and cost scale with context length. RAG remains essential for large codebases, document corpuses, and long-term memory.

“Base models are ‘unaligned’ and dangerous.” Base models reflect their training distribution — they complete internet text, which includes toxic, biased, and factually incorrect content. They’re not “trying” to be harmful; they’re modeling the data. Alignment adds a preference layer. For controlled applications (e.g., internal tooling with vetted prompts), base models can be safer than poorly aligned chat models that over-refuse or hallucinate confidently.

“Open weights = open source.” Most “open” foundation models (Llama, Qwen, Mistral, Gemma) release weights under licenses with commercial restrictions, acceptable use policies, or attribution requirements. The training data, code, and compute are rarely open. Treat them as open-weight, not open-source, and review licenses before production use.

Evaluating foundation models for your use case

Don’t rely on leaderboard rankings alone. Build a task-specific eval set — 50–200 representative inputs with expected outputs or grading rubrics. Test each candidate model with your actual prompts, context construction, and parsing logic. Measure:

  • Task accuracy (exact match, F1, or LLM-as-judge on your rubric)
  • Latency (p50, p99, time-to-first-token for streaming)
  • Cost per 1K tokens (input + output, including cache hits)
  • Failure modes (refusals, format violations, hallucination patterns)
# Minimal eval harness
def evaluate_model(model_id: str, eval_cases: list[dict]) -> dict:
    results = []
    for case in eval_cases:
        pred = call_model(model_id, case["prompt"])
        score = grade(case["expected"], pred, case.get("rubric"))
        results.append({"case_id": case["id"], "score": score, "pred": pred})
    return {
        "model": model_id,
        "mean_score": statistics.mean(r["score"] for r in results),
        "p99_latency_ms": p99_latency(results),
        "cost_usd": total_cost(results)
    }

Run this weekly. Foundation model capabilities shift rapidly — providers update models in place, and new releases change the frontier. An eval harness lets you switch models confidently when the economics or capabilities justify it.

The trajectory: multimodal, agentic, and smaller

Three directions define the next 18 months. Native multimodality — GPT-5 and Claude Opus process images, audio, and text in a single forward pass, not via separate encoders. This enables use cases like “review this architecture diagram” or “debug this screenshot” without orchestration.

Agentic training — post-training now includes tool use, planning, and multi-step reasoning traces. Models emit structured actions (function calls, code execution, search queries) and incorporate results. The boundary between “model” and “agent framework” is dissolving into the model itself.

Distillation and small models — the same training recipes that produce GPT-5-class models also produce 1B–8B parameter models (Llama 3.2 3B, Qwen 2.5 3B, Gemma 2 2B) that run on-device. These aren’t “compressed” versions — they’re trained from scratch with better data and longer training runs, inheriting reasoning patterns from their larger siblings via synthetic data distillation.


Foundation models explained simply: they’re general-purpose reasoning engines you adapt through context, not architecture. The engineering challenge has moved from training models to selecting, prompting, evaluating, and orchestrating them. Build your eval harness, standardize your interface, and treat model choice as a runtime decision — not a strategic commitment.

Tagsfoundation-modelsgpt-5claude

Written by

n4n Team

The team building n4n — a single OpenAI-compatible API in front of 240+ models, with automatic fallback, load balancing and pay-per-token metering.

More from n4n Team →

All foundation models: base vs instruct vs chat posts →