Skip to content
Sign in Create account

OpenAI-compatible chat completions

POST /api/v1/chat/completions

OpenAI-compatible chat completions. Supports streaming, tools/functions, and JSON mode. Supported clients attempt best-effort detection and tokenization on-device before sending. The gateway receives and relays request bytes, but does not inspect message content for personal data or verify that detection ran. The content-blind shape gate accepts top_p from 0 to 1, frequency_penalty and presence_penalty from -2 to 2, integer seed from 0 to 2147483647, integer n from 1 to 128, and max_completion_tokens from 1 to 200000. stop accepts one string or up to four strings of at most 32 characters; these stop sequences are operator configuration, not user text. Function-schema required entries must name sibling properties (at most 64 entries, each at most 64 characters). Client proof headers do not verify whether on-device detection ran or inspect message content.

Authenticate with an API key.

Parameters

  • X-CloakAPI-Privacy-Tier PrivacyMode header

    Which substitution style your client applies to sensitive values before the request leaves your user's device. Per-call; never persisted.

    Both modes protect the same data — a mode selects style only and can never switch protection off. Both cost something, so choose knowing which:

    • balanced (default) — Realistic stand-ins: John Mellows becomes Henry Caulinger. Cost: the model cannot tell the stand-ins are fake, so it may reason about them as if they were real — drawing conclusions from a substituted name, or treating a substituted address as a genuine place.
    • max — Opaque placeholders: John Mellows becomes <<CLOAK:PERSON:5e4120>>. Cost: the model can see the value is hidden, so it may write awkwardly around the placeholder, ask you for the real value, or decline to continue.

    Either way, the same detail always maps to the same replacement for the whole conversation, and the real values are restored in the reply on your device. You do not need to ask for that and cannot turn it off.

    An unrecognized value is rejected with 400 invalid_privacy_mode rather than reinterpreted — a header is code you just wrote, and silently resolving a typo is how an integration ships believing a privacy setting works. off and continuity were retired on 2026-07-28: there is no unprotected posture, and cross-turn stability is now unconditional.

  • X-Cloak-Engine-Version string header

    Client-declared version of the on-device CloakAPI tokenizer associated with this request. The gateway checks it against the minimum (currently 1.6.0) and answers 426 when lower; this does not prove that version ran. Leave it out, together with X-Cloak-Engine-Hash, only on a declared rules-only send (see X-CloakAPI-Tokenized); any other request without it is answered 428 engine_identity_required.

    Example: "1.6.0"
  • X-Cloak-Engine-Hash string header

    Client-declared SHA-256 of the engine binary claimed for this request. The gateway checks whether the hash is on its published allowlist and answers 403 engine_untrusted when missing or unknown; this does not prove that binary ran. Leave it out, together with X-Cloak-Engine-Version, only on a declared rules-only send.

  • X-CloakAPI-Tokenized string header

    Client-declared detection coverage, written true;coverage=full, true;coverage=rules_and_names or true;coverage=rules_only. A client that ran rule-based detection without an engine sends exactly true;coverage=rules_only, sends neither X-Cloak-Engine-Version nor X-Cloak-Engine-Hash, and still sends X-Cloak-Pretokenised and X-Cloak-Client-MAC. The gateway then relays the request without an engine identity, answers with the response header X-Cloak-Coverage set to rules_only, and signs a receipt that records x-cloakapi-detection with engine_identity set to not_declared and genuine_engine set to false. If an engine version or hash is sent, the engine checks apply whatever coverage is declared. The gateway does not read the body and does not verify the declared coverage.

    Example: "true;coverage=rules_only"
  • X-Cloak-Pretokenised string header required

    Client assertion that the request body was tokenized on-device. The gateway requires this header and verifies the tenant-bound MAC, but cannot verify that detection ran. Missing header answers 428 pretokenised_required.

    One of: "1"
  • X-Cloak-Client-MAC string header required

    MAC over the exact request body, obtained from POST /api/v1/pretokenised/mac. Missing or wrong answers 403 pretokenised_mac_invalid.

