---
title: "LangChain with EU-hosted models · ChatOpenAI setup"
description: "Connect LangChain's ChatOpenAI to inference.eu with base_url and run chains, agents and LangGraph workflows on open-weight models processed in the EU."
canonical: "https://inference.eu/integrations/langchain/"
language: "en"
---

Frameworks · LangChain

# Use LangChain with open-source models hosted in the EU

LangChain is a framework for building applications and agents on language models. Its \`ChatOpenAI\` class accepts a custom base URL, so you can run chains, tool-calling agents and LangGraph workflows on open-weight models at inference.eu, processed in European data centres.

[Contact sales](https://inference.eu/contact/)[Setup](#setup)

1.  01API format: OpenAI
2.  02EU data centres
3.  03Covered by one DPA

## Set it up in a few minutes

1.  1

    Create an API key in your inference.eu account and store it as `INFERENCE_EU_API_KEY`.

2.  2

    Install the integration with `pip install langchain-openai`, or `npm install @langchain/openai` for JavaScript.

3.  3

    Create `ChatOpenAI` with `base_url` set to the inference.eu base URL, `api_key` from the environment and an inference.eu `model` id.

4.  4

    Set `stream_usage=True` if you need token counts while streaming.

5.  5

    Call `invoke` once to confirm the connection, then use the model in your chains, agents or graphs.

python

```
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="qwen3-coder-480b-a35b-instruct",
    base_url="https://api.inference.eu/v1",
    api_key=os.environ["INFERENCE_EU_API_KEY"],
    stream_usage=True,
)

print(llm.invoke("Summarise GDPR Article 28 in two sentences.").content)

