Migrate from OpenAI
Move code that calls OpenAI's Chat Completions API to Safeguard: change the base URL and the key, map the model ids, and check the parameters you use.
Code written for OpenAI's Chat Completions API moves to Safeguard with three changes: the base URL, the key and the model id. Everything else on this page is about the differences to check before you switch.
1. Change the base URL and the key
import os
from openai import OpenAI
# Before: client = OpenAI() (OpenAI's API, OPENAI_API_KEY)
client = OpenAI(
base_url="https://api.safeguard.sh/gpt/v1",
api_key=os.environ["SAFEGUARD_INFERENCE_KEY"],
)Create the key in the Console under API keys. See Authentication.
2. Map the model ids
Safeguard's model ids name the provider first: OpenAI's gpt-6-sol is openai/gpt-6-sol. Look the model up at safeguard.sh/models or with GET /models and use its id.
response = client.chat.completions.create(
model="openai/gpt-6-sol", # was "gpt-6-sol"
messages=[{"role": "user", "content": "Hello"}],
)A model is callable only after it passes Safeguard's launch checks, so confirm that the models you use appear in GET /models before you switch traffic.
3. Check the parameters you send
| You use | On Safeguard |
|---|---|
messages with text content | Same. Roles system, developer, user, assistant and tool. |
Images or audio in messages | Refused with 400 unsupported_parameter. Text only in v1. |
max_tokens, max_completion_tokens | Same. Capped at the model's maximum output. |
temperature, top_p, stop | Same, with the same ranges. |
stream, stream_options.include_usage | Same. See Streaming. |
tools, tool_choice, parallel_tool_calls | Passed to the provider unchanged. |
response_format, seed, presence_penalty, frequency_penalty | Passed to the provider unchanged. |
n greater than 1 | Refused with 400 unsupported_parameter. |
user | Accepted and dropped, never sent to the provider. |
Any other parameter, such as logprobs, logit_bias, store or metadata | Ignored and not forwarded. |
The full list is on Chat completions.
4. Check the endpoints you call
Safeguard serves POST /chat/completions, GET /models, GET /models/{id} and GET /key. If your code also calls OpenAI's Responses API, Assistants, embeddings, images, audio, files, batches or moderations, keep those calls on OpenAI; Safeguard answers them with 404.
What else changes
- Billing. Requests spend your workspace's prepaid credit at the provider's list price, with no markup. When credit runs out, requests are refused with
402 insufficient_creditinstead of being billed later. See Pricing and billing. - Cost in every response.
usage.costgives the request's cost in US dollars, andprovidernames the route that served it. - Rate limits. Each key has its own requests-per-minute limit, 60 by default. See Limits.
- Errors. The body has OpenAI's shape, but the codes are Safeguard's, such as
insufficient_creditandmodel_unavailable. See Errors. - Organizations and projects. OpenAI organization and project settings have no meaning here. A Safeguard key belongs to your workspace.
- Data handling. Your prompts go to the provider of the model you choose. The request log keeps metadata only, unless a tenant admin or super admin turns on prompt storage. See Privacy and data.
A checklist for the switch
- Create a key for the application in the Console, with a monthly spend limit.
- Confirm your models appear in
GET /models. - Change the base URL, the key and the model ids.
- Run your tests against Safeguard and compare outputs and
usage.cost. - Watch Usage in the Console during the first days of traffic.
SDKs and clients
Use the inference API from the OpenAI Python and Node.js SDKs, from curl, or from any client that speaks OpenAI's Chat Completions format.
Migrate from another router
Move from any OpenAI-compatible model router or gateway to Safeguard: base URL, key, model ids, routing options and billing differences.