Skip to content

langchain-ai/langchain-litellm

langchain-litellm

πŸ“¦ Distribution πŸ”§ Project πŸš€ Activity
PyPI Package Version
PyPI Downloads
License: MIT
Platform
Python
uv
GitHub Issues Closed
GitHub Issues Open
GitHub PRs Open
GitHub PRs Closed

πŸ€” What is this?

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

πŸ“– Documentation

For conceptual guides, tutorials, and examples on using these classes, see the LangChain Docs.

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"])

πŸ“• Releases & Versioning

See our Releases and Versioning policies.

πŸ’ Contributing

As an open-source project in a rapidly developing field, we are extremely open to contributions, whether it be in the form of a new feature, improved infrastructure, or better documentation.

For detailed information on how to contribute, see the Contributing Guide.