.github/skills/apim-kql/SKILL.md
Guide for creating Kusto Query Language (KQL) queries for Azure API Management tables in Azure Monitor (Log Analytics Workspace). Use when users want to query, analyze, or monitor APIM logs including gateway logs, LLM/AI logs, MCP logs, WebSocket logs, and Application Insights data. This skill provides KQL syntax, table schemas, and query patterns for APIM monitoring scenarios.
npx skillsauth add azure-samples/ai-gateway apim-kqlInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guide for creating Kusto Query Language (KQL) queries for Azure API Management monitoring data in Azure Monitor.
ApiManagementGatewayLogs
| where TimeGenerated > ago(1h)
| project TimeGenerated, Method, Url, ResponseCode, TotalTime, BackendTime, CallerIpAddress
| order by TimeGenerated desc
| take 100
ApiManagementGatewayLlmLog
| where TimeGenerated > ago(24h)
| summarize
TotalPromptTokens = sum(PromptTokens),
TotalCompletionTokens = sum(CompletionTokens),
TotalTokens = sum(TotalTokens)
by DeploymentName, ModelName
| Table | Description | Use Case |
|-------|-------------|----------|
| ApiManagementGatewayLogs | Gateway request/response logs | API traffic analysis, errors, latency |
| ApiManagementGatewayLlmLog | LLM/AI model usage logs | Token usage, model performance |
| ApiManagementGatewayMCPLog | MCP server logs | MCP tool calls, sessions |
| ApiManagementWebSocketConnectionLogs | WebSocket connection events | Real-time API monitoring |
| AppRequests | Application Insights requests | End-to-end request tracking |
| AppMetrics | Application Insights metrics | Custom metrics analysis |
| AppTraces | Application Insights traces | Debug and diagnostic traces |
For complete table schemas, see references/table-schemas.md.
let llmLogs = ApiManagementGatewayLlmLog
| where DeploymentName != '';
let logsWithSubscription = llmLogs
| join kind=leftouter ApiManagementGatewayLogs on CorrelationId
| project
SubscriptionId = ApimSubscriptionId,
DeploymentName,
ModelName,
PromptTokens,
CompletionTokens,
TotalTokens;
logsWithSubscription
| summarize
SumPromptTokens = sum(PromptTokens),
SumCompletionTokens = sum(CompletionTokens),
SumTotalTokens = sum(TotalTokens)
by SubscriptionId, DeploymentName
ApiManagementGatewayLogs
| where TimeGenerated > ago(24h)
| where ResponseCode >= 400
| summarize ErrorCount = count() by ResponseCode, ApiId, LastErrorReason
| order by ErrorCount desc
ApiManagementGatewayLogs
| where TimeGenerated > ago(1h)
| summarize
AvgTotalTime = avg(TotalTime),
AvgBackendTime = avg(BackendTime),
P95TotalTime = percentile(TotalTime, 95),
RequestCount = count()
by bin(TimeGenerated, 5m), ApiId
| order by TimeGenerated desc
ApiManagementGatewayLogs
| where TimeGenerated > ago(1h)
| where BackendId != ""
| summarize
AvgBackendTime = avg(BackendTime),
MaxBackendTime = max(BackendTime),
ErrorCount = countif(BackendResponseCode >= 400),
TotalRequests = count()
by BackendId
| order by AvgBackendTime desc
ApiManagementGatewayLlmLog
| where TimeGenerated > ago(7d)
| summarize
TotalTokens = sum(TotalTokens),
PromptTokens = sum(PromptTokens),
CompletionTokens = sum(CompletionTokens)
by bin(TimeGenerated, 1h), DeploymentName
| order by TimeGenerated desc
ApiManagementGatewayMCPLog
| where TimeGenerated > ago(24h)
| summarize
CallCount = count(),
UniqueClients = dcount(ClientName)
by ToolName, ServerName, Method
| order by CallCount desc
ApiManagementWebSocketConnectionLogs
| where TimeGenerated > ago(1h)
| summarize
EventCount = count()
by EventName, Source, Destination
| order by EventCount desc
| where TimeGenerated > ago(1h)
| where ResponseCode == 200
| where ApiId contains "openai"
| where isnotempty(BackendId)
| summarize count() by ApiId
| summarize avg(TotalTime), percentile(TotalTime, 95) by ApiId
| summarize sum(TotalTokens) by DeploymentName
| summarize dcount(CallerIpAddress) by bin(TimeGenerated, 1h)
| where TimeGenerated > ago(1h)
| where TimeGenerated between (datetime(2024-01-01) .. datetime(2024-01-31))
| where TimeGenerated >= startofmonth(now()) and TimeGenerated <= endofmonth(now())
| summarize ... by bin(TimeGenerated, 5m)
| join kind=leftouter OtherTable on CorrelationId
| join kind=inner OtherTable on $left.Field1 == $right.Field2
| project TimeGenerated, Method, Url, ResponseCode
| project-away _BilledSize, _IsBillable
| extend Duration = TotalTime - BackendTime
| extend IsError = ResponseCode >= 400
| order by TimeGenerated desc
| take 100
| top 10 by TotalTime desc
ApiManagementGatewayLogs
| where TimeGenerated > ago(7d)
| summarize
TotalRequests = count(),
SuccessfulRequests = countif(ResponseCode < 400),
FailedRequests = countif(ResponseCode >= 400),
AvgLatency = avg(TotalTime)
by bin(TimeGenerated, 1d), ApiId
| extend SuccessRate = round(100.0 * SuccessfulRequests / TotalRequests, 2)
| order by TimeGenerated desc
let llmLogs = ApiManagementGatewayLlmLog
| where TimeGenerated > ago(30d);
llmLogs
| join kind=leftouter ApiManagementGatewayLogs on CorrelationId
| summarize
TotalTokens = sum(TotalTokens),
RequestCount = count()
by ApimSubscriptionId
| top 10 by TotalTokens desc
ApiManagementGatewayLogs
| where TimeGenerated > ago(24h)
| summarize
Total = count(),
Errors = countif(ResponseCode >= 400)
by bin(TimeGenerated, 1h)
| extend ErrorRate = round(100.0 * Errors / Total, 2)
| project TimeGenerated, Total, Errors, ErrorRate
| order by TimeGenerated desc
ApiManagementGatewayLogs
| where TimeGenerated > ago(24h)
| where Cache != ""
| summarize
HitCount = countif(Cache == "hit"),
MissCount = countif(Cache == "miss")
by ApiId
| extend HitRate = round(100.0 * HitCount / (HitCount + MissCount), 2)
ApiManagementGatewayLlmLog
| where TimeGenerated > ago(24h)
| summarize
StreamingRequests = countif(IsStreamCompletion == true),
NonStreamingRequests = countif(IsStreamCompletion == false),
AvgTokens = avg(TotalTokens)
by DeploymentName
az monitor log-analytics query \
-w <workspace-id> \
--analytics-query "ApiManagementGatewayLogs | take 10"
query = """
ApiManagementGatewayLogs
| where TimeGenerated > ago(1h)
| take 100
"""
result = utils.run(f'az monitor log-analytics query -w {workspace_id} --analytics-query "{query}"')
where TimeGenerated > ago(...) to limit data scannedtools
Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.
tools
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
development
Guide for creating new AI Gateway labs. Use when users want to create a new lab in the labs/ folder. This skill provides the standard lab structure, templates, and patterns used across the AI Gateway repository including Jupyter notebooks, Bicep infrastructure templates, APIM policies, and README documentation.
development
Guide for creating Terraform files for Azure API Management (APIM) and related Azure services. Use when users want to create, modify, or understand Terraform configurations for APIM instances, APIs, backends, subscriptions, policies, products, loggers, diagnostics, and supporting infrastructure using the azurerm provider. This skill provides HCL syntax, resource definitions, and patterns from the Terraform Registry and this repository.