Skip to content

Create chat completion

POST /api/v1/chat/completions

OpenAI-compatible chat completion through the MATVIS firewall. The request is filtered (inbound and outbound) and forwarded to the model configuration you name. All provider parameters (temperature, max_completion_tokens, stream, ...) are passed through.

Request body

Schema: ChatCompletionRequest.

Field Type Required Description
model string Yes Name of the MATVIS model configuration to use, as defined in the dashboard.
messages ChatMessage[] Yes The conversation so far.

Example request

export MATVIS_URL="https://<your-matvis-host>"
export MATVIS_API_KEY="<your-firewall-api-key>"

curl -X POST "$MATVIS_URL/api/v1/chat/completions" \
  -H "Authorization: $MATVIS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "ollama-gpt-oss",
    "messages": [
      { "role": "user", "content": "Tell me about life in one sentence." }
    ],
    "stream": false,
    "temperature": 1
  }'

Responses

200 OK

Schema: ChatCompletionResponse.

{
  "id": "chatcmpl-231",
  "model": "ollama-gpt-oss",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "Life is a brief, ever-shifting journey of choices, growth, and connection that unfolds in quiet wonder and sudden surprise.",
        "annotations": []
      }
    }
  ]
}

Error codes

Blocks, model errors and LLM errors use the OpenAI error shape: { "error": { "message", "type", "code" } }. Errors about the API key, the license, a refused configuration, data not loaded yet, and a malformed body (422) use { "detail": ... }.

Code Meaning
403 A filter blocked the request or the reply. Also returned for a missing or unknown API key, an admin key, or an invalid license.
custom Your firewall configuration can set its own status code for blocks. With a 2xx code, the block message comes back as a normal completion instead of an error.
404 The model names no model configuration.
409 MATVIS refused the model configuration when it loaded it.
422 The request body was malformed.
502 The LLM could not be reached, returned an error, or sent a reply that could not be read.
503 The model configuration has an error, the request or reply could not be masked safely (see below), or API keys or configurations are not loaded yet.
403 example
{
  "error": {
    "message": "Message flagged for a PromptInjection violation (severity: 1.0, severity level: 10). Please revise your chat history.",
    "type": "DISALLOWED_CONTENT",
    "code": "CONTENT_POLICY_VIOLATION"
  }
}

422 Validation error

The request body was malformed. See HTTPValidationError.

422 example
{
  "detail": [
    {
      "type": "missing",
      "loc": ["body", "model"],
      "msg": "Field required",
      "input": { "messages": [{ "role": "user", "content": "Hello" }] }
    }
  ]
}

When a scan cannot run

If MATVIS cannot complete a guardrail scan (a filter is unavailable, the scanner is saturated, or the scan fails for another reason), the request is not blocked and no HTTP error is returned: it proceeds to the model and you receive a normal completion, streaming included. MATVIS is in your data path here, so failing the request would take your traffic down with the scanner.

The failure is recorded in the MATVIS application logs as a scan_unavailable record carrying the request's correlation id. Nothing is written to Firewall Analytics, so an outage never appears there as a detection.

There is one exception. When your configuration masks PII and a placeholder clashes, MATVIS cannot mask the request safely. It does not forward it and answers 503. A clash in the reply's scan withholds the reply the same way. Retrying the same request does not help.