帮你快速理解、总结文档立即下载

修改自定义安全护栏策略

最近更新时间:2026-11-03 02:54:51
我的收藏

1. 接口描述

接口请求域名: tse.tencentcloudapi.com 。

局部修改已有策略并重新同步。省略字段保留原值,显式 false/0/[] 与省略不同;数组按整体替换,Scope 传入时替换完整范围。切换 AddressMode 时会自动清除未显式传入的另一模式地址字段;AuthType=none 会清除已有密钥并默认清空 HeaderName。请检查 Result.Success 和 FailedResources。网关需满足最低版本 3.9.6,且已安装、启用并加载 cngw-ai-custom-guardrail。创建、修改、删除要求网关处于稳定 Running 状态,升级/回滚/撤销升级期间不能修改策略。

本产品为 tse,版本为 2020-12-07。公共参数及签名按云 API 规范配置;在 API Explorer 选择目标环境,示例正文仅为业务参数,中文诊断示例以公共参数 Language=zh-CN 为前提。响应业务字段统一位于 Response.Result,Response.RequestId 为云 API 请求 ID;HTTP 成功不代表 Result.Success=true。示例 ID、域名和鉴权值均为占位内容,须替换为实际值。

输入约束:新配置只接受 field_mapping,不再默认为 standard_v2。创建时鉴权和检测行为必须完整填写;修改为 PATCH,省略保留,显式空值不补默认值。存量 standard_v2 策略仍可查询、删除或直接停用;修改其判定配置或重新启用前需迁移到 field_mapping。条件必填由后端按完整配置校验,非法配置不写库、不下发。

默认接口请求频率限制:20次/秒。

推荐使用 API Explorer
点击调试
API Explorer 提供了在线调用、签名验证、SDK 代码生成和快速检索接口等能力。您可查看每次调用的请求内容和返回结果以及自动生成 SDK 调用示例。

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数。

参数名称 必选 类型 描述
Action 是 String 公共参数,本接口取值:ModifyAIGWCustomGuardrailPolicy。
Version 是 String 公共参数,本接口取值:2020-12-07。
Region 是 String 公共参数,详见产品支持的 地域列表,本接口仅支持其中的: ap-bangkok, ap-beijing, ap-chengdu, ap-guangzhou, ap-hongkong, ap-jakarta, ap-nanjing, ap-seoul, ap-shanghai, ap-shanghai-fsi, ap-shenzhen-fsi, ap-singapore, ap-tokyo, eu-frankfurt, na-ashburn, na-siliconvalley 。
GatewayId 是 String

网关实例 ID


示例值:gateway-12345678
PolicyId 是 String

策略 ID


示例值:11111111-1111-4111-8111-111111111111
Name 否 String

策略名称,长度 1~64


示例值:mcp-content-guardrail
Description 否 String

策略描述,最长 200;传空字符串可清空


示例值:MCP 请求与响应安全审核策略
Enabled 否 Boolean

是否启用策略


示例值:true
ServiceConfig 否 CustomGuardrailServiceConfigPatch

审核服务局部更新配置

AuthConfig 否 CustomGuardrailAuthConfigPatch

审核服务鉴权局部更新配置

DecisionConfig 否 CustomGuardrailDecisionConfigPatch

审核响应判定局部更新配置

BehaviorConfig 否 CustomGuardrailBehaviorConfigPatch

处理行为局部更新配置

FilterConfig 否 CustomGuardrailFilterConfigPatch

过滤与采样局部更新配置

Scope 否 CustomGuardrailScopeInput

资源绑定范围,global 或 resource。修改时传入的是新的完整范围,不是增量追加。

3. 输出参数

参数名称 类型 描述
Result ModifyAIGWCustomGuardrailPolicyResult

接口业务结果,位于完整云 API 响应 Response.Result。存在 Success 时仍须单独判断;Response.RequestId 是本次云 API 请求标识。

RequestId String 唯一请求 ID,由服务端生成,每次请求都会返回(若请求因其他原因未能抵达服务端,则该次请求不会获得 RequestId)。定位问题时需要提供该次请求的 RequestId。

4. 示例

示例1 关闭审核引擎鉴权并清除旧密钥

