Skip to main content

An integration package connecting Litellm and LangChain

Project description

📦 Distribution 🔧 Project 🚀 Activity
PyPI Package Version
PyPI Downloads
License: MIT
Platform
Python
Poetry
GitHub Issues Closed
GitHub Issues Open
GitHub PRs Open
GitHub PRs Closed

langchain-litellm

This package contains the LangChain integration with LiteLLM. LiteLLM is a library that simplifies calling Anthropic, Azure, Huggingface, Replicate, etc.

Installation and setup

pip install -U langchain-litellm

Chat Models

from langchain_litellm import ChatLiteLLM
from langchain_litellm import ChatLiteLLMRouter

See a usage example

Advanced Features

Vertex AI Grounding (Google Search)

Supported in v0.3.5+

You can use Google Search grounding with Vertex AI models (e.g., gemini-2.5-flash). Citations and metadata are returned in response_metadata (Batch) or additional_kwargs (Streaming).

Setup

import os
from langchain_litellm import ChatLiteLLM

os.environ["VERTEX_PROJECT"] = "your-project-id"
os.environ["VERTEX_LOCATION"] = "us-central1"

llm = ChatLiteLLM(model="vertex_ai/gemini-2.5-flash", temperature=0)

Batch Usage

# Invoke with Google Search tool enabled
response = llm.invoke(
    "What is the current stock price of Google?",
    tools=[{"googleSearch": {}}]
)

# Access Citations & Metadata
provider_fields = response.response_metadata.get("provider_specific_fields")
if provider_fields:
    # Vertex returns a list; the first item contains the grounding info
    print(provider_fields[0])

Streaming Usage

stream = llm.stream(
    "What is the current stock price of Google?",
    tools=[{"googleSearch": {}}]
)

for chunk in stream:
    print(chunk.content, end="", flush=True)
    # Metadata is injected into the chunk where it arrives
    if "provider_specific_fields" in chunk.additional_kwargs:
        print("\n[Metadata Found]:", chunk.additional_kwargs["provider_specific_fields"])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_litellm-0.5.1.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_litellm-0.5.1-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file langchain_litellm-0.5.1.tar.gz.

File metadata

  • Download URL: langchain_litellm-0.5.1.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.2 Linux/6.11.0-1018-azure

File hashes

Hashes for langchain_litellm-0.5.1.tar.gz
Algorithm Hash digest
SHA256 1af5743c424456ce12c59cbf08b4774fbc9025124b6de8249713864242db57e1
MD5 2242df7b0a55f907bcf656ac1564c338
BLAKE2b-256 b1fa088dd2e3426aa413991afb67aef4c4e79ff3c0e4c25f753842bfaf4ec43f

See more details on using hashes here.

File details

Details for the file langchain_litellm-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: langchain_litellm-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.2 Linux/6.11.0-1018-azure

File hashes

Hashes for langchain_litellm-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3726c050eaaeb0b8aad0c8ceefae549917b185d176859866375f97d1d0ed6748
MD5 a01e7be3e753c22cad1fab4794d71ec7
BLAKE2b-256 b96f84c8cef2cd5a20e94222de93cc57645102087dff616d5054755b97db51b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page