安装方式
命令行安装
在项目根目录执行以下命令,完成 Skill 安装。
npx bzskills add microsoft/azure-skills --skill azure-aigateway 将 Azure API 管理配置为 AI 模型、MCP 工具和代理的 AI 网关。适用场景:语义缓存、令牌限制、内容安全、负载均衡、AI 模型治理、MCP 速率限制、越狱检测、添加 Azure OpenAI 后端、添加 AI Foundry 模型、测试 AI 网关、LLM 策略、配置 AI 后端、令牌指标、AI 成本控制、将 API 转换为 MCP、将 OpenAPI 导入网关。
299k
下载量
命令行安装
在项目根目录执行以下命令,完成 Skill 安装。
npx bzskills add microsoft/azure-skills --skill azure-aigateway name: azure-aigateway
description: 将 Azure API 管理配置为 AI 模型、MCP 工具和代理的 AI 网关。适用场景:语义缓存、令牌限制、内容安全、负载均衡、AI 模型治理、MCP 速率限制、越狱检测、添加 Azure OpenAI 后端、添加 AI Foundry 模型、测试 AI 网关、LLM 策略、配置 AI 后端、令牌指标、AI 成本控制、将 API 转换为 MCP、将 OpenAPI 导入网关。
license: MIT
metadata:
author: Microsoft
version: "3.1.1"
compatibility: Requires Azure CLI (az) for configuration and testing将 Azure API 管理 (APIM) 配置为 AI 网关,用于管理 AI 模型、MCP 工具和代理。
要部署 APIM,请使用 azure-prepare 技能。请参阅 APIM 部署指南。
| 类别 | 触发词 |
|---|---|
| 模型治理 | "语义缓存"、"令牌限制"、"AI 负载均衡"、"跟踪令牌使用" |
| 工具治理 | "MCP 限流"、"保护我的工具"、"配置我的工具"、"将 API 转换为 MCP" |
| 代理治理 | "内容安全"、"越狱检测"、"过滤有害内容" |
| 配置 | "添加 Azure OpenAI 后端"、"配置我的模型"、"添加 AI Foundry 模型" |
| 测试 | "测试 AI 网关"、"通过网关调用 OpenAI" |
---
| 策略 | 目的 | 详情 |
|---|---|---|
azure-openai-token-limit | 成本控制 | [模型策略](references/policies.md#令牌速率限制) |
azure-openai-semantic-cache-lookup/store | 节省 60-80% 成本 | [模型策略](references/policies.md#语义缓存) |
azure-openai-emit-token-metric | 可观测性 | [模型策略](references/policies.md#令牌指标) |
llm-content-safety | 安全与合规 | [代理策略](references/policies.md#内容安全) |
rate-limit-by-key | MCP/工具保护 | [工具策略](references/policies.md#请求速率限制) |
---
# 获取网关 URL
az apim show --name <apim-name> --resource-group <rg> --query "gatewayUrl" -o tsv
# 列出后端(AI 模型)
az apim backend list --service-name <apim-name> --resource-group <rg> \
--query "[].{id:name, url:url}" -o table
# 获取订阅密钥
az apim subscription keys list \
--service-name <apim-name> --resource-group <rg> --subscription-id <sub-id>
---
GATEWAY_URL=$(az apim show --name <apim-name> --resource-group <rg> --query "gatewayUrl" -o tsv)
curl -X POST "${GATEWAY_URL}/openai/deployments/<deployment>/chat/completions?api-version=2024-02-01" \
-H "Content-Type: application/json" \
-H "Ocp-Apim-Subscription-Key: <key>" \
-d '{"messages": [{"role": "user", "content": "Hello"}], "max_tokens": 100}'
---
完整步骤请参阅 [references/patterns.md](references/patterns.md#pattern-1-add-ai-model-backend)。
# 发现 AI 资源
az cognitiveservices account list --query "[?kind=='OpenAI']" -o table
# 创建后端
az apim backend create --service-name <apim> --resource-group <rg> \
--backend-id openai-backend --protocol http --url "https://<aoai>.openai.azure.com/openai"
# 授予访问权限(托管标识)
az role assignment create --assignee <apim-principal-id> \
--role "Cognitive Services User" --scope <aoai-resource-id>
推荐在 <inbound> 中的策略顺序:
完整示例请参阅 [references/policies.md](references/policies.md#combining-policies)。
---
| 问题 | 解决方案 |
|---|---|
| 令牌限制 429 | 增加 tokens-per-minute 或添加负载均衡 |
| 无缓存命中 | 将 score-threshold 降低至 0.7 |
| 内容误报 | 提高类别阈值(5-6) |
| 后端认证 401 | 授予 APIM "Cognitive Services User" 角色 |
详情请参阅 [references/troubleshooting.md](references/troubleshooting.md)。
---