Deployment
Deploy LangGraph applications with LangGraph Cloud/Platform, configure graph APIs, manage deployment options, and scale for production.
Deployment
Deploying LangGraph applications to production requires understanding LangGraph Cloud (Platform), API configuration, authentication, scaling, and operational considerations.
LangGraph Cloud / Platform Overview
LangGraph Platform provides a managed deployment infrastructure for LangGraph applications:
| Feature | Description |
|---|---|
| Managed API | Automatic REST API generation from your graph |
| Scaling | Auto-scaling based on demand |
| Persistence | Managed PostgreSQL for checkpointing |
| Authentication | API key and OAuth support |
| Monitoring | Built-in LangSmith integration |
| Streaming | Server-Sent Events (SSE) for real-time output |
Deployment Architecture
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β Client ββββββΆβ LangGraph ββββββΆβ LLM β
β (App/Web) β β Platform β β APIs β
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β
βΌ
ββββββββββββββββ βββββββββββββββ
β PostgreSQL β β LangSmith β
β (State/Pers.)β β (Observ.) β
ββββββββββββββββ βββββββββββββββ
Graph API Configuration
Create a langgraph.json configuration file at your project root:
{
"name": "my-agent",
"version": "1.0.0",
"graphs": {
"agent": "./src/agent.py:graph"
},
"dependencies": {
"pip": ["langchain-openai", "tavily-python"],
"python": "3.11"
},
"env": {
"OPENAI_API_KEY": "sk-...",
"TAVILY_API_KEY": "tvly-..."
},
"checkpointer": {
"type": "postgres",
"url": "postgresql://user:pass@host:5432/langgraph"
}
}The graphs field maps endpoint names to Python import paths. The value "./src/agent.py:graph" means "import graph from src/agent.py".
Dockerfile Deployment
For custom deployments, use the official LangGraph Docker image:
FROM langchain/langgraph:latest
WORKDIR /app
COPY pyproject.toml .
RUN pip install -e .
COPY . .
# The graph is auto-detected from langgraph.json
EXPOSE 8080
CMD ["langgraph", "serve"]Deployment Options
Option 1: LangGraph Cloud (Managed)
# Install CLI
pip install langgraph-cli
# Deploy to LangGraph Cloud
langgraph deploy --project my-agent
# Set environment variables
langgraph secrets set OPENAI_API_KEY sk-...Option 2: Self-Hosted Docker
# Build the Docker image
docker build -t my-agent .
# Run with environment variables
docker run -p 8080:8080 \
-e OPENAI_API_KEY=sk-... \
-e DATABASE_URL=postgresql://... \
my-agentOption 3: Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: langgraph-agent
spec:
replicas: 3
selector:
matchLabels:
app: langgraph-agent
template:
metadata:
labels:
app: langgraph-agent
spec:
containers:
- name: agent
image: my-agent:latest
ports:
- containerPort: 8080
env:
- name: OPENAI_API_KEY
valueFrom:
secretKeyRef:
name: api-keys
key: openai-key
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: db-credentials
key: urlFor production, use Kubernetes secrets or a vault service for API keys. Never hardcode secrets in your code or config files.
API Endpoints
LangGraph Platform generates these REST endpoints:
| Endpoint | Method | Description |
|---|---|---|
/threads | POST | Create a new conversation thread |
/threads/{id}/runs | POST | Invoke the graph on a thread |
/threads/{id}/state | GET | Get thread state |
/threads/{id}/state | PATCH | Update thread state |
/threads/{id}/runs/{run_id}/stream | GET | Stream execution events |
Client Example
import requests
API_URL = "https://my-agent.langgraph.app"
# Create a thread
resp = requests.post(f"{API_URL}/threads", json={})
thread_id = resp.json()["thread_id"]
# Invoke the graph
resp = requests.post(
f"{API_URL}/threads/{thread_id}/runs",
json={"input": {"query": "What is LangGraph?"}}
)
print(resp.json())
# Get state
state = requests.get(f"{API_URL}/threads/{thread_id}/state")
print(state.json())Streaming from Deployed API
# Stream events via SSE
import json
import requests
with requests.post(
f"{API_URL}/threads/{thread_id}/runs/stream",
json={"input": {"query": "Write a poem"}},
stream=True
) as resp:
for line in resp.iter_lines():
if line:
event = json.loads(line.decode("utf-8").removeprefix("data: "))
print(event)Authentication
# API Key authentication
headers = {
"X-Api-Key": "lgv2_...",
"Content-Type": "application/json"
}
resp = requests.post(
f"{API_URL}/threads",
headers=headers,
json={}
)Rotate API keys regularly. Use short-lived keys for production and revoke compromised keys immediately.
Scaling Considerations
| Dimension | Strategy |
|---|---|
| Concurrent users | Horizontal scaling (more replicas) |
| Long-running graphs | Async execution with webhook callbacks |
| Database | PostgreSQL connection pooling (PgBouncer) |
| LLM rate limits | Queue requests, implement retry with backoff |
| Memory | Monitor checkpoint size, trim old checkpoints |
| Cold starts | Keep minimum replicas warm |
Database Connection Pooling
from langgraph.checkpoint.postgres import PostgresSaver
# Use connection pooling for production
checkpointer = PostgresSaver.from_conn_string(
"postgresql://user:pass@host:5432/langgraph",
pool_size=10,
max_overflow=20
)Health Checks
from fastapi import FastAPI
from langgraph.graph import StateGraph
app = FastAPI()
graph_app = builder.compile(checkpointer=checkpointer)
@app.get("/health")
def health():
return {"status": "ok", "graph": "ready"}
@app.post("/invoke")
def invoke(input: dict):
result = graph_app.invoke(input)
return resultPractice Questions
What file configures LangGraph Platform deployment?
What does the 'graphs' field in langgraph.json specify?
What database is recommended for production checkpointing?
Which HTTP method creates a new conversation thread?
How do you invoke a graph on an existing thread via the API?
How should secrets be handled in production LangGraph deployments?
What is a recommended strategy for LLM rate limits in production?
How does LangGraph Platform handle concurrent users?
What protocol does LangGraph Platform use for real-time streaming?
What information does a health check endpoint typically return?
Key Takeaways
- langgraph.json configures LangGraph Platform deployment
- Three deployment options: LangGraph Cloud, self-hosted Docker, Kubernetes
- REST API: POST /threads β POST /threads/{id}/runs β GET /threads/{id}/state
- PostgreSQL for production checkpointing; connection pooling for scale
- API key authentication with regular rotation
- Horizontal scaling for concurrent users; retry with backoff for rate limits
- SSE for real-time streaming of execution events and tokens
- Health checks for monitoring and orchestration