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.
- 01API format: OpenAI
- 02EU data centres
- 03Covered by one DPA
Set it up in a few minutes
- 1
Create an API key in your inference.eu account and store it as
INFERENCE_EU_API_KEY. - 2
Install the SDK with
pip install openaiornpm install openai. - 3
Create the client with
base_url(Python) orbaseURL(JavaScript) set to the inference.eu base URL andapi_keyset from the environment. - 4
Replace the model name with an inference.eu model id such as
gpt-oss-120b. - 5
Run a short chat completion to confirm the connection, then enable streaming or tools as needed.
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): common questions
The questions buyers, developers and legal teams ask us most. Something missing? Ask us directly.
Related
- 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
- 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
- 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
- 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
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