# LangChain.js:
# new ChatOpenAI({ model: "gpt-oss-120b", apiKey: process.env.INFERENCE_EU_API_KEY,
#                  configuration: { baseURL: "https://api.inference.eu/v1" } });
```

## What LangChain is

LangChain is an open-source framework in Python and JavaScript for building applications on language models. It provides a common interface for chat models, prompts, tools, retrievers and output parsers, and its `create_agent` helper and LangGraph library run tool-calling agents and stateful workflows.

Every LangChain component that needs a chat model accepts any object implementing that common interface. The `ChatOpenAI` class from `langchain-openai` talks to any endpoint in the OpenAI format when you set `base_url`, so inference.eu slots into existing chains and agents without other code changes.

## How the configuration works

Pass `base_url` (the inference.eu base URL ending in `/v1`), `api_key` and `model` to `ChatOpenAI`. In LangChain.js, the URL goes under `configuration: { baseURL }`. LangChain also reads `OPENAI_API_BASE` and `OPENAI_BASE_URL` when no explicit URL is passed, but explicit arguments are clearer when a project uses several providers.

With a custom base URL, LangChain does not turn on streaming usage by default, so set `stream_usage=True` to receive token counts. You can also build the model with `init_chat_model("openai:<model id>", base_url=..., api_key=...)` if your code selects models from configuration.

## Which models to choose

For retrieval-augmented generation, summarisation and extraction, `gpt-oss-120b` is a quick and capable default. For agents built with `create_agent` or LangGraph that call several tools in sequence, `qwen3-coder-480b-a35b-instruct`, `glm-5.3` and `kimi-k3` produce dependable tool calls.

`glm-5.3` and `kimi-k3` also suit long-context work over large documents and complex multi-step planning. Use `with_structured_output` with a Pydantic model for extraction; LangChain validates the result. Because models are plain objects, you can give each node in a graph its own model, using a fast one for routing and a stronger one for reasoning.

## Troubleshooting

A 401 error means the key is missing or LangChain picked up an old `OPENAI_API_KEY`; pass `api_key` explicitly. A 404 usually means `base_url` has an extra path, or the `model` id does not exist at inference.eu.

`ChatOpenAI` follows the official OpenAI specification only, so non-standard fields such as `reasoning_content` from reasoning models are not kept in the message. Using built-in tools or parameters that only exist in OpenAI's Responses API switches `ChatOpenAI` to that API; keep `use_responses_api=False` and stick to Chat Completions features. If tool calls arrive as text, choose a model with tool calling support.

## Keeping data in the EU

With `base_url` pointed at inference.eu, every prompt, retrieved document and tool result your chains send to the model is processed in EU data centres and never used for training. We sign a data processing agreement under Article 28 GDPR, publish our subprocessor list and bill in euros.

LangChain itself only calls the services you configure. Embeddings, vector stores and tracing are separate: if you enable LangSmith tracing, prompts and outputs are sent to LangSmith under its own terms. Choose EU-hosted options for those components, or keep tracing off, so that the whole pipeline stays in Europe.

## LangChain

Category

Frameworks

Maker

LangChain

API format

OpenAI

Processing

EU data centres

Website

[www.langchain.com](https://www.langchain.com/)

Documentation

[docs.langchain.com](https://docs.langchain.com/oss/python/integrations/chat/openai)

## LangChain: common questions

The questions buyers, developers and legal teams ask us most. Something missing? Ask us directly.

Create \`ChatOpenAI\` with \`base\_url\`, \`api\_key\` and \`model\`. All LangChain components that accept a chat model, including agents and LangGraph nodes, then use that endpoint. In LangChain.js, pass the URL as \`configuration.baseURL\`.

Qwen3 Coder 480B, GLM-5.3 and Kimi K3 produce dependable tool calls for \`create\_agent\` and LangGraph. Use gpt-oss-120b for fast retrieval-augmented answers, summaries and routing steps where speed matters more than deep reasoning.

With a custom base URL, LangChain leaves streaming usage off by default because many non-OpenAI endpoints do not support it. inference.eu does, so set \`stream\_usage=True\` on \`ChatOpenAI\` to receive usage metadata at the end of the stream.

\`ChatOpenAI\` only keeps fields defined in the official OpenAI specification, so extra fields such as \`reasoning\_content\` are dropped. The final answer is unaffected. If you need the reasoning text, call the API directly with the OpenAI SDK and read the raw response.

Yes. Call \`init\_chat\_model("openai:gpt-oss-120b", base\_url=..., api\_key=...)\`. The \`openai\` provider prefix selects \`ChatOpenAI\`, and the extra arguments point it at inference.eu. This is useful when the model name comes from configuration or an environment variable.

Yes. Pass a Pydantic model or JSON schema to \`with\_structured\_output\` and LangChain asks for structured output and validates the result. Test your schema with the chosen model and keep fields simple for the most reliable results.

\`ChatOpenAI\` switches to the Responses API when you use features that only exist there, such as built-in OpenAI tools. Keep to Chat Completions features and set \`use\_responses\_api=False\` so that every request goes to \`/chat/completions\` at inference.eu.

The setup on this page covers chat models. For embeddings, use any embedding integration whose data handling meets your requirements, ideally hosted in the EU, so retrieved documents and queries stay in Europe alongside your chat requests.

Only if you enable tracing with \`LANGSMITH\_TRACING=true\` and a LangSmith key. Then prompts, outputs and tool calls are sent to LangSmith under its terms. Leave tracing off, or use a tracing setup hosted in the EU, to keep data in Europe.

Yes. Each node can use its own chat model object. To keep all model processing in the EU, use inference.eu models for every node, assigning a fast model to routing and a stronger one to reasoning-heavy steps.

[Ask a question](https://inference.eu/contact/)

## Related

[All integrations](https://inference.eu/integrations/)

-   [LlamaIndexConnect LlamaIndex to inference.eu with the OpenAILike class and run RAG pipelines and agents on open-weight models processed in EU data centres.Frameworks](https://inference.eu/integrations/llamaindex/)
-   [CrewAIRun CrewAI agents and crews on open-weight models processed in EU data centres by giving the LLM class the inference.eu base URL and key.Frameworks](https://inference.eu/integrations/crewai/)
-   [OpenAI SDK (Python and JavaScript)Point the official OpenAI Python or JavaScript SDK at inference.eu with base\_url and an API key, and call open-weight models processed in the EU.SDKs](https://inference.eu/integrations/openai-sdk/)
-   [HaystackPoint Haystack's OpenAIChatGenerator at inference.eu with api\_base\_url and run RAG pipelines and agents on open-weight models processed in the EU.Frameworks](https://inference.eu/integrations/haystack/)

## Move your AI workloads to EU infrastructure

Tell us which models you use and roughly how much traffic you have. We reply within one working day with pricing and next steps.

-   Reply within one working day
-   Pricing for your volume
-   DPA ready to sign
