Public preview: This API is in public preview. Endpoints, schemas, and limits may change before general availability.

Using the OpenAI SDK

Point the official `openai` SDK at EU GPT and reuse your existing code.

There is no EU GPT-specific SDK. The official OpenAI SDKs already speak the Responses API, and EU GPT implements it — so configuration is one line.

Install the SDK#

npm install openai
bun add openai
pip install openai
uv add openai

Configure the base URL#

Override baseURL (JS) / base_url (Python) to point at the EU GPT environment. Use your EU GPT API key — not an OpenAI key.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.EUGPT_API_KEY,
  baseURL: "https://api.eugpt.ai/v1",
});
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["EUGPT_API_KEY"],
    base_url="https://api.eugpt.ai/v1",
)

That is the entire configuration. Every call to client.responses.create now goes to EU GPT.

What works#

  • client.responses.create(...) — both stream: true and stream: false.
  • The async iterator pattern in JavaScript (for await (const event of stream)).
  • The Python generator pattern (for event in stream:).
  • Typed events — the SDK parses the data: JSON for you.
  • client.models.list() — the models you can pass as model.
  • client.files.create, .list, .retrieve, .content, and .delete — see Using files as context.

EU GPT-specific fields such as conversation_id, project_id, visible, and response_format are not in the SDK’s types. In JavaScript you can pass them in the request object (in TypeScript, cast the object); in Python, pass them in extra_body:

const response = await client.responses.create({
  model: "auto",
  input: "And add a bulleted list of risks.",
  conversation_id: "8f14e45f-ceea-467a-a4ed-a9e9a5cb16ee",
  stream: false,
});
response = client.responses.create(
    model="auto",
    input="And add a bulleted list of risks.",
    stream=False,
    extra_body={"conversation_id": "8f14e45f-ceea-467a-a4ed-a9e9a5cb16ee"},
)

What does not work (yet)#

The following surfaces are part of the OpenAI SDK but not implemented in EU GPT today. Calling them returns a 404:

  • client.chat.completions.* — use client.responses.* instead.
  • client.responses.retrieve, .delete, .cancel, and other calls on an existing response.
  • client.assistants.*, client.threads.* — the Assistants API is a separate product line.
  • client.embeddings.* — embeddings are an internal RAG concern; no public endpoint.
  • client.images.*, client.audio.* — image and audio generation are not exposed publicly.

These request parameters are accepted but ignored, so they fail silently:

  • previous_response_id — use conversation_id instead.
  • tools — EU GPT uses its own built-in tools.
  • text.format, and therefore client.responses.parse(...) with text_format — use response_format instead; see Structured outputs.
  • Sampling parameters such as temperature and top_p.

A reusable client#

Create the client once at module load. The SDK reuses HTTP connections.

// lib/eugpt.js
import OpenAI from "openai";

export const eugpt = new OpenAI({
  apiKey: process.env.EUGPT_API_KEY,
  baseURL: process.env.EUGPT_BASE_URL ?? "https://api.eugpt.ai/v1",
});
# app/eugpt.py
import os
from openai import OpenAI

eugpt = OpenAI(
    api_key=os.environ["EUGPT_API_KEY"],
    base_url=os.getenv("EUGPT_BASE_URL", "https://api.eugpt.ai/v1"),
)

Parameterising the base URL lets your tests point the client at a mock server without code changes.

Switching providers#

If your code already uses OpenAI and you want to add EU GPT alongside, instantiate two clients:

import OpenAI from "openai";

const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const eugpt = new OpenAI({
  apiKey: process.env.EUGPT_API_KEY,
  baseURL: "https://api.eugpt.ai/v1",
});

// Route per-call:
const client = featureFlag("use-eu-gpt", user) ? eugpt : openai;

Common pitfalls#

  • Forgetting /v1: the base URL must end in /v1, not /v1/ and not bare https://api.eugpt.ai. The SDK appends responses to it.
  • OpenAI key vs EU GPT key: keys are not interchangeable. EU GPT keys start with eugpt_.
  • Calling Chat Completions: client.chat.completions.create returns 404. Use client.responses.create.
  • Using an OpenAI model name: names like gpt-4o don’t exist on EU GPT and return 400 with model_not_found. Pass "auto" or an EU GPT model id from client.models.list(). See Models.
  • Sending chat history in input: only the first text part of input is used. Use conversation_id for multi-turn conversations.
  • No credit: requests return 402 (the SDK throws an error with status 402) until your prepaid balance has credit. See Usage limits & billing.