Request body

application/json ChatCompletionsRequest

  • attachments array of object

    Client-reviewed attachment text entries.

    Each item:

    • text string
  • clipboard string

    Optional client-reviewed clipboard text.

  • dimensions integer
    Range: at least 1
  • encoding_format string
    One of: "float", "base64"
  • frequency_penalty number
    Range: -2 to 2
  • max_completion_tokens integer
    Range: 1 to 200000
  • max_tokens integer
  • messages array of object required

    Only allowlisted message keys are accepted. annotations, audio metadata, url_citation, and other unknown message keys are rejected with 422 because they may contain text the client has not reviewed. Content parts also reject unknown keys and unsupported types. This gateway input subset is not measured against the upstream provider.

    Each item:

    • attachments array of object

      Client-reviewed attachment text entries.

      Each item:

      • text string
    • cache_control object
      • ttl string
        One of: "5m", "1h"
      • type string required
        One of: "ephemeral"
    • content any required

      One of

      • string
      • array of any

        Each item:

        One of

        • object
        • object
        • object
        • object
    • metadata object

      messages[*].metadata is removed before the request is forwarded. Root metadata keys must match the key class [A-Za-z0-9_.-]{1,32} and are not tokenized. Root string values that match the string class [A-Za-z0-9_.:@+/-]{0,512} are forwarded unchanged, except e-mail-form identity values, which are removed. A key or string outside its class receives 422.

    • role string required
      One of: "system", "developer", "user", "assistant"
    • tool_call_id any
    • tool_calls array of object

      Each item:

      • function object required
        • arguments string required
        • name string
      • id string
      • type string
        One of: "function"
  • metadata object

    messages[*].metadata is removed before the request is forwarded. Root metadata keys must match the key class [A-Za-z0-9_.-]{1,32} and are not tokenized. Root string values that match the string class [A-Za-z0-9_.:@+/-]{0,512} are forwarded unchanged, except e-mail-form identity values, which are removed. A key or string outside its class receives 422.

  • model string required
    Length: at most 64 characters. Pattern: ^(?!.*//)(?!.*(?:^|/)\.{1,2}(?:/|$))(?!.*\/$)[A-Za-z0-9][A-Za-z0-9._:/@~+-]{0,63}(?![\s\S])
  • n integer
    Range: 1 to 128
  • preprompt string

    Optional client-reviewed prompt prefix.

  • presence_penalty number
    Range: -2 to 2
  • provider string

    Provider identifier used for routing. Other values receive 422; inactive or unavailable providers receive 403.

    One of: "openai", "anthropic", "google", "azure", "grok", "openrouter", "gemini", "deepseek", "perplexity", "mistral", "cohere", "groq", "together", "fireworks"
  • reasoning_effort string

    Reasoning effort hint.

    One of: "none", "minimal", "low", "medium", "high", "xhigh", "max"
  • seed integer
    Range: 0 to 2147483647
  • stop any

    Operator configuration, not user text. One string or up to four strings, each at most 32 characters.

    One of

    • string
    • array of string
  • stream boolean
  • stream_options object

    Optional on streaming chat-completion requests to OpenAI-compatible providers. Only include_usage (boolean) is accepted; the gateway always requests usage on the provider stream. This field does not change the price.

    • include_usage boolean

      Optional. The gateway always requests a usage frame on the provider stream.

  • system any

    One of

    • string
    • array of object

      Each item:

      • cache_control object
        • ttl string
          One of: "5m", "1h"
        • type string required
          One of: "ephemeral"
      • text string required
      • type string required
        One of: "text"
  • temperature number
  • tool_choice any

    One of

    • string
    • object
      • function object required
        • name string required
      • type string required
        One of: "function"
  • tools array of object

    Each item:

    • function object

      Optional strict flag for function tools must be a boolean; string values such as "true" are rejected.

    • type string
      One of: "function"
  • top_p number
    Range: 0 to 1
  • user string

    Optional short identifier only. Arbitrary user strings are not supported yet and receive 422.

    Pattern: ^[A-Za-z0-9_.:-]{1,64}$

Generated sample

{
  "attachments": [
    {
      "text": "string"
    }
  ],
  "clipboard": "string",
  "dimensions": 1,
  "encoding_format": "float",
  "frequency_penalty": -2,
  "max_completion_tokens": 1,
  "max_tokens": 0,
  "messages": [
    {
      "attachments": [
        {
          "text": "string"
        }
      ],
      "cache_control": {
        "ttl": "5m",
        "type": "ephemeral"
      },
      "content": "string",
      "metadata": {},
      "role": "system",
      "tool_call_id": null,
      "tool_calls": [
        {
          "function": {
            "arguments": "string",
            "name": "string"
          },
          "id": "string",
          "type": "function"
        }
      ]
    }
  ],
  "metadata": {},
  "model": "string",
  "n": 1,
  "preprompt": "string",
  "presence_penalty": -2,
  "provider": "openai",
  "reasoning_effort": "none",
  "seed": 0,
  "stop": "string",
  "stream": true,
  "stream_options": {
    "include_usage": true
  },
  "system": "string",
  "temperature": 0,
  "tool_choice": "auto",
  "tools": [
    {
      "function": {
        "description": "string",
        "name": "string",
        "parameters": {
          "$defs": {},
          "$ref": "string",
          "additionalProperties": {},
          "allOf": [
            {}
          ],
          "anyOf": [
            {}
          ],
          "definitions": {},
          "description": "string",
          "examples": [
            "string"
          ],
          "exclusiveMaximum": 0,
          "exclusiveMinimum": 0,
          "format": "date-time",
          "items": {},
          "maxItems": 0,
          "maxLength": 0,
          "maxProperties": 0,
          "maximum": 0,
          "minItems": 0,
          "minLength": 0,
          "minProperties": 0,
          "minimum": 0,
          "multipleOf": 0,
          "not": {},
          "nullable": true,
          "oneOf": [
            {}
          ],
          "properties": {},
          "required": [
            "string"
          ],
          "title": "string",
          "type": "object",
          "uniqueItems": true
        },
        "strict": true
      },
      "type": "function"
    }
  ],
  "top_p": 0,
  "user": "string"
}

Responses

200 Chat completion

application/json ChatCompletionsResponse

  • choices array of object

    Each item:

    • finish_reason string
    • index integer
    • message object
      • content string or null
      • role string
  • created integer
  • id string
  • model string
  • object string
    Example: "chat.completion"
  • usage object
    • completion_tokens integer
    • prompt_tokens integer
    • total_tokens integer

Generated sample

{
  "choices": [
    {
      "finish_reason": "string",
      "index": 0,
      "message": {
        "content": "string",
        "role": "string"
      }
    }
  ],
  "created": 0,
  "id": "string",
  "model": "string",
  "object": "chat.completion",
  "usage": {
    "completion_tokens": 0,
    "prompt_tokens": 0,
    "total_tokens": 0
  }
}

text/event-stream string

400 Invalid request or unavailable chat model. Model selection failures use model_not_priced, model_retired, or model_unavailable and include error.suggested_model when a current alternative is available.

application/json any

One of

401 The API key is missing, invalid, expired, or paused for scheduled account deletion.

application/json object

  • error object required
    • type string required
      Value: "authentication_error"
    • code string required
      One of: "missing_api_key", "invalid_api_key", "expired_api_key", "account_not_found", "account_deletion_scheduled"
    • message string required
402 The account balance is insufficient to continue the request.

application/json object

  • error object required
    • type string required
      Value: "billing_error"
    • message string required
    • code string required
      Value: "insufficient_balance"
    • action string required
      Value: "topup"
    • top_up_url string required
    • grace_minutes integer required
    • wallet string required

      Spendable prepaid balance after in-flight holds. empty means the spendable amount is less than or equal to zero. short means a positive remainder that does not cover this request's hold. unknown means the wallet row could not be read.

      One of: "empty", "short", "unknown"
    • cloakup_plan string required

      Cloakup subscription state. It does not waive the wallet gate. active means the cloakup subscription is active. past_due means the subscription status is past_due, including inside a paid period. none means there is no cloakup subscription, the user is anonymous, or the subscription row could not be read.

      One of: "active", "past_due", "none"
403 Engine not recognized (engine_untrusted) or client MAC missing/invalid (pretokenised_mac_invalid).

application/json GenericError

  • error any

    One of

    • string
    • object

      Any keys are accepted.

  • error_code string
  • code string
  • message string
  • detail string
  • status any

    One of

    • string
    • integer
  • errors object

    Any keys are accepted.

409 An idempotency conflict or a stale client model catalog. model_unknown_refresh_catalogue remains HTTP 409 for compatibility with existing SDKs and includes error.suggested_model when a current alternative is available.

application/json any

Any of

413 Error response.

application/json GenericError

  • error any

    One of

    • string
    • object

      Any keys are accepted.

  • error_code string
  • code string
  • message string
  • detail string
  • status any

    One of

    • string
    • integer
  • errors object

    Any keys are accepted.

415 Request body must use Content-Type: application/json (unsupported_media_type).

application/json GenericError

  • error any

    One of

    • string
    • object

      Any keys are accepted.

  • error_code string
  • code string
  • message string
  • detail string
  • status any

    One of

    • string
    • integer
  • errors object

    Any keys are accepted.

422 An unrecognized message key can result in HTTP 422 with error.code=untokenisable_content_part. A model that does not support the chat endpoint also returns HTTP 422 with error.code=model_endpoint_unsupported and error.suggested_model (nullable).

application/json GenericError

  • error any

    One of

    • string
    • object

      Any keys are accepted.

  • error_code string
  • code string
  • message string
  • detail string
  • status any

    One of

    • string
    • integer
  • errors object

    Any keys are accepted.

426 Engine version below the minimum (min_engine_version in the body).

application/json GenericError

  • error any

    One of

    • string
    • object

      Any keys are accepted.

  • error_code string
  • code string
  • message string
  • detail string
  • status any

    One of

    • string
    • integer
  • errors object

    Any keys are accepted.

428 Either no engine identity was declared: X-Cloak-Engine-Version is missing and the request is not a declared rules-only send (engine_identity_required; the body carries min_engine_version and upgrade_url). Or the required client pre-tokenization assertion was missing (pretokenised_required). Response header X-Cloak-Pretokenised-Required: 1.

application/json GenericError

  • error any

    One of

    • string
    • object

      Any keys are accepted.

  • error_code string
  • code string
  • message string
  • detail string
  • status any

    One of

    • string
    • integer
  • errors object

    Any keys are accepted.

429 Rate limit exceeded

application/json GenericError

  • error any

    One of

    • string
    • object

      Any keys are accepted.

  • error_code string
  • code string
  • message string
  • detail string
  • status any

    One of

    • string
    • integer
  • errors object

    Any keys are accepted.

text/html string

503 The gateway could not process the request because tokenization is suspended for the account, a provider is unavailable, stream concurrency coordination is unavailable, or rate limiting is unavailable. error.type identifies the response category and error.code identifies the cause. Retry-After gives the applicable delay. X-RateLimit-Error is returned when rate limiting is unavailable.

Response headers

  • Retry-After string header

    Seconds to wait before retrying.

  • X-RateLimit-Error string header

    Present when rate limiting is unavailable.

application/json object

  • error object required
    • code string required
      One of: "internal_error", "provider_error", "rate_limiter_backend_unavailable", "tokenisation_suspended", "upstream_circuit_open"
    • message string required
    • retry_after_s integer
      Range: at least 1
    • type string required
      One of: "internal_error", "provider_error", "service_unavailable"