{
  "openapi": "3.1.0",
  "info": {
    "title": "Reglint API",
    "version": "2026-11-15",
    "description": "Scan an AI agent's reply before it reaches the user, and report scan results to Reglint. Human docs: https://www.reglint.ai/docs#api-reference"
  },
  "servers": [
    {
      "url": "https://www.reglint.ai"
    }
  ],
  "paths": {
    "/api/monitor/scan": {
      "post": {
        "operationId": "scanOutput",
        "summary": "Scan an agent reply",
        "security": [
          {
            "apiKey": []
          }
        ],
        "description": "Full mode (default) typically answers in ~1–3 s, fast mode in under 1 s. Use a 30-second client timeout. Body at most 1 MB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ScanRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Scan result. Branch on final_decision.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ScanResponse"
                }
              }
            }
          },
          "400": {
            "description": "Malformed request (error.field names the field).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "VALIDATION_ERROR": {
                    "value": {
                      "error": {
                        "code": "VALIDATION_ERROR",
                        "message": "…"
                      }
                    }
                  },
                  "AGENT_OUTPUT_REQUIRED": {
                    "value": {
                      "error": {
                        "code": "AGENT_OUTPUT_REQUIRED",
                        "message": "…"
                      }
                    }
                  },
                  "INVALID_REQUEST_BODY": {
                    "value": {
                      "error": {
                        "code": "INVALID_REQUEST_BODY",
                        "message": "…"
                      }
                    }
                  },
                  "INVALID_MODE": {
                    "value": {
                      "error": {
                        "code": "INVALID_MODE",
                        "message": "…"
                      }
                    }
                  },
                  "INVALID_PRIVACY_MODE": {
                    "value": {
                      "error": {
                        "code": "INVALID_PRIVACY_MODE",
                        "message": "…"
                      }
                    }
                  },
                  "AUTH_CONTEXT_REQUIRED": {
                    "value": {
                      "error": {
                        "code": "AUTH_CONTEXT_REQUIRED",
                        "message": "…"
                      }
                    }
                  },
                  "CUSTOM_RULES_REQUIRED": {
                    "value": {
                      "error": {
                        "code": "CUSTOM_RULES_REQUIRED",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "x-api-key missing, invalid, revoked or expired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "UNAUTHORIZED": {
                    "value": {
                      "error": {
                        "code": "UNAUTHORIZED",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "No active subscription (error.upgrade_url), or a test-only parameter on a customer key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "NO_SUBSCRIPTION": {
                    "value": {
                      "error": {
                        "code": "NO_SUBSCRIPTION",
                        "message": "…"
                      }
                    }
                  },
                  "MODEL_SWITCH_FORBIDDEN": {
                    "value": {
                      "error": {
                        "code": "MODEL_SWITCH_FORBIDDEN",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            }
          },
          "413": {
            "description": "Body over 1 MB.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "PAYLOAD_TOO_LARGE": {
                    "value": {
                      "error": {
                        "code": "PAYLOAD_TOO_LARGE",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit (120 scans per minute per API key; Retry-After and RateLimit-* headers) or the plan's monthly quota (top-level upgrade_url).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "RATE_LIMIT_EXCEEDED": {
                    "value": {
                      "error": {
                        "code": "RATE_LIMIT_EXCEEDED",
                        "message": "…"
                      }
                    }
                  },
                  "AGENT_CALL_LIMIT_REACHED": {
                    "value": {
                      "error": {
                        "code": "AGENT_CALL_LIMIT_REACHED",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait (rate limit only)."
              }
            }
          },
          "500": {
            "description": "Unexpected server error. Retry with backoff; the key's on_error decides what to deliver meanwhile.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "INTERNAL_ERROR": {
                    "value": {
                      "error": {
                        "code": "INTERNAL_ERROR",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            }
          },
          "502": {
            "description": "The scan service could not be reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "LAMBDA_ERROR": {
                    "value": {
                      "error": {
                        "code": "LAMBDA_ERROR",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "description": "The scan service is unavailable or not configured.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "SERVICE_UNAVAILABLE": {
                    "value": {
                      "error": {
                        "code": "SERVICE_UNAVAILABLE",
                        "message": "…"
                      }
                    }
                  },
                  "NOT_CONFIGURED": {
                    "value": {
                      "error": {
                        "code": "NOT_CONFIGURED",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/agent-monitor/webhook": {
      "post": {
        "operationId": "reportScanResult",
        "summary": "Report a scan result (inbound webhook)",
        "security": [
          {
            "webhookSecret": []
          }
        ],
        "description": "Send a result your own pipeline produced to the Reglint dashboard. Idempotent on scan_id: a duplicate updates mutable fields. Retry on 5xx with exponential back-off.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookPayload"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Stored.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "received"
                  ],
                  "properties": {
                    "received": {
                      "type": "boolean",
                      "const": true
                    },
                    "id": {
                      "type": "string"
                    },
                    "replayed": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Missing required fields: scan_id, customer_id, agent_name or final_decision.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "VALIDATION_ERROR": {
                    "value": {
                      "error": {
                        "code": "VALIDATION_ERROR",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "x-reglint-secret missing or wrong.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "UNAUTHORIZED": {
                    "value": {
                      "error": {
                        "code": "UNAUTHORIZED",
                        "message": "…"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "Your rgl_ API key. Keep it server-side."
      },
      "webhookSecret": {
        "type": "apiKey",
        "in": "header",
        "name": "x-reglint-secret"
      }
    },
    "schemas": {
      "ScanRequest": {
        "type": "object",
        "required": [
          "agent_output"
        ],
        "additionalProperties": true,
        "properties": {
          "agent_output": {
            "description": "The reply your agent is about to send: a string, or a raw OpenAI / Anthropic message (text content or tool calls). Any other type is a 400 VALIDATION_ERROR (field agent_output).",
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object"
              },
              {
                "type": "array",
                "items": {
                  "type": "object"
                }
              }
            ]
          },
          "user_input": {
            "type": "string",
            "description": "The customer message the reply answers (optional, recommended). Gives the engine the request context; without it the reply is judged on its own."
          },
          "proposed_action": {
            "type": "object",
            "description": "A tool call the agent intends to run (action-level scan, full mode). Args are scanned by the rules engine; the model judges the risk of the action.",
            "properties": {
              "tool": {
                "type": "string",
                "description": "Tool / function name."
              },
              "args": {
                "type": "object",
                "additionalProperties": true,
                "description": "The arguments the agent would pass."
              }
            },
            "required": [
              "tool"
            ]
          },
          "declared_rationale": {
            "type": "string",
            "description": "Why the agent says it is taking the proposed_action (judged together with it)."
          },
          "agent_name": {
            "type": "string",
            "description": "Which agent produced it."
          },
          "industry": {
            "type": "string",
            "description": "Rule set; default the key policy, else general."
          },
          "mode": {
            "type": "string",
            "enum": [
              "full",
              "fast"
            ],
            "default": "full"
          },
          "language": {
            "type": "string",
            "enum": [
              "en",
              "ar"
            ],
            "description": "Optional; detected from the text when absent. Case-insensitive. Any other value is a 400 VALIDATION_ERROR (field language)."
          },
          "countries": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "ISO codes whose law applies, e.g. [\"sa\"]."
          },
          "region": {
            "type": "string"
          },
          "actor_type": {
            "type": "string",
            "enum": [
              "agent",
              "human"
            ],
            "default": "human"
          },
          "channel": {
            "type": "string",
            "description": "Optional. Agents / API: api, email, sms, chat, web, voice, phone, webhook. Browser extension: gmail, outlook, teams, slack, whatsapp, linkedin, chatgpt, claude-web, gemini, deepseek, copilot, perplexity (host forms such as mail.google.com are mapped). Any other value is a 400 VALIDATION_ERROR (field channel)."
          },
          "customer_id": {
            "type": "string",
            "description": "Your end user's id (optional)."
          },
          "privacy_mode": {
            "type": "string",
            "enum": [
              "strict",
              "trust",
              "authenticated",
              "custom"
            ],
            "default": "strict"
          },
          "auth_context": {
            "type": "object",
            "description": "Required when privacy_mode is authenticated.",
            "properties": {
              "user_authenticated": {
                "type": "boolean"
              }
            }
          },
          "custom_rules": {
            "type": "object",
            "description": "Required when privacy_mode is custom."
          },
          "ai_system": {
            "$ref": "#/components/schemas/AiSystem"
          },
          "agent_meta": {
            "$ref": "#/components/schemas/AgentMeta"
          }
        }
      },
      "AiSystem": {
        "type": "object",
        "description": "The AI system that produced the reply (AI register, 'declared').",
        "properties": {
          "provider": {
            "type": "string",
            "maxLength": 64
          },
          "model": {
            "type": "string",
            "maxLength": 128
          },
          "version": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        }
      },
      "AgentMeta": {
        "type": "object",
        "description": "What your agent SDK knows; every field optional. provider / model fill the AI register ('Reported by SDK').",
        "properties": {
          "model": {
            "type": "string",
            "maxLength": 128
          },
          "provider": {
            "type": "string",
            "maxLength": 64
          },
          "provider_region": {
            "type": "string",
            "maxLength": 64
          },
          "temperature": {
            "type": "number",
            "minimum": 0,
            "maximum": 10
          },
          "tools": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 128
            },
            "maxItems": 64
          },
          "system_prompt_hash": {
            "type": "string",
            "maxLength": 128
          },
          "sdk": {
            "type": "string",
            "maxLength": 64
          },
          "sdk_version": {
            "type": "string",
            "maxLength": 64
          },
          "system_prompt": {
            "type": "string",
            "maxLength": 32000,
            "description": "The system prompt text, on the first scan and after a change: audited automatically after the response; never stored on the scan."
          }
        }
      },
      "Violation": {
        "type": "object",
        "properties": {
          "violation_id": {
            "type": "string"
          },
          "severity": {
            "type": "string",
            "enum": [
              "critical",
              "high",
              "medium",
              "low"
            ]
          },
          "recommended_action": {
            "type": "string",
            "enum": [
              "BLOCK",
              "HITL",
              "REDACT",
              "ALERT",
              "PASS"
            ],
            "description": "PASS = a finding kept for the audit trail only (the key set this class to PASS)."
          },
          "law": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "violating_text": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "description": "rules_engine | claude_analysis | custom_policy | …"
          },
          "identifier_no_article_cap": {
            "type": "boolean",
            "description": "An identifier finding with no article in the key's countries' law (or an off market): ALERT, masked in redacted_output."
          }
        }
      },
      "ScanResponse": {
        "type": "object",
        "required": [
          "scan_id",
          "final_decision",
          "safe_to_deliver",
          "violations"
        ],
        "properties": {
          "scan_id": {
            "type": "string",
            "format": "uuid"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "final_decision": {
            "type": "string",
            "enum": [
              "BLOCK",
              "REDACT",
              "ALERT_HITL",
              "ALERT",
              "PASS"
            ]
          },
          "safe_to_deliver": {
            "type": "boolean",
            "description": "true only for PASS and ALERT — branch on final_decision (REDACT is deliverable as redacted_output)."
          },
          "violations_count": {
            "type": "integer"
          },
          "violations": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Violation"
            }
          },
          "original_output": {
            "type": "string",
            "description": "Your text; \"[BLOCKED]\" on BLOCK and \"[HELD_FOR_REVIEW]\" on ALERT_HITL, in every privacy_mode."
          },
          "redacted_output": {
            "type": "string",
            "description": "Your text with identifiers and REDACT spans masked. Deliver on REDACT; on PASS / ALERT deliver it when present."
          },
          "processing_time_ms": {
            "type": "integer"
          },
          "privacy_mode": {
            "type": "string",
            "enum": [
              "strict",
              "trust",
              "authenticated",
              "custom"
            ]
          },
          "behavior": {
            "type": "string",
            "enum": [
              "block",
              "warn-only",
              "log-only"
            ],
            "description": "The key's EXTENSION setting, not the decision."
          },
          "custom_rules_applied": {
            "type": "boolean",
            "description": "privacy_mode custom rules applied. A company policy that fired is a violation with source custom_policy."
          },
          "custom_policies_evaluated": {
            "type": "boolean"
          },
          "on_error": {
            "type": "string",
            "enum": [
              "allow",
              "block"
            ],
            "description": "The key's setting for when a scan fails."
          },
          "metadata": {
            "type": "object",
            "properties": {
              "primary_class": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "Class of the top finding (highest action, then severity); null on PASS."
              }
            }
          }
        }
      },
      "WebhookPayload": {
        "type": "object",
        "required": [
          "scan_id",
          "customer_id",
          "agent_name",
          "final_decision"
        ],
        "properties": {
          "scan_id": {
            "type": "string",
            "description": "Unique scan UUID (idempotency key)."
          },
          "customer_id": {
            "type": "string"
          },
          "agent_name": {
            "type": "string"
          },
          "industry": {
            "type": "string"
          },
          "final_decision": {
            "type": "string",
            "enum": [
              "BLOCK",
              "REDACT",
              "ALERT",
              "PASS"
            ]
          },
          "violations_count": {
            "type": "integer"
          },
          "violations": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "violation_id": {
                  "type": "string"
                },
                "type": {
                  "type": "string",
                  "description": "Legacy alias for violation_id."
                },
                "law": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "violating_text": {
                  "type": "string"
                },
                "action": {
                  "type": "string",
                  "enum": [
                    "BLOCK",
                    "REDACT",
                    "ALERT"
                  ]
                },
                "severity": {
                  "type": "string"
                }
              }
            }
          },
          "original_output": {
            "type": "string"
          },
          "redacted_output": {
            "type": "string"
          },
          "agent_endpoint": {
            "type": "string"
          },
          "processing_time_ms": {
            "type": "integer"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "Stable — branch on it."
              },
              "message": {
                "type": "string"
              },
              "field": {
                "type": "string",
                "description": "The request field at fault (validation errors)."
              },
              "upgrade_url": {
                "type": "string"
              }
            }
          },
          "retry_after": {
            "type": "integer"
          },
          "upgrade_url": {
            "type": "string"
          },
          "scan_id": {
            "type": "string"
          }
        }
      }
    }
  }
}
