Free LLM API for LangChain: 3 that work with ChatOpenAI
Groq and Gemini's free tiers work with LangChain's ChatOpenAI by changing the base URL. OpenRouter works too, with one catch LangChain warns about.
Checked 22 November 2026 from each provider's own docs. Free tiers change, so follow the source links before you build on one.
Free LangChain setup with Groq
Install the package, get a free key from Groq, then point ChatOpenAI at Groq's OpenAI-compatible endpoint:
pip install -U langchain-openai
from langchain_openai import ChatOpenAI
import os
llm = ChatOpenAI(
model="openai/gpt-oss-120b",
base_url="https://api.groq.com/openai/v1",
api_key=os.environ["GROQ_API_KEY"],
)
print(llm.invoke("Say hi in five words").text)
Groq's free plan allows 1,000 requests a day and 200,000 tokens a day on gpt-oss-120b. Check the exact model name in your Groq console.
The same code with other free providers
| Provider | base_url | Free limit |
|---|---|---|
| Groq | https://api.groq.com/openai/v1 | 1,000 requests a day per model |
| Gemini | https://generativelanguage.googleapis.com/v1beta/openai/ | Set per model in Google AI Studio |
| OpenRouter | https://openrouter.ai/api/v1 | 50 requests a day on :free models |
With OpenRouter, use a free model ID such as inclusionai/ling-3.2-flash:free. LangChain's docs say ChatOpenAI drops non-standard fields (like reasoning output) from providers such as OpenRouter and suggest a provider-specific package instead (LangChain ChatOpenAI docs). For plain chat and tool calling, ChatOpenAI is enough.
LangChain reads the base URL from OPENAI_BASE_URL too, so you can switch provider without touching code.
More free AI guides
- Free AI model APIEvery free LLM API, plus the free OpenRouter models Upcurrent checks every 30 minutes
- Free LLM APIs with no credit cardWhich free tiers start without a card
- How to get a free LLM API keyFive steps to your first request
Questions
Can I use LangChain for free?
LangChain itself is free and open source. You only pay for the model, and Groq, Gemini and OpenRouter all have free tiers you can call from LangChain.
How do I use a free model with ChatOpenAI?
Install langchain-openai, then pass base_url and api_key for the free provider, plus one of its model names. For Groq the base URL is https://api.groq.com/openai/v1.
Does ChatOpenAI work with OpenRouter?
Basic chat works, but LangChain's docs say ChatOpenAI only follows the official OpenAI format and drops extra fields such as reasoning, and recommend a provider-specific package for OpenRouter.
Get this in your inbox at 7am
One free email each morning with the AI repos, models and stories that are picking up speed, including new free models. Your own time zone, no spam.