Skip to main content
Get started with RunPod chat models.

Overview

This guide covers how to use the LangChain ChatRunPod class to interact with chat models hosted on RunPod Serverless.

Setup

  1. Install the package:
  2. Deploy a Chat Model Endpoint: Follow the setup steps in the RunPod Provider Guide to deploy a compatible chat model endpoint on RunPod Serverless and get its Endpoint ID.
  3. Set Environment Variables: Make sure RUNPOD_API_KEY and RUNPOD_ENDPOINT_ID (or a specific RUNPOD_CHAT_ENDPOINT_ID) are set.

Instantiation

Initialize the ChatRunPod class. You can pass model-specific parameters via model_kwargs and configure polling behavior.

Invocation

Use the standard LangChain .invoke() and .ainvoke() methods to call the model. Streaming is also supported via .stream() and .astream() (simulated by polling the RunPod /stream endpoint).

Chaining

The chat model integrates seamlessly with LangChain Expression Language (LCEL) chains.

Model Features (Endpoint Dependent)

The availability of advanced features depends heavily on the specific implementation of your RunPod endpoint handler. The ChatRunPod integration provides the basic framework, but the handler must support the underlying functionality. Key Takeaway: Standard chat invocation and simulated streaming work if the endpoint follows basic RunPod API conventions. Advanced features require specific handler implementations and potentially extending or customizing this integration package.

API reference

For detailed documentation of the ChatRunPod class, parameters, and methods, refer to the source code or the generated API reference (if available). Link to source code: https://github.com/runpod/langchain-runpod/blob/main/langchain_runpod/chat_models.py