Skip to main content
Helicone OSS LLM Observability

LangChain Integration

Integrate Helicone AI Gateway with LangChain to access 100+ LLM providers with unified observability.
2 min read

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
Note

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.

Note

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

Info

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!

You can find all 100+ supported models at helicone.ai/models.

Use LangChain normally

Your existing LangChain code continues to work without any changes:

View requests in the Helicone dashboard

All your LangChain requests are now visible in your Helicone dashboard.
  • Request/response bodies
  • Latency metrics
  • Token usage and costs
  • Model performance analytics
  • Error tracking
  • Session tracking
Tip

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:

Note

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:

Info

Looking for a framework or tool not listed here? Request it here!