Introduction
LangChain is a popular open-source framework for building applications with large language models across Python, TypeScript, and other languages. By integrating Helicone AI Gateway with LangChain, you can:- Route to different models & providers with automatic failover through a single endpoint
- Unified billing with pass-through billing or bring your own keys
- Monitor all requests with automatic cost tracking in one dashboard
- Stream responses with full observability for real-time applications
This integration requires only two changes to your existing LangChain code - updating the base URL and API key.
Integration Steps
1
Create an account + Generate an API Key
Sign up at helicone.ai and generate an API key.
Youβll also need to configure your provider API keys (OpenAI, Anthropic, etc.) at Helicone Providers for BYOK (Bring Your Own Keys).
2
Set environment variables
.env file in your project:3
Install LangChain packages
4
Configure LangChain with Helicone AI Gateway
The only changes from a standard LangChain setup are the
apiKey, baseURL (or base_url in Python), and optional tracking headers. Everything else stays the same!5
Use LangChain normally
Your existing LangChain code continues to work without any changes:
6
- Request/response bodies
- Latency metrics
- Token usage and costs
- Model performance analytics
- Error tracking
- Session tracking
Migration Example
Hereβs what migrating an existing LangChain application looks like:Before (Direct OpenAI)
After (Helicone AI Gateway)
Complete Working Examples
Basic Example
Streaming Example
Multiple Models Example
Batch Processing Example (Python)
Python
Helicone Prompts Integration
You can use Helicone Prompts for centralized prompt management and versioning by passing parameters throughmodelKwargs:
All prompt parameters (
prompt_id, version_id, environment, inputs) are optional. Learn more about Prompts with AI Gateway.Custom Headers and Properties
You can add custom properties to track and filter your requests:Looking for a framework or tool not listed here? Request it here!
Related Documentation
AI Gateway Overview
Learn about Heliconeβs AI Gateway features and capabilities
Provider Routing
Configure intelligent routing and automatic failover
Model Registry
Browse all available models and providers
Prompt Management
Version and manage prompts with Helicone Prompts
Custom Properties
Add metadata to track and filter your requests
Sessions
Track multi-turn conversations and user sessions
Rate Limiting
Configure rate limits for your applications