Menu: Gateway API

Model gateway

Gateway API

Reference for the OpenAI-compatible endpoints at www.scalaix.com/v1, with Scalaix headers and errors.

Base URL: https://www.scalaix.com/v1. Authenticate with Authorization: Bearer sx_.... Requests and responses follow the OpenAI API, so existing clients work unchanged.

GET /v1/models

Lists the models the key may use, in the OpenAI list shape. Each entry has a scalaix object with the provider, billed prices per million tokens (margin included), limits and capabilities. When routing is possible for the key, the list also contains {"id": "auto"}.

curl https://www.scalaix.com/v1/models -H "Authorization: Bearer $SCALAIX_API_KEY"
{
  "object": "list",
  "data": [
    {
      "id": "gpt-4o-mini",
      "object": "model",
      "owned_by": "open_ai",
      "scalaix": {
        "provider": "open_ai",
        "input_per_mtok": 0.15,
        "output_per_mtok": 0.6,
        "context_window": 128000,
        "max_output_tokens": 16384,
        "supports": ["text", "vision", "json"]
      }
    },
    { "id": "auto" }
  ]
}

POST /v1/chat/completions

The OpenAI chat completions request and response, streaming or not.

curl https://www.scalaix.com/v1/chat/completions \
  -H "Authorization: Bearer $SCALAIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [
      {"role": "system", "content": "Answer in one sentence."},
      {"role": "user", "content": "What is a circuit breaker?"}
    ],
    "temperature": 0.3
  }'

Supported fields

FieldNotes
modelA catalog id, auto (routing), or default (the key's default model). Omit it to use the default.
messagesRoles system, developer, user, assistant, tool. Text and image_url content parts.
temperature, top_p, seed, stop, userPassed to the provider.
max_tokens, max_completion_tokensEither one.
nAny value for OpenAI-compatible providers; only 1 for Anthropic models.
response_formattext, json_object or json_schema.
tools, tool_choiceFunction calling.
stream, stream_options.include_usageServer-sent events ending with data: [DONE].

Responses always include usage. When streaming, ask for stream_options: {"include_usage": true} to get it as a final chunk.

Streaming

curl -N https://www.scalaix.com/v1/chat/completions \
  -H "Authorization: Bearer $SCALAIX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-4o-mini", "stream": true, "stream_options": {"include_usage": true},
       "messages": [{"role": "user", "content": "Count to five."}]}'

Structured output

{
  "model": "gpt-4o-mini",
  "messages": [{"role": "user", "content": "Extract the city: I live in Lisbon."}],
  "response_format": {
    "type": "json_schema",
    "json_schema": {
      "name": "city",
      "schema": {
        "type": "object",
        "properties": { "city": { "type": "string" } },
        "required": ["city"],
        "additionalProperties": false
      }
    }
  }
}

Headers

Request

HeaderMeaning
Authorization: Bearer sx_...Required.
X-Scalaix-Cache: offSkip the cache for this request.
X-Scalaix-Cache: ttl=<seconds>Cache this request's answer for this many seconds.

Response

HeaderMeaning
X-Scalaix-Request-IdOn every response. Quote it when you contact support.
X-Scalaix-ModelThe model that answered (after routing and fallback).
X-Scalaix-Cachehit, miss or off.
X-Scalaix-FallbacksHow many fallback models were tried before the answer.
Retry-AfterOn 429: seconds to wait.

Errors

Errors use the OpenAI shape:

{ "error": { "message": "Model claude-3-opus is not allowed for this key.", "type": "forbidden", "code": "forbidden" } }
StatustypeWhen
400invalid_requestThe body isn't valid.
401invalid_api_keyMissing, unknown, revoked or expired key.
402insufficient_quotaThe team is out of credits, or the key's monthly budget can't cover the request (see Budgets).
403forbiddenThe key's rules don't allow this model, collection, origin, IP or mode.
404not_foundUnknown model or path.
413invalid_requestThe body is over 10 MB.
429rate_limitedOver the key's requests per minute. See Retry-After.
501not_implementedA feature that isn't available yet.
502upstream_errorThe provider failed and no fallback succeeded.
504timeoutThe provider didn't answer in time.

See Errors for handling advice.