SKILL.md
唯讀
名稱
azure-aigateway
描述
將 Azure API 管理設定為 AI 模型、MCP 工具與代理程式的 AI 閘道。適用情境:語意快取、權杖限制、內容安全、負載平衡、AI 模型治理、MCP 速率限制、越獄偵測、新增 Azure OpenAI 後端、新增 AI Foundry 模型、測試 AI 閘道、LLM 原則、設定 AI 後端、權杖指標、AI 成本控制、將 API 轉換為 MCP、將 OpenAPI 匯入閘道。
Azure AI 閘道
將 Azure API 管理 (APIM) 設定為 AI 閘道,用於管理 AI 模型、MCP 工具與代理程式。
若要部署 APIM,請使用 azure-prepare 技能。請參閱 APIM 部署指南。
何時使用此技能
| 類別 | 觸發情境 |
|---|---|
| 模型治理 | "語意快取", "權杖限制", "負載平衡 AI", "追蹤權杖使用量" |
| 工具治理 | "MCP 速率限制", "保護我的工具", "設定我的工具", "將 API 轉換為 MCP" |
| 代理程式治理 | "內容安全", "越獄偵測", "過濾有害內容" |
| 設定 | "新增 Azure OpenAI 後端", "設定我的模型", "新增 AI Foundry 模型" |
| 測試 | "測試 AI 閘道", "透過閘道呼叫 OpenAI" |
快速參考
| 原則 | 用途 | 詳細資訊 |
|---|---|---|
azure-openai-token-limit |
成本控制 | 模型原則 |
azure-openai-semantic-cache-lookup/store |
節省 60-80% 成本 | 模型原則 |
azure-openai-emit-token-metric |
可觀測性 | 模型原則 |
llm-content-safety |
安全與合規 | 代理程式原則 |
rate-limit-by-key |
MCP/工具保護 | 工具原則 |
取得閘道詳細資訊
# 取得閘道 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>
測試 AI 端點
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}'
常見工作
新增 AI 後端
完整步驟請參閱 references/patterns.md。
# 探索 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>
套用 AI 治理原則
在 <inbound> 中建議的原則順序:
- 驗證 - 對後端使用受控識別
- 語意快取查詢 - 呼叫 AI 前檢查快取
- 權杖限制 - 成本控制
- 內容安全 - 過濾有害內容
- 後端選擇 - 負載平衡
- 指標 - 權杖使用量追蹤
完整範例請參閱 references/policies.md。
疑難排解
| 問題 | 解決方案 |
|---|---|
| 權杖限制 429 | 增加 tokens-per-minute 或新增負載平衡 |
| 無快取命中 | 將 score-threshold 降低至 0.7 |
| 內容誤判 | 提高類別閾值 (5-6) |
| 後端驗證 401 | 授予 APIM "Cognitive Services User" 角色 |
詳細資訊請參閱 references/troubleshooting.md。
參考資料
- 詳細原則 - 完整原則範例
- 設定模式 - 逐步模式
- 疑難排解 - 常見問題
- AI-Gateway 範例
- GenAI 閘道文件
SDK 快速參考
- 內容安全:Python | TypeScript
- API 管理:Python | .NET




