Azure AI 网关配置
azure-aigateway
将 Azure API Management(Azure API 管理)配置为 AI 网关,用于 AI 模型、MCP 工具和智能体。适用场景:语义缓存、令牌(token)限制、内容安全、负载均衡、AI 模型治理、MCP 速率限制、越狱检测、添加 Azure OpenAI 后端、添加 AI Foundry 模型、测试 AI 网关、LLM 策略、配置 AI 后端、令牌指标、AI 成本控制、将 API 转换为 MCP、将 OpenAPI 导入网关。
- License 许可
- MIT
- 所属仓库
- microsoft/skills
- 最近更新
- 2026-11-14
- Stars
- ★ 3.2k
- Forks
- 368
01 前言 Front Matter
- name
- azure-aigateway
- license
- MIT
- metadata
- { "author": "Microsoft", "version": "3.2.1" }
- description
- Configure Azure API Management as an AI Gateway for AI models, MCP tools, and agents. WHEN: semantic caching, token limit, content safety, load balancing, AI model governance, MCP rate limiting, jailbreak detection, add Azure OpenAI backend, add AI Foundry model, test AI gateway, LLM policies, configure AI backend, token metrics, AI cost control, convert API to MCP, import OpenAPI to gateway.
- compatibility
- Requires Azure CLI (az) for configuration and testing
02 资源文件 100
- 参考文档copilot-studio/agent.sync.yaml174 B
- 参考文档copilot-studio/behaviors/aibast_guided-fix.mcs.yml1.2 KB
- 参考文档copilot-studio/behaviors/aibast_local-work-check.mcs.yml1.2 KB
- 参考文档copilot-studio/behaviors/aibast_technician-booking.mcs.yml1.2 KB
- 参考文档copilot-studio/behaviors/aibast_visit-history.mcs.yml1.1 KB
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_first-time-fix-rules-and-guardrails.md2.7 KB
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_first-time-fix-rules-and-guardrails.md.mcs.yml194 B
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_first-time-fix-synthetic-records.md10.7 KB
- 参考文档copilot-studio/capabilities/knowledge/files/aibast_first-time-fix-synthetic-records.md.mcs.yml188 B
- 参考文档copilot-studio/settings.mcs.yml3.9 KB
- 参考文档deployment.json3.9 KB
- 参考文档EASY-MODE-COPILOT-CHAT.md219 B
- 参考文档EASY-MODE-PERSONLESS.md219 B
- 参考文档EASY-MODE.md2.6 KB
- 参考文档evals/copilot-studio-preview-evidence.json1.6 KB
- 参考文档evals/dataverse-draft-evidence.json1.6 KB
- 参考文档evals/manual-build-evidence.json3.0 KB
- 参考文档evals/onepager-map.json1.7 KB
- 参考文档evals/source-audit.json1.5 KB
- 参考文档evals/transcripts.json7.5 KB
- 参考文档evals/visual-checkpoints.json21.8 KB
- 参考文档evidence-report.html28.1 KB
- 参考文档export-manifest.json44.9 KB
- 资产文件exports/first-time-fix-copilot-studio-solution.zip40.3 KB
- 参考文档exports/first-time-fix-deployment-settings.json208 B
- 参考文档exports/first-time-fix-solution-export.json1.0 KB
- 参考文档exports/README.md1.5 KB
- 参考文档field-guide.html37.8 KB
- 参考文档FIELD-GUIDE.md13.9 KB
- 参考文档manual-tutorial.html79.0 KB
- 参考文档manual/GLOBAL-INSTRUCTIONS.md3.0 KB
- 参考文档manual/knowledge/aibast_first-time-fix-rules-and-guardrails.md2.7 KB
- 参考文档manual/knowledge/aibast_first-time-fix-synthetic-records.md10.7 KB
- 参考文档quest.html128.3 KB
- 参考文档README.md3.6 KB
- 参考文档references/auth-best-practices.md6.1 KB
- 参考文档references/patterns.md6.6 KB
- 参考文档references/policies.md9.2 KB
- 参考文档references/sdk/azure-ai-contentsafety-py.md1.3 KB
- 参考文档references/sdk/azure-ai-contentsafety-ts.md1.4 KB
- 参考文档references/sdk/azure-mgmt-apimanagement-dotnet.md1.3 KB
- 参考文档references/sdk/azure-mgmt-apimanagement-py.md1.0 KB
- 参考文档references/troubleshooting.md7.7 KB
- 资产文件screenshots/assisted/01-review-build.jpg166.2 KB
- 资产文件screenshots/assisted/02-ftf-01.jpg154.7 KB
- 资产文件screenshots/assisted/03-ftf-02.jpg179.4 KB
- 资产文件screenshots/assisted/04-ftf-03.jpg144.3 KB
- 资产文件screenshots/assisted/05-ftf-04.jpg192.1 KB
- 资产文件screenshots/assisted/06-confirm-draft.jpg50.2 KB
- 资产文件screenshots/assisted/annotated/01-review-build.png112.7 KB
- 资产文件screenshots/assisted/annotated/02-ftf-01.png97.2 KB
- 资产文件screenshots/assisted/annotated/03-ftf-02.png110.2 KB
- 资产文件screenshots/assisted/annotated/04-ftf-03.png90.8 KB
- 资产文件screenshots/assisted/annotated/05-ftf-04.png118.6 KB
- 资产文件screenshots/assisted/annotated/06-confirm-draft.png29.0 KB
- 参考文档screenshots/assisted/browserfilm.json1.3 KB
- 资产文件screenshots/assisted/copilot-assisted-contact-sheet.jpg149.9 KB
- 资产文件screenshots/assisted/copilot-assisted-walkthrough.gif839.4 KB
- 参考文档screenshots/assisted/README.md467 B
- 资产文件screenshots/manual/01-create-blank-agent.jpg89.3 KB
- 资产文件screenshots/manual/02-name-agent.jpg88.1 KB
- 资产文件screenshots/manual/03-enter-instructions.jpg182.7 KB
- 资产文件screenshots/manual/04-save-instructions.jpg173.8 KB
- 资产文件screenshots/manual/05-remove-web-search.jpg181.7 KB
- 资产文件screenshots/manual/06-add-aibast-first-time-fix-rules-and-guardrails.jpg186.1 KB
- 资产文件screenshots/manual/07-add-aibast-first-time-fix-synthetic-records.jpg189.8 KB
- 资产文件screenshots/manual/08-add-aibast-guided-fix-01.jpg190.6 KB
- 资产文件screenshots/manual/09-add-aibast-local-work-check-02.jpg192.6 KB
- 资产文件screenshots/manual/10-add-aibast-technician-booking-04.jpg194.9 KB
- 资产文件screenshots/manual/11-add-aibast-visit-history-03.jpg196.4 KB
- 资产文件screenshots/manual/12-review-inventory.jpg196.4 KB
- 资产文件screenshots/manual/13-open-preview.jpg59.3 KB
- 资产文件screenshots/manual/14-ftf-01.jpg152.6 KB
- 资产文件screenshots/manual/15-ftf-02.jpg163.2 KB
- 资产文件screenshots/manual/16-ftf-03.jpg145.0 KB
- 资产文件screenshots/manual/17-ftf-04.jpg164.8 KB
- 资产文件screenshots/manual/18-confirm-draft.jpg50.7 KB
- 资产文件screenshots/manual/annotated/01-create-blank-agent.png60.3 KB
- 资产文件screenshots/manual/annotated/02-name-agent.png59.5 KB
- 资产文件screenshots/manual/annotated/03-enter-instructions.png116.0 KB
- 资产文件screenshots/manual/annotated/04-save-instructions.png110.1 KB
- 资产文件screenshots/manual/annotated/05-remove-web-search.png115.1 KB
- 资产文件screenshots/manual/annotated/06-add-aibast-first-time-fix-rules-and-guardrails.png119.1 KB
- 资产文件screenshots/manual/annotated/07-add-aibast-first-time-fix-synthetic-records.png120.8 KB
- 资产文件screenshots/manual/annotated/08-add-aibast-guided-fix-01.png119.8 KB
- 资产文件screenshots/manual/annotated/09-add-aibast-local-work-check-02.png121.4 KB
- 资产文件screenshots/manual/annotated/10-add-aibast-technician-booking-04.png122.9 KB
- 资产文件screenshots/manual/annotated/11-add-aibast-visit-history-03.png123.6 KB
- 资产文件screenshots/manual/annotated/12-review-inventory.png131.4 KB
- 资产文件screenshots/manual/annotated/13-open-preview.png35.7 KB
- 资产文件screenshots/manual/annotated/14-ftf-01.png102.0 KB
- 资产文件screenshots/manual/annotated/15-ftf-02.png105.1 KB
- 资产文件screenshots/manual/annotated/16-ftf-03.png91.8 KB
- 资产文件screenshots/manual/annotated/17-ftf-04.png108.3 KB
- 资产文件screenshots/manual/annotated/18-confirm-draft.png29.2 KB
- 参考文档screenshots/manual/browserfilm.json3.2 KB
- 资产文件screenshots/manual/manual-build-contact-sheet.jpg593.2 KB
- 资产文件screenshots/manual/manual-build-walkthrough.gif3.6 MB
- 参考文档screenshots/manual/README.md461 B
- 参考文档screenshots/README.md521 B
03 SKILL.md 正文
Azure AI Gateway
Configure Azure API Management (APIM) as an AI Gateway for governing AI models, MCP tools, and agents.
To deploy APIM, use the azure-prepare skill. See APIM deployment guide.
When to Use This Skill
| Category | Triggers |
|---|---|
| Model Governance | "semantic caching", "token limits", "load balance AI", "track token usage" |
| Tool Governance | "rate limit MCP", "protect my tools", "configure my tool", "convert API to MCP" |
| Agent Governance | "content safety", "jailbreak detection", "filter harmful content" |
| Configuration | "add Azure OpenAI backend", "configure my model", "add AI Foundry model" |
| Testing | "test AI gateway", "call OpenAI through gateway" |
Quick Reference
| Policy | Purpose | Details |
|---|---|---|
azure-openai-token-limit |
Cost control | Model Policies |
azure-openai-semantic-cache-lookup/store |
60-80% cost savings | Model Policies |
azure-openai-emit-token-metric |
Observability | Model Policies |
llm-content-safety |
Safety & compliance | Agent Policies |
rate-limit-by-key |
MCP/tool protection | Tool Policies |
Get Gateway Details
# Get gateway URL
az apim show --name <apim-name> --resource-group <rg> --query "gatewayUrl" -o tsv
# List backends (AI models)
az apim backend list --service-name <apim-name> --resource-group <rg> \
--query "[].{id:name, url:url}" -o table
# Get subscription key
az apim subscription keys list \
--service-name <apim-name> --resource-group <rg> --subscription-id <sub-id>
Test AI Endpoint
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}'
Common Tasks
Add AI Backend
See references/patterns.md for full steps.
# Discover AI resources
az cognitiveservices account list --query "[?kind=='OpenAI']" -o table
# Create backend
az apim backend create --service-name <apim> --resource-group <rg> \
--backend-id openai-backend --protocol http --url "https://<aoai>.openai.azure.com/openai"
# Grant access (managed identity)
az role assignment create --assignee <apim-principal-id> \
--role "Cognitive Services User" --scope <aoai-resource-id>
Apply AI Governance Policy
Recommended policy order in <inbound>:
- Authentication - Managed identity to backend
- Semantic Cache Lookup - Check cache before calling AI
- Token Limits - Cost control
- Content Safety - Filter harmful content
- Backend Selection - Load balancing
- Metrics - Token usage tracking
See references/policies.md for complete example.
Troubleshooting
| Issue | Solution |
|---|---|
| Token limit 429 | Increase tokens-per-minute or add load balancing |
| No cache hits | Lower score-threshold to 0.7 |
| Content false positives | Increase category thresholds (5-6) |
| Backend auth 401 | Grant APIM "Cognitive Services User" role |
See references/troubleshooting.md for details.
References
- Detailed Policies - Full policy examples
- Configuration Patterns - Step-by-step patterns
- Troubleshooting - Common issues
- AI-Gateway Samples
- GenAI Gateway Docs
SDK Quick References
- Content Safety: Python | TypeScript
- API Management: Python | .NET
04 同仓库更多 Skills
azure-advisor-cost-optimization
Analyze Azure Advisor Cost/IdleResources findings and prevalidate deletion safety, including Service Groups. WHEN: "find unused Azure resources", "what resources am I paying for but no longer using", "idle-resource savings", "historical idle-resource savings", "are these idle resources safe to delete". Generic Cost, other subcategories, and cross-category requests use azure-advisor.
Azure 技能创建与更新指南
skill-creator
面向使用 Azure SDK 和 Microsoft Foundry 服务的 AI 编码智能体,指导其创建高效技能的指南。在创建新技能或更新现有技能时使用。
AI 播客音频生成
podcast-generation
通过 WebSocket 使用 Azure OpenAI 的 GPT Realtime Mini 模型生成 AI 驱动的播客式音频叙述。当构建文本转语音功能、音频叙述生成、根据内容制作播客,或集成 Azure OpenAI Realtime API 以获得真实音频输出时使用。涵盖从 React 前端到 Python FastAPI 后端及 WebSocket 流式传输的全栈实现。
Microsoft 技术文档查询
microsoft-docs
通过查询官方文档来理解 Microsoft 技术。当用户询问某项技术的工作原理、想要教程、需要任何 Microsoft 技术(Azure、.NET、M365、Windows、Power Platform 等)的配置选项、限制、配额或最佳实践时使用——即使他们没有提到"文档"。如果问题是为了理解概念而非编写代码,那么这就是合适的技能。
MCP 服务器构建
mcp-builder
用于创建高质量 MCP(Model Context Protocol)服务器的指南,使大语言模型能够通过设计完善的工具与外部服务交互。当构建用于集成外部 API 或服务的 MCP 服务器时使用,无论采用 Python(FastMCP)、Node/TypeScript(MCP SDK),还是 C#/.NET(Microsoft MCP SDK)。
KQL 查询编写与调试
kql
KQL 语言专业能力,用于编写正确且高效的 Kusto Query Language 查询。涵盖语法陷阱、join 模式、dynamic 类型、datetime 陷阱、regex 模式、序列化、内存管理、结果集规模控制,以及高级函数(geo、vector、graph)。在编写、调试或审查 KQL 查询时均使用本技能——即使是简单查询——因为陷阱章节可防止最常见的错误,避免浪费工具调用并引发代价高昂的连锁重试。触发条件:KQL、Kusto、ADX、Azure Data Explorer、Fabric Real-Time Intelligence、EventHouse、Log Analytics、日志分析、数据探索、时间序列、异常检测、summarize、where 子句、join、extend、project、let 语句、parse 运算符、extract 函数,以及任何提及管道式查询语法的情形。