For the complete documentation index, see llms.txt. This page is also available as Markdown.

Langgraph

Track usage, control costs, and add guardrails to your LangGraph agents

What is LangGraph?

LangGraph is a framework for building stateful, multi-step agents as graphs. Built by the LangChain team, it adds durable state, cycles, branching, and human-in-the-loop control on top of LangChain's model interfaces.

By routing LangGraph through FastRouter, you get:

  • 100+ models from OpenAI, Anthropic, Google, xAI, Meta, Groq, Mistral, and more through one endpoint

  • Observability for every request: cost, tokens, latency, and model selection tracked in real time

  • Reliability through automatic failover across providers, response caching, and intelligent routing

  • Governance with per-key budgets, rate limits, model restrictions, role-based access, and project isolation

This guide covers connecting LangGraph (Python) to FastRouter using a ChatOpenAI model inside a prebuilt ReAct agent.

Prerequisites

  • A FastRouter.ai account (sign up)

  • Python 3.10 or higher


Quick Start

Step 1: Create a Project and Virtual Environment

You'll only need to do this once:

mkdir my_project
cd my_project
python -m venv .venv

Activate the virtual environment. Do this every time you start a new terminal session.

On macOS or Linux:

On Windows:

Step 2: Install LangGraph

Step 3: Get Your FastRouter API Key

  1. Sign up or log in at fastrouter.ai

  2. Navigate to your project's Keys page

  3. Click Create User Key

  4. Copy the key immediately. FastRouter does not display the key again after creation.

Export it in your terminal:

Step 4: Point the Model at FastRouter

LangGraph uses LangChain chat models, so the standard ChatOpenAI class works once you override the base URL. Save this as graph_example.py:

Step 5: Run the Agent

The agent calls the get_weather tool and responds with the weather. Every request, token count, and cost appears in your FastRouter Dashboard.


Use LangGraph with 100+ Models

FastRouter uses the provider/model-name format. Switch providers by changing the model slug—no new dependencies or credentials:

You can give each node in your graph a different model—a fast model for routing nodes and a frontier model for reasoning nodes.

Explore the full model catalog

Automatic Model Selection

Let FastRouter pick the best model for each request based on query complexity, domain, and cost:

Explore automatic model selection


FAQs

Configuration & Setup

Can I use multiple models with the same API key?

Yes. The API key controls access and budget. Each node can use its own ChatOpenAI instance with a different model, all sharing one key.

Can I restrict a key to only use specific models?

Yes. When creating or editing a key, use the Select Models setting to limit which models the key can access. FastRouter rejects requests to unauthorized models.

Costs & Budgeting

Graphs with cycles can make many model calls. How do I control cost?

Set a budget and rate limit on the key, and use Dynamic Tags to attribute spend per graph or per run. The Dashboard breaks down costs by project, key, model, and tag.

Performance & Reliability

Does FastRouter add latency to graph execution?

FastRouter adds near-zero gateway overhead, negligible compared to model inference time.


Next Steps

Last updated