只修改网关访问审核引擎的鉴权,不关闭客户端访问网关的鉴权。 这是说明性示例,未执行真实资源操作;响应字段以目标环境实际部署版本为准。

输入示例

POST / HTTP/1.1
Host: tse.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: ModifyAIGWCustomGuardrailPolicy
X-TC-Version: 2020-12-07
X-TC-Region: ap-guangzhou
<其他公共请求参数与 TC3 签名>

{
    "GatewayId": "gateway-12345678",
    "PolicyId": "11111111-1111-4111-8111-111111111111",
    "AuthConfig": {
        "AuthType": "none",
        "ClearApiKey": true
    }
}

输出示例

{
    "Response": {
        "Result": {
            "Success": true,
            "Policy": {
                "PolicyId": "11111111-1111-4111-8111-111111111111",
                "Name": "mcp-custom-audit",
                "Description": "MCP Streamable HTTP 输入审核",
                "Enabled": true,
                "EffectiveEnabled": true,
                "ServiceConfig": {
                    "AddressMode": "manual",
                    "Endpoint": "https://audit.example.com/v2/audit",
                    "SSLVerify": true,
                    "QueryPassthroughEnabled": false,
                    "HeaderAllowList": []
                },
                "AuthConfig": {
                    "AuthType": "none",
                    "HasApiKey": false
                },
                "DecisionConfig": {
                    "ContractMode": "field_mapping",
                    "BlockMessageMode": "response",
                    "BlockMessage": "您的请求可能包含不安全内容,已被安全策略拦截。请修改后重试。",
                    "RewriteEnabled": false,
                    "FieldMapping": {
                        "HitFieldPath": "decision",
                        "HitValue": "\"block\"",
                        "MessageFieldPath": "message"
                    }
                },
                "BehaviorConfig": {
                    "Direction": "input",
                    "HandleAction": "block",
                    "TimeoutMs": 5000,
                    "FailureMode": "closed"
                },
                "FilterConfig": {
                    "RequestStreamMode": "all",
                    "ResponseStreamMode": "all",
                    "RequestKeywords": [],
                    "ResponseKeywords": [],
                    "KeywordMatchMode": "any",
                    "KeywordCaseSensitive": false,
                    "SamplingEnabled": false,
                    "RequestSamplingRate": 1,
                    "ResponseSamplingRate": 1
                },
                "Scope": {
                    "BindType": "resource",
                    "Resources": [
                        {
                            "ResourceType": "mcp_server",
                            "ResourceId": "22222222-2222-4222-8222-222222222222"
                        }
                    ]
                },
                "Bindings": [
                    {
                        "ResourceType": "mcp_server",
                        "ResourceId": "22222222-2222-4222-8222-222222222222",
                        "ResourceName": "示例 MCP 服务",
                        "Path": "/mcp/example",
                        "Protocol": "mcp",
                        "RouteId": "44444444-4444-4444-8444-444444444444",
                        "PluginId": "88888888-8888-4888-8888-888888888888",
                        "SyncStatus": "synced"
                    }
                ],
                "SyncStatus": "synced",
                "CreateTime": "2026-09-08 10:00:00",
                "ModificationTime": "2026-09-08 10:00:00"
            },
            "AddedResources": [
                {
                    "ResourceType": "mcp_server",
                    "ResourceId": "22222222-2222-4222-8222-222222222222"
                }
            ],
            "RemovedCount": 0,
            "FailedResources": [],
            "SyncStatus": "synced"
        },
        "RequestId": "77777777-7777-4777-8777-777777777777"
    }
}

示例2 开启响应审核与内容改写

以已有 field_mapping 策略为前提,未传的审核地址、命中字段与其他配置保留。 这是说明性示例,未执行真实资源操作;响应字段以目标环境实际部署版本为准。

输入示例

POST / HTTP/1.1
Host: tse.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: ModifyAIGWCustomGuardrailPolicy
X-TC-Version: 2020-12-07
X-TC-Region: ap-guangzhou
<其他公共请求参数与 TC3 签名>

{
    "GatewayId": "gateway-12345678",
    "PolicyId": "11111111-1111-4111-8111-111111111111",
    "BehaviorConfig": {
        "Direction": "both"
    },
    "DecisionConfig": {
        "RewriteEnabled": true,
        "FieldMapping": {
            "RewriteFieldPath": "content.body"
        }
    }
}

