Migrating from OpenAI
Move code from the OpenAI API to PeakPrivacy: what to change, what is dropped or missing, before-and-after code in Python and JavaScript and a checklist.
If your code uses the official OpenAI SDKs, moving to PeakPrivacy is mostly configuration: another base URL, a PeakPrivacy token and PeakPrivacy model ids.
All examples were run against the live API on 11.11.2026 with the Python SDK 3.49 and the JavaScript SDK 6.49.
The three changes
- Base URL:
https://api.peakprivacy.ch/v1/ai - API key: a PeakPrivacy token, see Authentication.
- Model id: an id from
GET /v1/ai/models, for examplegpt-swiss.
For plain chat completions, that is often all. If your code creates the client without arguments, environment variables are enough, because both SDKs read them:
export OPENAI_BASE_URL="https://api.peakprivacy.ch/v1/ai"
export OPENAI_API_KEY="$PEAKPRIVACY_API_KEY"Then change the model id in your code.
Before and after
A ticket summary, first against OpenAI, then against PeakPrivacy. Comments 1 to 3 mark the three changes. Comments 4 and 5 are needed because the OpenAI code uses the developer role and max_completion_tokens, see What behaves differently.
Before (OpenAI)
from openai import OpenAI
client = OpenAI() # reads OPENAI_API_KEY
TICKET = "Nadia (Accounting): Since this morning the scanner on floor 2 sends PDFs without the last page. Restarting didn't help. She needs it for the month-end closing on Friday."
completion = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "developer", "content": "You summarise IT support tickets in two sentences."},
{"role": "user", "content": TICKET},
],
max_completion_tokens=300,
)
print(completion.choices[0].message.content)After (PeakPrivacy)
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.peakprivacy.ch/v1/ai", # 1. PeakPrivacy base URL
api_key=os.environ["PEAKPRIVACY_API_KEY"], # 2. PeakPrivacy token
)
TICKET = "Nadia (Accounting): Since this morning the scanner on floor 2 sends PDFs without the last page. Restarting didn't help. She needs it for the month-end closing on Friday."
completion = client.chat.completions.create(
model="gpt-swiss", # 3. PeakPrivacy model id
messages=[
{"role": "system", "content": "You summarise IT support tickets in two sentences."}, # 4. system, not developer
{"role": "user", "content": TICKET},
],
max_tokens=300, # 5. max_tokens, not max_completion_tokens
)
print(completion.choices[0].message.content)Output of the PeakPrivacy version:
Nadia from Accounting reports that the scanner on floor 2 has been generating PDFs that are missing the final page since this morning, and a restart did not resolve the problem. She requires a fix before Friday to complete month‑end closing.What behaves differently
PeakPrivacy passes on only the fields listed in Request body. Everything else is dropped without an error, so code that relies on it keeps running but behaves differently.
| With OpenAI | With PeakPrivacy | What to do |
|---|---|---|
developer role | Accepted by some models. mistral-small-swiss returned 500. | Send instructions as system. |
max_completion_tokens | Dropped. | Use max_tokens. Only some models apply it: in our tests gpt-swiss did; gpt-4.1, deepseek-v4-flash and mistral-small-swiss didn't. Don't rely on it to limit answer length. |
response_format, .parse() helpers | response_format is dropped, so .parse() fails with a validation error. | Prompt for JSON and validate it, see Getting JSON back. |
n, stop, seed, logprobs, tool_choice, parallel_tool_calls, presence_penalty, frequency_penalty, user | Dropped. With n above 1 you still get one choice. | Remove them. Cut at stop sequences in your own code. |
stream_options | Not needed. | Every stream ends with a usage chunk, see Streaming. |
previous_response_id, store on /responses | Dropped. Each request stands alone. | Send the conversation in input, see Conversations. |
reasoning_effort | Applied by some models only. | See Reasoning. |
Images in messages | Supported by models with meta.capabilities.vision set to true. In our test, gpt-4.1 read an image sent as a data URL. | Choose the model by that flag, see Choosing a model › Capabilities. |
client.files | 404. PeakPrivacy has its own Files API. | Use plain HTTP, see Files. |
| Embeddings, images, audio, fine-tuning | No endpoints. The SDK calls fail with 404. | Keep these with another provider, or drop them. |
client.models.retrieve(id) | 404. | Use client.models.list(). |
| Answer text | ß is replaced by ss. | Nothing, unless you compare strings. |
PeakPrivacy also adds a field: anonymize runs messages through the anonymiser first, see Anonymisation.
Error handling
The SDK exception classes still work: BadRequestError for 400, AuthenticationError for 401, RateLimitError for 429, and so on. The bodies inside have PeakPrivacy shapes, and the two SDKs read them differently.
import os
import openai
from openai import OpenAI
client = OpenAI(
base_url="https://api.peakprivacy.ch/v1/ai",
api_key=os.environ["PEAKPRIVACY_API_KEY"],
)
try:
client.chat.completions.create(
model="gpt-4.1-mini", # an OpenAI id that PeakPrivacy doesn't offer
messages=[{"role": "user", "content": "Hello"}],
)
except openai.APIStatusError as error:
print(error.status_code, error.response.json())400 {'message': 'Validation error', 'errors': {'model': ['The selected model is invalid.']}}error.response.json() returns the full body, including trace_id on 500 errors. error.body can hold only part of it.
Pick a model
PeakPrivacy model ids aren't one-to-one equivalents of OpenAI models. Use this table to decide what to try first, then test with your own prompts. Security levels and the full list are on Models.
| If you used | Try first | Why |
|---|---|---|
gpt-4o, gpt-4.1, gpt-5 | The same id, Extern | Available under the same name. Before you send personal data, test a model with the Schweiz level. With tools on chat completions, gpt-5 returned 500 in our tests unless the request had "reasoning_effort": "none", see Tool calling › Which models support it. |
Small, fast models such as gpt-4.1-mini or gpt-5-mini | gpt-swiss or mistral-small-swiss, both Schweiz | gpt-swiss answered in one to three seconds in our tests. mistral-small-swiss doesn't reason and streams cleanly. |
Reasoning models such as o3 or o4-mini | gpt-swiss with reasoning_effort, or gpt-5 on /responses | See Reasoning › Models. |
| Image input | A model with meta.capabilities.vision set to true | See Choosing a model › Capabilities. |
Check at startup that the ids you use are still listed:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.peakprivacy.ch/v1/ai",
api_key=os.environ["PEAKPRIVACY_API_KEY"],
)
REQUIRED = {"gpt-swiss", "deepseek-v4-flash"}
missing = REQUIRED - {model.id for model in client.models.list()}
if missing:
raise RuntimeError(f"Models not available: {sorted(missing)}")
print("All models available")Checklist
- Base URL and token set, in code or through
OPENAI_BASE_URLandOPENAI_API_KEY. - Model ids replaced and checked against
client.models.list()at startup. - Security level of each model checked against the data you send, see Security levels (German).
-
developermessages sent assystem. -
max_completion_tokensreplaced bymax_tokens, and no length limit that depends on it. -
response_formatand.parse()replaced by a prompt and validation. - Dropped fields such as
n,stop,seedandtool_choiceremoved. - Stream consumers read
usagefrom the last chunk and checkfinish_reason. - Responses calls send the history in
inputinstead ofprevious_response_id. - Uploads moved to the PeakPrivacy Files API. Embeddings, images and audio handled elsewhere.
- Error handling logs the status instead of parsing OpenAI error objects. In Python it also logs the
trace_idfromerror.response.json()(non-streamed requests).