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-TierPrivacyMode headerWhich 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 MellowsbecomesHenry 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 Mellowsbecomes<<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_moderather than reinterpreted — a header is code you just wrote, and silently resolving a typo is how an integration ships believing a privacy setting works.offandcontinuitywere retired on 2026-07-28: there is no unprotected posture, and cross-turn stability is now unconditional.X-Cloak-Engine-Versionstring headerClient-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 (seeX-CloakAPI-Tokenized); any other request without it is answered 428engine_identity_required.Example:"1.6.0"X-Cloak-Engine-Hashstring headerClient-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_untrustedwhen missing or unknown; this does not prove that binary ran. Leave it out, together withX-Cloak-Engine-Version, only on a declared rules-only send.X-CloakAPI-Tokenizedstring headerClient-declared detection coverage, written
true;coverage=full,true;coverage=rules_and_namesortrue;coverage=rules_only. A client that ran rule-based detection without an engine sends exactlytrue;coverage=rules_only, sends neitherX-Cloak-Engine-VersionnorX-Cloak-Engine-Hash, and still sendsX-Cloak-PretokenisedandX-Cloak-Client-MAC. The gateway then relays the request without an engine identity, answers with the response headerX-Cloak-Coverageset torules_only, and signs a receipt that recordsx-cloakapi-detectionwithengine_identityset tonot_declaredandgenuine_engineset 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-Pretokenisedstring header requiredClient 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-MACstring header requiredMAC over the exact request body, obtained from
POST /api/v1/pretokenised/mac. Missing or wrong answers 403pretokenised_mac_invalid.
Request body
application/json ChatCompletionsRequest
attachmentsarray of objectClient-reviewed attachment text entries.
Each item:
textstring
clipboardstringOptional client-reviewed clipboard text.
dimensionsintegerRange: at least 1encoding_formatstringOne of:"float","base64"frequency_penaltynumberRange: -2 to 2max_completion_tokensintegerRange: 1 to 200000max_tokensintegermessagesarray of object requiredOnly 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:
attachmentsarray of objectClient-reviewed attachment text entries.
Each item:
textstring
cache_controlobjectttlstringOne of:"5m","1h"typestring requiredOne of:"ephemeral"
contentany requiredOne of
- string
- array of any
Each item:
One of
- object
- object
- object
- object
metadataobjectmessages[*].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.
rolestring requiredOne of:"system","developer","user","assistant"tool_call_idanytool_callsarray of objectEach item:
functionobject requiredargumentsstring requirednamestring
idstringtypestringOne of:"function"
metadataobjectmessages[*].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.
modelstring requiredLength: at most 64 characters. Pattern:^(?!.*//)(?!.*(?:^|/)\.{1,2}(?:/|$))(?!.*\/$)[A-Za-z0-9][A-Za-z0-9._:/@~+-]{0,63}(?![\s\S])nintegerRange: 1 to 128prepromptstringOptional client-reviewed prompt prefix.
presence_penaltynumberRange: -2 to 2providerstringProvider 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_effortstringReasoning effort hint.
One of:"none","minimal","low","medium","high","xhigh","max"seedintegerRange: 0 to 2147483647stopanyOperator configuration, not user text. One string or up to four strings, each at most 32 characters.
One of
- string
- array of string
streambooleanstream_optionsobjectOptional 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_usagebooleanOptional. The gateway always requests a usage frame on the provider stream.
systemanyOne of
- string
- array of object
Each item:
cache_controlobjectttlstringOne of:"5m","1h"typestring requiredOne of:"ephemeral"
textstring requiredtypestring requiredOne of:"text"
temperaturenumbertool_choiceanyOne of
- string
- object
functionobject requirednamestring required
typestring requiredOne of:"function"
toolsarray of objectEach item:
functionobjectOptional strict flag for function tools must be a boolean; string values such as "true" are rejected.
descriptionstring requirednamestringparametersReviewedToolJsonSchemastrictboolean
typestringOne of:"function"
top_pnumberRange: 0 to 1userstringOptional 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
choicesarray of objectEach item:
finish_reasonstringindexintegermessageobjectcontentstring or nullrolestring
createdintegeridstringmodelstringobjectstringExample:"chat.completion"usageobjectcompletion_tokensintegerprompt_tokensintegertotal_tokensinteger
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
errorobject requiredtypestring requiredValue:"authentication_error"codestring requiredOne of:"missing_api_key","invalid_api_key","expired_api_key","account_not_found","account_deletion_scheduled"messagestring required
402 The account balance is insufficient to continue the request.
application/json object
errorobject requiredtypestring requiredValue:"billing_error"messagestring requiredcodestring requiredValue:"insufficient_balance"actionstring requiredValue:"topup"top_up_urlstring requiredgrace_minutesinteger requiredwalletstring requiredSpendable 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_planstring requiredCloakup 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
erroranyOne of
- string
- object
Any keys are accepted.
error_codestringcodestringmessagestringdetailstringstatusanyOne of
- string
- integer
errorsobjectAny 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
erroranyOne of
- string
- object
Any keys are accepted.
error_codestringcodestringmessagestringdetailstringstatusanyOne of
- string
- integer
errorsobjectAny keys are accepted.
415 Request body must use Content-Type: application/json (unsupported_media_type).
application/json GenericError
erroranyOne of
- string
- object
Any keys are accepted.
error_codestringcodestringmessagestringdetailstringstatusanyOne of
- string
- integer
errorsobjectAny 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
erroranyOne of
- string
- object
Any keys are accepted.
error_codestringcodestringmessagestringdetailstringstatusanyOne of
- string
- integer
errorsobjectAny keys are accepted.
426 Engine version below the minimum (min_engine_version in the body).
application/json GenericError
erroranyOne of
- string
- object
Any keys are accepted.
error_codestringcodestringmessagestringdetailstringstatusanyOne of
- string
- integer
errorsobjectAny 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
erroranyOne of
- string
- object
Any keys are accepted.
error_codestringcodestringmessagestringdetailstringstatusanyOne of
- string
- integer
errorsobjectAny keys are accepted.
429 Rate limit exceeded
application/json GenericError
erroranyOne of
- string
- object
Any keys are accepted.
error_codestringcodestringmessagestringdetailstringstatusanyOne of
- string
- integer
errorsobjectAny 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-Afterstring headerSeconds to wait before retrying.
X-RateLimit-Errorstring headerPresent when rate limiting is unavailable.
application/json object
errorobject requiredcodestring requiredOne of:"internal_error","provider_error","rate_limiter_backend_unavailable","tokenisation_suspended","upstream_circuit_open"messagestring requiredretry_after_sintegerRange: at least 1typestring requiredOne of:"internal_error","provider_error","service_unavailable"