{
  "openapi": "3.1.0",
  "info": {
    "title": "Guardrail Runtime",
    "version": "0.1.0"
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/request": {
      "post": {
        "operationId": "evaluateRequest",
        "parameters": [
          {
            "name": "x-ap-gr-policy-id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ap-gr-policy-revision",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ap-gr-bundle-digest",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ap-gr-content-profile",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ap-gr-response-mode",
            "in": "header",
            "required": false,
            "description": "Required for agentgateway-1.5.0-chat-webhook-v2. Trusted configuration: buffered for a complete response, sse-reject for streaming. Response redact matches are rejected in sse-reject mode.",
            "schema": {
              "type": "string",
              "enum": [
                "buffered",
                "sse-reject"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Request"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Native action. A content denial is HTTP 200 with action.status_code 403.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RequestResult"
                }
              }
            }
          },
          "400": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/response": {
      "post": {
        "operationId": "evaluateResponse",
        "parameters": [
          {
            "name": "x-ap-gr-policy-id",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ap-gr-policy-revision",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ap-gr-bundle-digest",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ap-gr-content-profile",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-ap-gr-response-mode",
            "in": "header",
            "required": false,
            "description": "Required for agentgateway-1.5.0-chat-webhook-v2. Trusted configuration: buffered for a complete response, sse-reject for streaming. Response redact matches are rejected in sse-reject mode.",
            "schema": {
              "type": "string",
              "enum": [
                "buffered",
                "sse-reject"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Response"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Native action. A content denial is HTTP 200 with action.status_code 403.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResponseResult"
                }
              }
            }
          },
          "400": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "415": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Check failure; never a PassAction.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/readyz": {
      "get": {
        "operationId": "readReadiness",
        "security": [],
        "responses": {
          "200": {
            "description": "Immutable bundle loaded; no Gateway serving claim."
          },
          "503": {
            "description": "Not ready."
          }
        }
      }
    },
    "/metrics": {
      "get": {
        "operationId": "readMetrics",
        "responses": {
          "200": {
            "description": "Bounded Prometheus process counters."
          },
          "401": {
            "description": "Authentication required."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Dedicated service token from a mounted file. Never forward the original caller token."
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "traceId": {
            "type": "string"
          }
        },
        "required": [
          "code",
          "message",
          "traceId"
        ]
      },
      "Request": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "body": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "messages": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "role": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 32
                    },
                    "content": {
                      "type": "string",
                      "maxLength": 2097152
                    }
                  },
                  "required": [
                    "role",
                    "content"
                  ]
                },
                "minItems": 1,
                "maxItems": 64
              }
            },
            "required": [
              "messages"
            ]
          }
        },
        "required": [
          "body"
        ]
      },
      "Response": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "body": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "choices": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "message": {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "role": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 32
                        },
                        "content": {
                          "type": "string",
                          "maxLength": 2097152
                        }
                      },
                      "required": [
                        "role",
                        "content"
                      ]
                    }
                  },
                  "required": [
                    "message"
                  ]
                },
                "minItems": 1,
                "maxItems": 64
              }
            },
            "required": [
              "choices"
            ]
          }
        },
        "required": [
          "body"
        ]
      },
      "Pass": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "reason": {
            "const": "policy_pass"
          }
        },
        "required": [
          "reason"
        ]
      },
      "Reject": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "body": {
            "const": "Запрос отклонён политикой"
          },
          "status_code": {
            "const": 403
          },
          "reason": {
            "const": "policy_denied"
          }
        },
        "required": [
          "body",
          "status_code",
          "reason"
        ]
      },
      "RequestMask": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "body": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "messages": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "role": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 32
                    },
                    "content": {
                      "type": "string",
                      "maxLength": 2097152
                    }
                  },
                  "required": [
                    "role",
                    "content"
                  ]
                },
                "minItems": 1,
                "maxItems": 64
              }
            },
            "required": [
              "messages"
            ]
          },
          "reason": {
            "const": "content_redacted"
          }
        },
        "required": [
          "body",
          "reason"
        ]
      },
      "ResponseMask": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "body": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "choices": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "message": {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "role": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 32
                        },
                        "content": {
                          "type": "string",
                          "maxLength": 2097152
                        }
                      },
                      "required": [
                        "role",
                        "content"
                      ]
                    }
                  },
                  "required": [
                    "message"
                  ]
                },
                "minItems": 1,
                "maxItems": 64
              }
            },
            "required": [
              "choices"
            ]
          },
          "reason": {
            "const": "content_redacted"
          }
        },
        "required": [
          "body",
          "reason"
        ]
      },
      "RequestResult": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Pass"
              },
              {
                "$ref": "#/components/schemas/Reject"
              },
              {
                "$ref": "#/components/schemas/RequestMask"
              }
            ]
          }
        },
        "required": [
          "action"
        ]
      },
      "ResponseResult": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "action": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Pass"
              },
              {
                "$ref": "#/components/schemas/Reject"
              },
              {
                "$ref": "#/components/schemas/ResponseMask"
              }
            ]
          }
        },
        "required": [
          "action"
        ]
      }
    }
  }
}
