Skip to main content

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

Create a .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
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)

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!

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