AI Hints
Home›LangChain Tutorial›Getting Started
LangChain · Lesson 3 of 120

Setting Up

Packages and a key.

⏱ 2 min read▶ Video at 2:03🎓 Free
Watch this lesson in the LangChain courseWatch on YouTube ↗Full LangChain course

To follow along, you need Python, a few packages, and an API key for a model. We'll use Google's Gemini, because it has a free tier, but every example works with other providers too.

Setting Up
From the video: Setting Up
  • Python
  • A few packages
  • An API key

Installing the packages

In your terminal, install two packages with pip. Lang chain is the main library. Lang chain google gen AI connects it to Gemini. Then get a free key from Google AI Studio, and store it in an environment variable called google API key.

terminalpython
pip install langchain langchain-google-genai

# get a key at aistudio.google.com, then:
export GOOGLE_API_KEY="your-key-here"

Checking the setup

Let's check everything is ready. We print the LangChain version, and whether a key is set, without ever printing the key itself. Run it. Version one point five, and the key is there. Never paste a key into your code, or share it.

check_setup.pypython
import os
import langchain

print("LangChain version:", langchain.__version__)
has_key = bool(os.environ.get("GOOGLE_API_KEY") or os.environ.get("GEMINI_API_KEY"))
print("API key set:", has_key)
Output
LangChain version: 1.5.0
API key set: True

Summary

Install langchain and langchain google gen AI, and keep your key in an environment variable. Next, your first model call.

Key takeaways
  • pip install
  • Key in an environment variable
  • Never in your code
Next up: Your First Model Call — init_chat_model