cd /news/artificial-intelligence/running-nvidia-nemotron-on-langchain… Β· home β€Ί topics β€Ί artificial-intelligence β€Ί article
[ARTICLE Β· art-2547] src=dev.to β†— pub= topic=artificial-intelligence verified=true sentiment=↑ positive

Running Nvidia Nemotron on LangChain via OpenRouter

Step-by-step guide on how to build a LangChain agent that utilizes Nvidia's free Nemotron AI models via the OpenRouter platform. It covers the entire setup process, from installing necessary packages and configuring API keys to creating a simple tool-calling agent that can execute functions like retrieving weather data. The guide also offers tips for expanding the agent with multiple tools and suggests other free models for further experimentation.

read4 min views15 publishedMay 20, 2026

Nvidia's Nemotron models are powerful, free-to-use AI models available through OpenRouter. In this guide, you'll learn how to set up a LangChain agent that uses Nemotron β€” from installing packages to running your first tool-calling agent.

What Are We Building? #

A simple LangChain agent that:

  • Uses Nvidia Nemotron as its brain (via OpenRouter's free tier) - Has access to a custom tool(a weather function) - Answers questions by calling that tool automatically

Prerequisites #

Step 1 β€” Get Your OpenRouter API Key #

OpenRouter gives you free access to many models, including Nvidia's Nemotron family, with no credit card required.

Step 2 β€” Set Up Your Project #

Create a new project folder and initialize it:

mkdir my-nemotron-agent
cd my-nemotron-agent
uv init

Or if you're using pip, just create a folder and a virtual environment:

mkdir my-nemotron-agent
cd my-nemotron-agent
python -m venv .venv
.venv\Scripts\activate   # Windows

Step 3 β€” Install Dependencies #

uv add langchain langchain-openrouter python-dotenv

Or with pip:

pip install langchain langchain-openrouter python-dotenv

These three packages are all you need:

langchainβ€” the agent framework - langchain-openrouterβ€” connects LangChain to OpenRouter's API - python-dotenvβ€” loads your API key from a.env

file safely

Step 4 β€” Store Your API Key #

Create a .env

file in your project folder (never commit this to Git!):

OPENROUTER_API_KEY=your-key-here

Also create a .gitignore

to protect it:

.env
.venv

Step 5 β€” Choose a Nemotron Model #

OpenRouter hosts several free Nvidia Nemotron models. Here are the main ones:

Model ID Best For
Nemotron 3 Nano 30B nvidia/nemotron-3-nano-30b-a3b:free
Fast, general tasks
Nemotron 3 Super 120B nvidia/nemotron-3-super-120b-a12b:free
Complex reasoning
Nemotron Nano 9B V2 nvidia/nemotron-nano-9b-v2:free
Lightweight tasks

Note:The:free

suffix is required. Without it, OpenRouter will look for a paid endpoint.

For beginners, nvidia/nemotron-3-nano-30b-a3b:free

is a great starting point β€” it's fast and capable.

Step 6 β€” Write Your Agent #

Create a file called main.py

:

from dotenv import load_dotenv
from langchain.agents import create_agent

load_dotenv()

def get_weather(city: str) -> str:
    """Get weather for a given city."""
    return f"It's always sunny in {city}!"

agent = create_agent(
    model="openrouter:nvidia/nemotron-3-nano-30b-a3b:free",
    tools=[get_weather],
    system_prompt="You are a helpful assistant",
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]}
)

print(result["messages"][-1].content)

How It Works

load_dotenv()

reads your.env

file and sets theOPENROUTER_API_KEY

environment variable - get_weather

is a regular Python function β€” LangChain uses itsdocstring to describe the tool to the model - create_agent

wires everything together: the model, the tools, and the system prompt - agent.invoke(...)

sends the user's message and returns a result dict - result["messages"][-1].content

gets the final text response from the last message

Step 7 β€” Run It #

uv run main.py

Or with pip/venv:

python main.py

You should see something like:

The weather in San Francisco is sunny!

Step 8 β€” Add More Tools #

You can give your agent multiple tools β€” just add more functions to the list:

def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"It's always sunny in {city}!"

def get_population(city: str) -> str:
    """Get the population of a city."""
    populations = {
        "San Francisco": "870,000",
        "New York": "8,300,000",
        "Dhaka": "21,000,000",
    }
    return populations.get(city, "Population data not available.")

agent = create_agent(
    model="openrouter:nvidia/nemotron-3-nano-30b-a3b:free",
    tools=[get_weather, get_population],
    system_prompt="You are a helpful assistant",
)

The agent will automatically decide which tool to call based on the user's question.

Common Errors & Fixes #

Error Cause Fix
OPENROUTER_API_KEY must be set
Missing API key Add it to your .env file and call load_dotenv()
is not a valid model ID
Wrong model name Use the exact ID from openrouter.ai/models, with :free suffix
No endpoints found
Model unavailable Try a different Nemotron model ID
cannot import name 'create_agent'
Wrong Python / old langchain Use uv run instead of python , or upgrade langchain

Project Structure #

When you're done, your project should look like this:

my-nemotron-agent/
β”œβ”€β”€ .env              ← Your API key (never share this!)
β”œβ”€β”€ .gitignore        ← Excludes .env from Git
β”œβ”€β”€ main.py           ← Your agent code
└── pyproject.toml    ← Dependencies (if using uv)

Next Steps #

Once you're comfortable with the basics, here's what to explore next:

Real toolsβ€” connect to real APIs (weather, search, databases) instead of mock functions - Memoryβ€” give your agent conversation history so it remembers past messages - Streamingβ€” stream the response token by token for a ChatGPT-like feel - LangSmithβ€” trace and debug your agent's reasoning visually - Other free modelsβ€” trydeepseek/deepseek-r1:free

orgoogle/gemma-3-27b-it:free

for comparison

Happy building!

── more in #artificial-intelligence 4 stories Β· sorted by recency
── more on @nvidia 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain β€” perfect for shipping the agent you just read about.

$git push zahid main
β†’ Live at https://your-agent.zahid.host βœ“
Get free account β†’ Pricing
from €0/mo Β· no card required
LIVE [news/running-nvidia-nemot…] indexed:0 read:4min 2026-05-20 Β· β€”