> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixroute.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain

> LangChain Framework Integration Guide

## Introduction

LangChain is a powerful framework for developing language model applications. With [**MixRoute**](https://api.mixroute.ai/)\*\* API\*\*, you can flexibly use various AI models in LangChain.

## Quick Start

### 1. Install Dependencies

```bash theme={null}
pip install langchain langchain-openai
```

### 2. Basic Configuration

```python theme={null}
import os
from langchain_openai import ChatOpenAI

os.environ["OPENAI_API_KEY"] = "YOUR_MIXROUTE_API_KEY"
os.environ["OPENAI_BASE_URL"] = "https://api.mixroute.ai/v1"

llm = ChatOpenAI(
    model="gpt-5.5",
    temperature=0.7
)
```

## Core Features

### Basic Chat

```python theme={null}
from langchain.schema import HumanMessage, SystemMessage

messages = [
    SystemMessage(content="You are a helpful assistant"),
    HumanMessage(content="Explain Python's main features")
]

response = llm.invoke(messages)
print(response.content)
```

### Conversation Chain (with Memory)

```python theme={null}
from langchain.memory import ConversationBufferMemory
from langchain.chains import ConversationChain

memory = ConversationBufferMemory()
conversation = ConversationChain(llm=llm, memory=memory)

conversation.predict(input="I want to learn machine learning")
conversation.predict(input="Recommend some resources")
```

### Streaming Output

```python theme={null}
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler

streaming_llm = ChatOpenAI(
    model="gpt-5.5",
    streaming=True,
    callbacks=[StreamingStdOutCallbackHandler()]
)

streaming_llm.invoke("Write a poem about spring")
```
