Skip to Content
Launching the open-source gateway

LangChain (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 required.

Paste this into your coding agent:

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

Setup

Install packages

pip install langchain langchain-openai python-dotenv

Set environment variables

export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"

No OPENAI_API_KEY needed — the Respan gateway handles provider authentication.

Point LangChain to the Respan gateway

import os from langchain_openai import ChatOpenAI llm = ChatOpenAI( api_key=os.environ["RESPAN_API_KEY"], base_url="https://api.respan.ai/api", model="gpt-5.5", ) response = llm.invoke("Say hello through the Respan gateway.") print(response.content)

Switch models

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

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

ChatOpenAI is LangChain’s OpenAI-compatible chat adapter. This page avoids showing Claude or Gemini inside that OpenAI-named adapter; use the Respan API or OpenAI SDK gateway pages for provider-neutral Claude and Gemini examples.

See the full model list .

Respan parameters

Pass additional Respan parameters via extra_body for gateway features.

llm = ChatOpenAI( base_url="https://api.respan.ai/api/", api_key=os.environ["RESPAN_API_KEY"], model="gpt-5.5", extra_body={ "customer_identifier": "user_123", "fallback_models": ["gpt-5-mini"], "metadata": {"session_id": "abc123"}, "thread_identifier": "conversation_456", }, )

See Respan params & metadata for the full list.