Skip to main content
In this section, you will learn how to initialize and invoke LLM Chat Models using LangChain.

Objectives

  1. Understand the differences between raw API integrations and LangChain.
  2. Swapping model providers seamlessly using standard message formatting.

Direct APIs vs. LangChain

Directly writing code against raw LLM provider APIs (like OpenAI, Google, or Anthropic) introduces API fragmentation. Every model provider has its own proprietary SDK, request payload structure, and response format.

1. Direct Provider APIs (Fragmentation)

Every provider requires a unique SDK, setup protocol, and response extraction syntax:
OpenAI Direct API
Google Gemini Direct API
Hugging Face Inference API

2. LangChain’s Simplified & Unified Syntax

LangChain unifies all these disparate APIs behind a single interface. Switching between providers only requires changing model configuration variables:

Next Steps: What We Will Build

Now that you understand the advantages of LangChain’s unified core abstractions, we will implement and analyze five progressively advanced chat model configurations:
  1. Chat Model Basic: Set up and run your first model invocation using unified abstractions.
  2. Chat Model Basic Conversation: Format message arrays with specific system instructions and structured message roles.
  3. Chat Model Alternatives: Swap between OpenAI, Anthropic, Google, and Groq providers effortlessly.
  4. Chat Model Conversation With User: Create an interactive command-line chat session with live memory.
  5. Chat Model Save Message History: Persist your conversation sessions securely inside a Google Cloud Firestore database.

Practice & Exercises

To reinforce what you’ve learned in this section, practice with the interactive notebook:

Practice & Exercises

Practice initializing chat models, building conversations, and managing chat message structures.💻 VS Code | 🚀 Colab | 📥 Download