输出示例

{
    "Response": {
        "Result": {
            "Success": true,
            "Policy": {
                "PolicyId": "11111111-1111-4111-8111-111111111111",
                "Name": "mcp-custom-audit",
                "Description": "MCP Streamable HTTP 输入审核",
                "Enabled": true,
                "EffectiveEnabled": true,
                "ServiceConfig": {
                    "AddressMode": "manual",
                    "Endpoint": "https://audit.example.com/v2/audit",
                    "SSLVerify": true,
                    "QueryPassthroughEnabled": false,
                    "HeaderAllowList": []
                },
                "AuthConfig": {
                    "AuthType": "none",
                    "HasApiKey": false
                },
                "DecisionConfig": {
                    "ContractMode": "field_mapping",
                    "BlockMessageMode": "response",
                    "BlockMessage": "您的请求可能包含不安全内容,已被安全策略拦截。请修改后重试。",
                    "RewriteEnabled": true,
                    "FieldMapping": {
                        "HitFieldPath": "decision",
                        "HitValue": "\"block\"",
                        "MessageFieldPath": "message",
                        "RewriteFieldPath": "content.body"
                    }
                },
                "BehaviorConfig": {
                    "Direction": "both",
                    "HandleAction": "block",
                    "TimeoutMs": 5000,
                    "FailureMode": "closed"
                },
                "FilterConfig": {
                    "RequestStreamMode": "all",
                    "ResponseStreamMode": "all",
                    "RequestKeywords": [],
                    "ResponseKeywords": [],
                    "KeywordMatchMode": "any",
                    "KeywordCaseSensitive": false,
                    "SamplingEnabled": false,
                    "RequestSamplingRate": 1,
                    "ResponseSamplingRate": 1
                },
                "Scope": {
                    "BindType": "resource",
                    "Resources": [
                        {
                            "ResourceType": "mcp_server",
                            "ResourceId": "22222222-2222-4222-8222-222222222222"
                        }
                    ]
                },
                "Bindings": [
                    {
                        "ResourceType": "mcp_server",
                        "ResourceId": "22222222-2222-4222-8222-222222222222",
                        "ResourceName": "示例 MCP 服务",
                        "Path": "/mcp/example",
                        "Protocol": "mcp",
                        "RouteId": "44444444-4444-4444-8444-444444444444",
                        "PluginId": "88888888-8888-4888-8888-888888888888",
                        "SyncStatus": "synced"
                    }
                ],
                "SyncStatus": "synced",
                "CreateTime": "2026-09-08 10:00:00",
                "ModificationTime": "2026-09-08 10:00:00"
            },
            "AddedResources": [
                {
                    "ResourceType": "mcp_server",
                    "ResourceId": "22222222-2222-4222-8222-222222222222"
                }
            ],
            "RemovedCount": 0,
            "FailedResources": [],
            "SyncStatus": "synced"
        },
        "RequestId": "77777777-7777-4777-8777-777777777777"
    }
}

示例3 设置全局资源范围与 10% 采样

假定网关当前仅有示例 MCP 这一项受支持资源且未被其他策略占用。global 不填写资源列表;采样率 0.1 为 10%,未抽中内容不送审。 这是说明性示例,未执行真实资源操作;响应字段以目标环境实际部署版本为准。

输入示例

POST / HTTP/1.1
Host: tse.tencentcloudapi.com
Content-Type: application/json
X-TC-Action: ModifyAIGWCustomGuardrailPolicy
X-TC-Version: 2020-12-07
X-TC-Region: ap-guangzhou
<其他公共请求参数与 TC3 签名>

{
    "GatewayId": "gateway-12345678",
    "PolicyId": "11111111-1111-4111-8111-111111111111",
    "Scope": {
        "BindType": "global",
        "Resources": []
    },
    "FilterConfig": {
        "SamplingEnabled": true,
        "RequestSamplingRate": 0.1,
        "ResponseSamplingRate": 0.1
    }
}

输出示例

