inference.eu

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.

  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: common questions

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

Ask a question

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