---
title: "OpenAI SDK with EU-hosted models · Base URL setup"
description: "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."
canonical: "https://inference.eu/integrations/openai-sdk/"
language: "en"
---

SDKs · OpenAI SDK (Python and JavaScript)

# Use the OpenAI SDK with open-source models hosted in the EU

The official OpenAI SDKs for Python and JavaScript work with any OpenAI-compatible API. Set the base URL to inference.eu and your existing code calls open-weight models processed in European data centres, with the same methods, types, streaming and tool calling you already use.

[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 SDK with `pip install openai` or `npm install openai`.

3.  3

    Create the client with `base_url` (Python) or `baseURL` (JavaScript) set to the inference.eu base URL and `api_key` set from the environment.

4.  4

    Replace the model name with an inference.eu model id such as `gpt-oss-120b`.

5.  5

    Run a short chat completion to confirm the connection, then enable streaming or tools as needed.

python

```
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.inference.eu/v1",
    api_key=os.environ["INFERENCE_EU_API_KEY"],
)

response = client.chat.completions.create(
    model="gpt-oss-120b",
    messages=[{"role": "user", "content": "Summarise GDPR Article 28 in two sentences."}],
)
print(response.choices[0].message.content)

# JavaScript / TypeScript:
# const client = new OpenAI({ baseURL: "https://api.inference.eu/v1", apiKey: process.env.INFERENCE_EU_API_KEY });
```

## Why use the OpenAI SDK with inference.eu

The `openai` packages are the most widely used client libraries for language model APIs, and many other tools build on them. They handle retries, timeouts, streaming, typed responses and errors for you. Because inference.eu speaks the OpenAI API format, you keep all of that and only change where requests go.

This is often the quickest way to move an existing application to open-weight models in the EU: two constructor arguments and a model name change, with no new dependency and no change to the rest of your code.

## How the configuration works

In Python, pass `base_url` and `api_key` to `OpenAI(...)` or `AsyncOpenAI(...)`. In JavaScript and TypeScript, pass `baseURL` and `apiKey` to `new OpenAI({...})`. The base URL ends in `/v1`; the SDK appends paths such as `/chat/completions` itself.

Both SDKs also read `OPENAI_BASE_URL` and `OPENAI_API_KEY` from the environment when you do not pass them explicitly. That is convenient for tools you cannot edit, but explicit arguments with `INFERENCE_EU_API_KEY` are clearer in your own code and avoid mixing up keys when a project talks to more than one provider.

## Which models to choose

Use `client.models.list()` to see the model ids available to your key. For general chat, extraction and summarisation, `gpt-oss-120b` is a fast, capable default. For code generation and agents that call tools, `qwen3-coder-480b-a35b-instruct` is a strong choice.

For complex reasoning, long documents or multi-step agent workflows, try `glm-5.3` or `kimi-k3`. Because only the `model` string changes, you can compare models on your own prompts by running the same request against several ids and checking quality, latency and token usage in the responses.

## Troubleshooting

A 401 `AuthenticationError` means the key is missing or wrong; check that you read `INFERENCE_EU_API_KEY` and not an old `OPENAI_API_KEY`. A 404 `NotFoundError` usually means the base URL is missing `/v1` or has an extra path, or the model id does not exist.

Use Chat Completions, `client.chat.completions.create`, as the most widely supported path. For streaming usage, pass `stream_options={"include_usage": True}` to receive token counts in the last chunk. If tool calls come back as plain text, check the model supports tool calling and that `tools` follows the JSON Schema format.

## Keeping data in the EU

With the base URL set to inference.eu, every request your application sends through the SDK is processed in EU data centres. Prompts and completions are never used for training. We sign a data processing agreement under Article 28 GDPR, publish our subprocessor list and bill in euros.

The SDK itself only talks to the base URL you configure; it sends no telemetry to OpenAI. Check the rest of your stack: logging, tracing and evaluation services may store prompts too. If you set `OPENAI_BASE_URL` globally, make sure no other code path still creates a client with OpenAI's default URL.

## OpenAI SDK (Python and JavaScript)

Category

SDKs

Maker

OpenAI

API format

OpenAI

Processing

EU data centres

Website

[github.com](https://github.com/openai/openai-python)

Documentation

[github.com](https://github.com/openai/openai-python#configuring-the-http-client)

## OpenAI SDK (Python and JavaScript): common questions

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

Yes. Pass \`base\_url\` and \`api\_key\` to \`OpenAI()\` and the SDK sends all requests to that endpoint. Any provider that implements the OpenAI API format, including inference.eu, works with the same methods and response types.

Pass \`baseURL\` when you create the client, for example \`new OpenAI({ baseURL: process.env.INFERENCE\_EU\_BASE\_URL, apiKey: process.env.INFERENCE\_EU\_API\_KEY })\`. The same option works in Node.js, Deno, Bun and edge runtimes, and in TypeScript projects.

Yes. Both SDKs read \`OPENAI\_BASE\_URL\` and \`OPENAI\_API\_KEY\` when no explicit values are given. This is useful for tools you cannot modify. In your own code, explicit arguments make it obvious which provider each client uses.

Start with \`gpt-oss-120b\` for general tasks, \`qwen3-coder-480b-a35b-instruct\` for code and tool calling, and \`glm-5.3\` or \`kimi-k3\` for harder reasoning. Call \`client.models.list()\` to see every model id available to your key.

Yes. Pass \`stream=True\` in Python or \`stream: true\` in JavaScript and iterate over the chunks as usual. Add \`stream\_options={"include\_usage": True}\` if you need token counts, which arrive in the final chunk.

Yes, for models that support tool calling. Pass \`tools\` with JSON Schema definitions and read \`tool\_calls\` from the response as you would with OpenAI. Qwen3 Coder 480B, GLM-5.3 and Kimi K3 handle tool calls well.

You can pass \`response\_format\` with a JSON schema on Chat Completions. Support for strict schema enforcement depends on the model, so validate the parsed result in your code, for example with Pydantic, and retry if a field is missing.

Either the base URL is wrong or the model id is unknown. The base URL must end in \`/v1\` with nothing after it, because the SDK adds \`/chat/completions\`. Then compare the model id with \`client.models.list()\`.

No. The SDK sends requests only to the base URL you configure and has no built-in telemetry. Make sure every client in your codebase uses the inference.eu base URL, including those created by libraries that read \`OPENAI\_BASE\_URL\`.

No. The official \`openai\` package for Python or JavaScript is all you need. If you prefer the Anthropic format, the official Anthropic SDK also works with inference.eu, so you can use whichever client your code already depends on.

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

## Related

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

-   [Anthropic SDK (Python and TypeScript)Point the official Anthropic Python or TypeScript SDK at inference.eu and call open-weight models processed in the EU through the Messages API.SDKs](https://inference.eu/integrations/anthropic-sdk/)
-   [Vercel AI SDKUse the Vercel AI SDK's OpenAI-compatible provider to call open-weight models processed in EU data centres from Next.js, Node.js or edge apps.SDKs](https://inference.eu/integrations/vercel-ai-sdk/)
-   [LangChainConnect LangChain's ChatOpenAI to inference.eu with base\_url and run chains, agents and LangGraph workflows on open-weight models processed in the EU.Frameworks](https://inference.eu/integrations/langchain/)
-   [LiteLLMAdd inference.eu to the LiteLLM proxy or Python SDK with the openai/ prefix and route your team's requests to open-weight models processed in the EU.Gateways](https://inference.eu/integrations/litellm/)

## 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
