Safeguard Docs
API Platform (Console)

Quickstart

From access to your first chat completion: create an API key, find a model id, and call the API with curl, Python or Node.js.

Early access

The inference API is deployed but switched off while it is in early access. Open a model at safeguard.sh/models and choose Use with Safeguard; Safeguard then turns the API Platform on for your workspace. Until it is on, Create key in the Console is disabled, and requests are refused with 403 gateway_disabled.

1. Get access

Choose Use with Safeguard on any model at safeguard.sh/models and leave your email address. Safeguard switches the API Platform on for your workspace. Requests spend your workspace's prepaid credit; while card top-up is not available, Safeguard adds the credit for you.

2. Create an API key

  1. In the Safeguard web app, open the product switcher and choose API Platform (Console), or press G then 5.
  2. Open API keys and choose Create key.
  3. Give the key a name, such as production backend. You can also set a Monthly spend limit (USD) and a Requests per minute limit for this key; leave them empty for no spend limit and the default rate limit.
  4. Choose Create key. The Copy your key dialog shows the full key. This is the only time it is shown, so copy it now.

Keep the key on your server, for example in an environment variable:

export SAFEGUARD_INFERENCE_KEY="sg-api-..."

The examples in these docs read the key from SAFEGUARD_INFERENCE_KEY. Any name works. We avoid SAFEGUARD_API_KEY because Safeguard's CI/CD scanning setup uses that name for a different kind of key.

3. Find a model id

List the models your key can call now:

curl https://api.safeguard.sh/gpt/v1/models \
  -H "Authorization: Bearer $SAFEGUARD_INFERENCE_KEY"

Each entry's id is a value you can pass as model. Ids have the form provider/model, the same ids the catalog at safeguard.sh/models shows, for example openai/gpt-6-sol. An empty list means no model is switched on for the API yet. See Models.

4. Send your first request

Replace MODEL_ID with an id from step 3.

curl https://api.safeguard.sh/gpt/v1/chat/completions \
  -H "Authorization: Bearer $SAFEGUARD_INFERENCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "messages": [
      {"role": "system", "content": "You are a concise assistant."},
      {"role": "user", "content": "Explain what an SBOM is in two sentences."}
    ],
    "max_tokens": 200
  }'

5. Read the answer

The response has OpenAI's shape, plus two fields Safeguard adds: provider and usage.cost. The values below are illustrative.

{
  "id": "gen-6f1c2e0a9b4d4c7e8a1f3b5d7c9e0a2b",
  "object": "chat.completion",
  "created": 1791475000,
  "model": "MODEL_ID",
  "provider": "openai",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "An SBOM is a list of every component in a piece of software. It lets you see which versions you ship and which known vulnerabilities affect them."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 27,
    "completion_tokens": 33,
    "total_tokens": 60,
    "cost": 0.000159
  }
}
  • id is the request id: gen- followed by 32 hexadecimal characters. Safeguard records it with the request's log entry, so include it when you ask Safeguard about a request.
  • model is the model that answered and provider is the provider route that served it.
  • usage.cost is what this request cost in US dollars, at the provider's list price with no markup.

6. Check usage and credit

  • In the Console, Usage shows requests, tokens and cost, a request log, and your credit balance. See Usage and analytics.
  • From code, GET /key returns the calling key's limits, its spend this month and your workspace's available credit. See Authentication.

Next steps

  • Chat completions: every request and response field.
  • Streaming: tokens as they are generated.
  • Errors: what each status means and which ones to retry.
  • Limits: rate limits, spend limits and request sizes.

On this page