Safeguard Docs
API Platform (Console)

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 useOn Safeguard
messages with text contentSame. Roles system, developer, user, assistant and tool.
Images or audio in messagesRefused with 400 unsupported_parameter. Text only in v1.
max_tokens, max_completion_tokensSame. Capped at the model's maximum output.
temperature, top_p, stopSame, with the same ranges.
stream, stream_options.include_usageSame. See Streaming.
tools, tool_choice, parallel_tool_callsPassed to the provider unchanged.
response_format, seed, presence_penalty, frequency_penaltyPassed to the provider unchanged.
n greater than 1Refused with 400 unsupported_parameter.
userAccepted and dropped, never sent to the provider.
Any other parameter, such as logprobs, logit_bias, store or metadataIgnored 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_credit instead of being billed later. See Pricing and billing.
  • Cost in every response. usage.cost gives the request's cost in US dollars, and provider names 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_credit and model_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

  1. Create a key for the application in the Console, with a monthly spend limit.
  2. Confirm your models appear in GET /models.
  3. Change the base URL, the key and the model ids.
  4. Run your tests against Safeguard and compare outputs and usage.cost.
  5. Watch Usage in the Console during the first days of traffic.

On this page