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#
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).
Set environment variables
Create a .env file in your project:
Install LangChain packages
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!
Use LangChain normally
Your existing LangChain code continues to work without any changes:
View requests in the Helicone dashboard
- Request/response bodies
- Latency metrics
- Token usage and costs
- Model performance analytics
- Error tracking
- Session tracking
While you're here, why not give us a star on GitHub? It helps us a lot!
Migration Example#
Here's what migrating an existing LangChain application looks like:
Before (Direct OpenAI)#
After (Helicone AI Gateway)#
That's it! Just two changes and you're routing through Helicone's AI Gateway.
Complete Working Examples#
Basic Example#
Streaming Example#
Multiple Models Example#
Batch Processing Example (Python)#
Helicone Prompts Integration#
You can use Helicone Prompts for centralized prompt management and versioning by passing parameters through modelKwargs:
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#
Learn about Helicone's AI Gateway features and capabilities
Configure intelligent routing and automatic failover
Browse all available models and providers
Version and manage prompts with Helicone Prompts
Add metadata to track and filter your requests
Track multi-turn conversations and user sessions
Configure rate limits for your applications
