AI Gateway Labs is a collection of hands-on examples for using an AI gateway built with Azure API Management and Microsoft Foundry to manage AI models, tools, and agents. Developers use the labs to explore policies for security, request routing, monitoring, caching, and cost control, with notebooks and deployable infrastructure templates. The catalogue entries provide skills and instructions for working through these gateway examples.
Borrowing it
Nothing to install: this file belongs to Azure-Samples/AI-Gateway. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.
curl -O https://raw.githubusercontent.com/Azure-Samples/AI-Gateway/main/.github/skills/apim-policies/SKILL.mdgit clone --depth 1 https://github.com/Azure-Samples/AI-GatewayWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/azure-samples/ai-gateway/apim-policies)<a href="https://agentmods.dev/skills/azure-samples/ai-gateway/apim-policies"><img src="https://agentmods.dev/badge/skills/azure-samples/ai-gateway/apim-policies/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/azure-samples/ai-gateway/apim-policies"><img src="https://agentmods.dev/badge/skills/azure-samples/ai-gateway/apim-policies.svg" alt="Reviewed on agentmods" width="80" height="20"></a>- NVIDIA SkillSpector warn
SkillSpector: 2 findings, up to high
These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →
- high Prompt Injection · line 18 Hidden instructions were detected in comments or invisible text. These could contain malicious directives. Manual review is recommended.Fix: Audit all comments and invisible characters. Remove any instructions that direct the agent to perform unauthorized actions. Use plain, reviewable content.
- high Prompt Injection · line 93 Hidden instructions were detected in comments or invisible text. These could contain malicious directives. Manual review is recommended.Fix: Audit all comments and invisible characters. Remove any instructions that direct the agent to perform unauthorized actions. Use plain, reviewable content.
What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00074 | $0.01731 |
| Opus 5.5 | $0.00030 | $0.00692 |
| Sonnet 5.5 | $0.00015 | $0.00346 |
| Haiku 4.5 | $0.00007 | $0.00173 |
Grade A, and why
apim-policies scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 249 lines — stays where its author put it; the contents beside it link to each section on GitHub.
APIM Policies
This skill provides guidance for creating Azure API Management XML policies.
Policy Document Structure
Every APIM policy document follows this structure:
<policies>
<inbound>
<base />
<!-- Policies applied to incoming requests -->
</inbound>
<backend>
<base />
<!-- Policies applied before forwarding to backend -->
</backend>
<outbound>
<base />
<!-- Policies applied to outgoing responses -->
</outbound>
<on-error>
<base />
<!-- Policies applied when errors occur -->
</on-error>
</policies>
The <base /> element inherits policies from parent scopes (Global → Product → API → Operation).
Policy Categories Quick Reference
| Category | Common Policies | Section |
|---|---|---|
| Authentication | authentication-managed-identity, validate-azure-ad-token, validate-jwt |
inbound |
| Rate Limiting | rate-limit-by-key, llm-token-limit, azure-openai-token-limit |
inbound |
| Caching | azure-openai-semantic-cache-lookup/store, cache-lookup/store |
inbound/outbound |
| Routing | set-backend-service, forward-request, retry |
inbound/backend |
| Transformation | set-header, set-body, set-variable, rewrite-uri |
any |
| AI Gateway | llm-content-safety, llm-emit-token-metric, azure-openai-emit-token-metric |
inbound |
| Control Flow | choose, return-response, retry, wait |
any |
Essential Policies
Set Backend Service
Route requests to a specific backend:
<set-backend-service backend-id="my-backend" />
Authentication with Managed Identity
Authenticate to Azure services using APIM's managed identity:
<authentication-managed-identity resource="https://cognitiveservices.azure.com"
output-token-variable-name="managed-id-access-token" ignore-error="false" />
<set-header name="Authorization" exists-action="override">
<value>@("Bearer " + (string)context.Variables["managed-id-access-token"])</value>
</set-header>
What ships with it
3 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 2mo ago First seen · 249 lines · 74 tokens per session scan A cedf8f3ac055
apim-policies is a skill published in the GitHub repository Azure-Samples/AI-Gateway (1,008 stars, last pushed yesterday), licensed MIT. It adds 74 tokens to every session and 1,731 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
apim-policies compared with skills from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| apim-policiesAzure-Samples/AI-Gateway | Skill | 1.0k | yesterday | MIT | A | 74 | Claude Code, Codex |
| azure-maps-search-dotnetmicrosoft/skills | Skill | 3.2k | yesterday | MIT | A | 91 | Claude Code |
| azure-eventgrid-dotnetmicrosoft/skills | Skill | 3.2k | yesterday | MIT | A | 80 | Claude Code |
| azure-mgmt-apicenter-dotnetmicrosoft/skills | Skill | 3.2k | yesterday | MIT | A | 97 | Claude Code |
| microsoft-azure-webjobs-extensions-authentication-events-dotnetmicrosoft/skills | Skill | 3.2k | yesterday | MIT | A | 97 | Claude Code |
| azure-appconfiguration-javamicrosoft/skills | Skill | 3.2k | yesterday | MIT | A | 55 | Claude Code |
| azure-speech-to-text-rest-pymicrosoft/skills | Skill | 3.2k | yesterday | MIT | A | 104 | Claude Code |