Create a message (Anthropic-compatible)¶
POST /api/v1/messages
Anthropic Messages API compatible endpoint; a base-URL drop-in replacement for https://api.anthropic.com/v1/messages. The request is filtered through the MATVIS firewall (inbound and outbound), forwarded to the configured LLM, and returned in Anthropic Messages shape. Supports streaming via server-sent events when stream is true.
Request body¶
| Field | Type | Required | Description |
|---|---|---|---|
model |
string |
Yes | Name of the MATVIS model configuration to use, as defined in the dashboard. |
messages |
AnthropicMessage[] |
Yes | The conversation history in Anthropic Messages format. |
max_tokens |
integer |
Yes | Maximum number of tokens to generate before stopping. |
system |
string \| object[] |
No | System prompt: a plain string or a list of text content blocks. |
stream |
boolean |
No | Whether to stream the response using server-sent events. |
Each AnthropicMessage has a role (user or assistant; only the system prompt goes in the top-level system field, not in messages) and a content (a string or a list of content blocks). Other Anthropic parameters (temperature, tools, stop_sequences, ...) are accepted and passed through.
Authentication¶
Send your Firewall API key in the Authorization header, with or without a Bearer prefix, or in the x-api-key header as Anthropic clients do.
Example request¶
export MATVIS_URL="https://<your-matvis-host>"
export MATVIS_API_KEY="<your-firewall-api-key>"
curl -X POST "$MATVIS_URL/api/v1/messages" \
-H "Authorization: $MATVIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "SafeModel",
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "Tell me about life in one sentence." }
],
"stream": false
}'
Responses¶
200 OK¶
Anthropic Messages shape (AnthropicMessagesResponse):
| Field | Type | Description |
|---|---|---|
id |
string |
Message identifier. |
type |
string |
Always "message". |
role |
string |
Always "assistant". |
model |
string |
Model configuration used. |
content |
object[] |
Generated content blocks (e.g. { "type": "text", "text": ... }). |
stop_reason |
string \| null |
Why generation stopped (e.g. end_turn, max_tokens). |
stop_sequence |
string \| null |
The stop sequence hit, if any. |
usage |
object |
Token usage (input_tokens, output_tokens). |
{
"id": "msg_013Zva2CMHLNnXjNJJKqJ2EF",
"type": "message",
"role": "assistant",
"model": "SafeModel",
"stop_reason": "end_turn",
"content": [
{ "type": "text", "text": "Life is a brief, ever-shifting journey." }
],
"usage": {
"input_tokens": 12,
"output_tokens": 18
}
}
Error codes¶
Blocks, model errors and LLM errors use the Anthropic error shape: { "type": "error", "error": { "type", "message" } }. Errors about the API key, the license, a refused configuration, data not loaded yet, and a malformed body (422) use { "detail": ... }.
| Code | Meaning |
|---|---|
400 |
A message holds only content blocks MATVIS cannot pass on (for example only thinking blocks). |
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 message with stop_reason: "end_turn" instead of an error. |
404 |
The model names no model configuration. |
409 |
MATVIS refused the model configuration when it loaded it. |
415 |
An image source type that MATVIS cannot convert. |
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
422 Validation error¶
The request body was malformed. See HTTPValidationError.
422 example
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.