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

# LangChain

> Use LangChain with Phaseo through the OpenAI-compatible chat API.

Use this guide when you want LangChain chains, agents, or LangGraph workflows to call models through Phaseo.

## Install

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

## Configure ChatOpenAI

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

llm = ChatOpenAI(
    model="openai/gpt-5-nano",
    api_key=os.environ["PHASEO_API_KEY"],
    base_url="https://api.phaseo.ai/v1",
)

result = llm.invoke("Write one sentence about routing reliability.")
print(result.content)
```

## Use with LangGraph

Pass the same `llm` into your graph nodes or agent builder:

```python theme={null}
def call_model(state):
    response = llm.invoke(state["messages"])
    return {"messages": [response]}
```

## Notes

* LangChain's OpenAI-compatible path targets Chat Completions. Use Phaseo features that are available on `/v1/chat/completions`.
* If you need Responses-only server tools such as `phaseo:apply_patch`, call Phaseo directly or use the OpenAI SDK guide.
* For tracing, pair this with [Observability](./observability.mdx).

## Related

* [OpenAI SDK](./openai-sdk.mdx)
* [Tool Calling](../tool-calling.mdx)
* [Routing and Fallbacks](../routing-and-fallbacks.mdx)
