Available Policies
March 23, 2026 ยท View on GitHub
This document lists policy elements that the toolkit's authoring and compiler support by mapping C# APIs to Azure API Management policy elements. The list below was generated from the public authoring interfaces ( inbound/outbound/backend/on-error/fragment contexts) and reflects which policies the toolkit can compile into XML.
The toolkit also includes a decompiler that converts existing policy XML back to C# code, enabling round-trip workflows: XML โ C# โ XML. Policies marked with โ support full round-trip (compiler + decompiler). Policies marked with ๐ง support compilation only (no decompiler yet).
If a policy you need is missing you can either:
- Use
InlinePolicy(...)to insert raw XML into the compiled document, or - Open an issue / contribute the feature (learn more in our contribution guide).
Notes:
- The C# compiler maps C# constructs to policy constructs. For example, if/else in C# is compiled to the
choosepolicy (withwhen/otherwise). InlinePolicy(string)allows inserting arbitrary XML when a policy isn't implemented as a first-class API.- The decompiler uses
InlinePolicyas a fallback for any XML element it does not have a specific handler for.
Implemented policies
- โ authentication-basic
- โ authentication-certificate
- โ authentication-managed-identity
- โ azure-openai-emit-token-metric
- โ azure-openai-semantic-cache-lookup
- โ azure-openai-semantic-cache-store
- โ azure-openai-token-limit
- โ base
- โ cache-lookup
- โ cache-lookup-value
- โ cache-remove-value
- โ cache-store
- โ cache-store-value
- โ cache-value
- โ check-header
- โ choose (implemented via C# if/else -> choose/when/otherwise)
- โ cors
- โ cross-domain
- โ emit-metric
- โ find-and-replace
- โ forward-request
- โ get-authorization-context
- โ include-fragment
- โ inline-policy (method to insert raw XML)
- โ invoke-dapr-binding (publish/send to Dapr bindings)
- โ ip-filter
- โ json-to-xml
- โ jsonp
- โ limit-concurrency
- โ llm-content-safety
- โ llm-emit-token-metric
- โ llm-semantic-cache-lookup
- โ llm-semantic-cache-store
- โ llm-token-limit
- โ log-to-eventhub
- โ mock-response
- โ proxy
- โ publish-to-dapr
- โ quota
- โ quota-by-key
- โ rate-limit
- โ rate-limit-by-key
- โ redirect-content-urls
- โ remove-header (via SetHeader/RemoveHeader APIs)
- โ remove-query-parameter (via SetQueryParameter/Remove APIs)
- โ return-response
- โ retry
- โ rewrite-uri
- โ send-one-way-request
- โ send-request
- โ send-service-bus-message
- โ set-backend-service (including Dapr attributes: dapr-app-id, dapr-method, dapr-namespace)
- โ set-body
- โ set-header
- โ set-header-if-not-exist
- โ set-method
- โ set-query-parameter
- โ set-query-parameter-if-not-exist
- โ set-status
- โ set-variable
- โ trace
- โ validate-azure-ad-token
- โ validate-client-certificate
- โ validate-content
- โ validate-headers
- โ validate-jwt
- โ validate-odata-request
- โ validate-parameters
- โ validate-status-code
- โ wait
- โ xml-to-json
- โ xsl-transform
Policies not yet implemented
The following Azure API Management policies are not yet supported as first-class C# APIs. Use InlinePolicy(...) as
a workaround.
- validate-graphql-request
- sql-data-source (GraphQL resolver)
- cosmosdb-data-source (GraphQL resolver)
- http-data-source (GraphQL resolver)
- publish-event (GraphQL subscription)
C# authoring examples
Validation policies
// Validate headers against API schema
c.ValidateHeaders(new ValidateHeadersConfig
{
SpecifiedHeaderAction = "prevent",
UnspecifiedHeaderAction = "ignore",
ErrorsVariableName = "header-errors"
});
// Validate query/path parameters
c.ValidateParameters(new ValidateParametersConfig
{
SpecifiedParameterAction = "prevent",
UnspecifiedParameterAction = "prevent",
ErrorsVariableName = "param-errors"
});
// Validate response status codes
c.ValidateStatusCode(new ValidateStatusCodeConfig
{
UnspecifiedStatusCodeAction = "prevent",
ErrorsVariableName = "statuscode-errors"
});
// Validate OData requests
c.ValidateOdataRequest(new ValidateOdataRequestConfig
{
ErrorVariableName = "odata-errors",
DefaultOdataVersion = "4.0",
MaxSize = 10000
});
// Validate request/response content
c.ValidateContent(new ValidateContentConfig
{
UnspecifiedContentTypeAction = "prevent",
MaxSize = 102400,
SizeExceededAction = "prevent",
ErrorsVariableName = "content-errors"
});
// Validate client certificate
c.ValidateClientCertificate(new ValidateClientCertificateConfig
{
ValidateRevocation = true,
ValidateTrust = true,
ValidateNotBefore = true,
ValidateNotAfter = true
});
// Validate Azure AD token
c.ValidateAzureAdToken(new ValidateAzureAdTokenConfig
{
HeaderName = "Authorization",
FailedValidationHttpCode = 401,
FailedValidationErrorMessage = "Unauthorized",
Audiences = new[] { "https://api.example.com" },
RequiredClaims = new ClaimConfig[]
{
new() { Name = "roles", Match = "any", Values = new[] { "admin", "reader" } }
}
});
XSL transform
c.XslTransform(new XslTransformConfig
{
Xsl = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
"<xsl:output method=\"xml\" indent=\"yes\"/>" +
"<xsl:template match=\"/\"><root><xsl:value-of select=\".\"/></root></xsl:template>" +
"</xsl:stylesheet>"
});
Cross-domain access
c.CrossDomain("<cross-domain-policy><allow-access-from domain=\"*\" /></cross-domain-policy>");
HTTP proxy
c.Proxy(new ProxyConfig
{
Url = "http://proxy.example.com:8080",
Username = "admin",
Password = "secret"
});
Integration policies
// Send Azure Service Bus message
c.SendServiceBusMessage(new SendServiceBusMessageConfig
{
QueueName = "my-queue",
Namespace = "my-namespace.servicebus.windows.net"
});
// Invoke Dapr binding
c.InvokeDarpBinding(new InvokeDarpBindingConfig
{
Name = "my-binding",
Operation = "create",
IgnoreError = true
});
// Publish to Dapr topic
c.PublishToDarp(new PublishToDarpConfig
{
Topic = "my-topic",
PubSubName = "pubsub"
});
AI gateway policies
// Content safety check for LLM requests
c.LlmContentSafety(new LlmContentSafetyConfig
{
BackendId = "content-safety-backend"
});
// Azure OpenAI token limit
c.AzureOpenAiTokenLimit(new TokenLimitConfig
{
CounterKey = "my-key",
TokensPerMinute = 10000,
EstimatePromptTokens = true,
RemainingTokensHeaderName = "x-remaining-tokens"
});
// LLM token metrics
c.LlmEmitTokenMetric(new EmitTokenMetricConfig
{
Namespace = "my-namespace",
Dimensions = new MetricDimensionConfig[]
{
new() { Name = "API ID", Value = "@(context.Api.Id)" }
}
});
// Semantic cache lookup
c.AzureOpenAiSemanticCacheLookup(new SemanticCacheLookupConfig
{
EmbeddingsBackendId = "embeddings-backend",
ScoreThreshold = 0.8,
EmbeddingsModelName = "text-embedding-ada-002"
});
How to work around missing policies
InlinePolicy is a workaround until all the policies are implemented or new policies are not added yet to toolkit. It allows you to include policy not implemented yet to the document.
c.InlinePolicy("<set-backend-service base-url=\"https://internal.contoso.example\" />");
Contributing
If you'd like a specific policy implemented natively in the toolkit, please open an issue or a pull request in this repository. See CONTRIBUTING.md and Add new policy guide for guidance.