---
title: "LangChain (gateway)"
description: "Set up LangChain with the Respan gateway."
---

Route LangChain's underlying LLM calls through the Respan gateway to use 1000+ models from different providers. Only your Respan API key is needed. No separate provider keys are required.

Paste this into your coding agent:

```text
Help me set up the Respan gateway with the LangChain integration.
Follow https://www.respan.ai/docs/integrations/gateway/lang-chain.md
```

## Setup

<Steps>
<Step title="Install packages">

<Tabs>
<Tab title={"Python"}>

```bash
pip install langchain langchain-openai python-dotenv
```

</Tab>
<Tab title={"TypeScript"}>

```bash
npm install langchain @langchain/core @langchain/openai
```

</Tab>
</Tabs>

</Step>

<Step title="Set environment variables">

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
```

No `OPENAI_API_KEY` needed: the Respan gateway handles provider authentication.

</Step>

<Step title="Point LangChain to the Respan gateway">

<Tabs>
<Tab title={"Python"}>

```python
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url="https://gateway.respan.ai",
    model="gpt-5.5",
)

response = llm.invoke("Say hello through the Respan gateway.")
print(response.content)
```

</Tab>
<Tab title={"TypeScript"}>

```typescript
import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "gpt-5.5",
  apiKey: process.env.RESPAN_API_KEY,
  configuration: {
    baseURL: "https://gateway.respan.ai",
  },
});

const response = await llm.invoke("Say hello through the Respan gateway.");
console.log(response.content);
```

</Tab>
</Tabs>

</Step>
</Steps>

## LangGraph

LangGraph uses LangChain's chat models, so the same `ChatOpenAI` works in a graph. Install `langgraph` next to `langchain-openai` and pass `llm` to your nodes or agents.

```bash
pip install langgraph langchain-openai
```

## Switch models

Change the `model` parameter on `ChatOpenAI` to use another OpenAI model through the same gateway-backed endpoint.

```python
llm = ChatOpenAI(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url="https://gateway.respan.ai",
    model="gpt-5.5",
)
llm = ChatOpenAI(
    api_key=os.environ["RESPAN_API_KEY"],
    base_url="https://gateway.respan.ai",
    model="gpt-5-mini",
)
```


See the [full model list](https://platform.respan.ai/platform/models).

## Respan parameters

Pass additional Respan parameters via `extra_body` for gateway features.

```python
llm = ChatOpenAI(
    base_url="https://gateway.respan.ai",
    api_key=os.environ["RESPAN_API_KEY"],
    model="gpt-5.5",
    extra_body={
        "customer_identifier": "user_123",
        "metadata": {"session_id": "abc123"},
        "session_identifier": "conversation_456",
    },
)
```

See [Respan params & metadata](/docs/ai-gateway/customers/respan-params) for the full list.