{
    "Response": {
        "Result": {
            "Success": true,
            "Policy": {
                "PolicyId": "11111111-1111-4111-8111-111111111111",
                "Name": "mcp-custom-audit",
                "Description": "MCP Streamable HTTP 输入审核",
                "Enabled": true,
                "EffectiveEnabled": true,
                "ServiceConfig": {
                    "AddressMode": "manual",
                    "Endpoint": "https://audit.example.com/v2/audit",
                    "SSLVerify": true,
                    "QueryPassthroughEnabled": false,
                    "HeaderAllowList": []
                },
                "AuthConfig": {
                    "AuthType": "none",
                    "HasApiKey": false
                },
                "DecisionConfig": {
                    "ContractMode": "field_mapping",
                    "BlockMessageMode": "response",
                    "BlockMessage": "您的请求可能包含不安全内容,已被安全策略拦截。请修改后重试。",
                    "RewriteEnabled": false,
                    "FieldMapping": {
                        "HitFieldPath": "decision",
                        "HitValue": "\"block\"",
                        "MessageFieldPath": "message"
                    }
                },
                "BehaviorConfig": {
                    "Direction": "input",
                    "HandleAction": "block",
                    "TimeoutMs": 5000,
                    "FailureMode": "closed"
                },
                "FilterConfig": {
                    "RequestStreamMode": "all",
                    "ResponseStreamMode": "all",
                    "RequestKeywords": [],
                    "ResponseKeywords": [],
                    "KeywordMatchMode": "any",
                    "KeywordCaseSensitive": false,
                    "SamplingEnabled": true,
                    "RequestSamplingRate": 0.1,
                    "ResponseSamplingRate": 0.1
                },
                "Scope": {
                    "BindType": "global",
                    "Resources": []
                },
                "Bindings": [
                    {
                        "ResourceType": "mcp_server",
                        "ResourceId": "22222222-2222-4222-8222-222222222222",
                        "ResourceName": "示例 MCP 服务",
                        "Path": "/mcp/example",
                        "Protocol": "mcp",
                        "RouteId": "44444444-4444-4444-8444-444444444444",
                        "PluginId": "88888888-8888-4888-8888-888888888888",
                        "SyncStatus": "synced"
                    }
                ],
                "SyncStatus": "synced",
                "CreateTime": "2026-09-08 10:00:00",
                "ModificationTime": "2026-09-08 10:00:00"
            },
            "AddedResources": [
                {
                    "ResourceType": "mcp_server",
                    "ResourceId": "22222222-2222-4222-8222-222222222222"
                }
            ],
            "RemovedCount": 0,
            "FailedResources": [],
            "SyncStatus": "synced"
        },
        "RequestId": "77777777-7777-4777-8777-777777777777"
    }
}

5. 开发者资源

腾讯云 API 平台

腾讯云 API 平台 是综合 API 文档、错误码、API Explorer 及 SDK 等资源的统一查询平台,方便您从同一入口查询及使用腾讯云提供的所有 API 服务。

API Inspector

用户可通过 API Inspector 查看控制台每一步操作关联的 API 调用情况,并自动生成各语言版本的 API 代码,也可前往 API Explorer 进行在线调试。

SDK

云 API 3.0 提供了配套的开发工具集(SDK),支持多种编程语言,能更方便的调用 API。

命令行工具

6. 错误码

以下仅列出了接口业务逻辑相关的错误码,其他错误码详见 公共错误码。

错误码 描述
FailedOperation 操作失败。
FailedOperation.FailedOperation 操作失败。
FailedOperation.InternalError 操作失败,内部错误。
InternalError.InternalError 服务内部错误。
InvalidParameterValue.BadRequestFormat 请求格式不正确。
InvalidParameterValue.InvalidParameterValue 无效的参数值。
LimitExceeded.LimitExceeded 参数超过限制。
MissingParameter.MissParameter 缺少参数。
OperationDenied.OperationDenied 不允许的操作。
ResourceInUse.CustomGuardrailGlobal ResourceInUse.CustomGuardrailGlobal
ResourceInUse.CustomGuardrailRoute ResourceInUse.CustomGuardrailRoute
ResourceNotFound 资源不存在。
ResourceNotFound.InstanceNotFound 实例不存在。
ResourceNotFound.ResourceNotFound 资源不存在。
UnauthorizedOperation 未授权操作。
UnauthorizedOperation.UnauthorizedOperation 未授权的操作。