Skip to main content
Azure API Management (APIM) and Cognisafe solve different layers of the AI gateway problem. APIM owns cross-cutting enterprise concerns: subscription management, OAuth2/Azure AD validation, rate limiting by business tier, and unified API exposure across teams. Cognisafe owns AI-specific runtime security: per-request OWASP LLM scoring, jailbreak detection, PII scanning, cost attribution, and the full audit trail of every LLM exchange. Neither replaces the other. Together they form a complete enterprise AI gateway.

Architecture

APIM never touches the LLM response payload — it passes through unchanged. Cognisafe intercepts and scores asynchronously, so neither APIM nor the client sees added latency from scoring.

Step 1: Create the APIM instance

1

Provision APIM

For internal enterprise use, Standard tier supports VNet integration. Developer tier is suitable for non-production.
If your AKS cluster uses an internal load balancer (no public IP on the proxy Service), set virtualNetworkType=Internal and deploy APIM into the same VNet as AKS. The Cognisafe proxy backend URL will then be the internal ClusterIP or internal load balancer DNS name.
2

Import the OpenAI API spec

APIM can import the OpenAI API OpenAPI spec directly. This creates operations for /v1/chat/completions, /v1/completions, /v1/embeddings, etc.
After import, the effective endpoint clients call is: https://cognisafe-apim.azure-api.net/llm/v1/chat/completions
3

Set the backend URL

Point the APIM API backend at the Cognisafe proxy. If the proxy runs inside AKS with a ClusterIP service, you need either an internal load balancer IP or the AKS internal DNS name.
Alternatively, set the backend via the APIM portal: APIsCognisafe LLM GatewaySettingsWeb service URL.
4

Create Named Values for secrets

Named values store secrets in APIM without embedding them in policy XML. APIM can pull values from Azure Key Vault directly.

Step 2: APIM inbound policy

This policy runs on every request before it reaches the Cognisafe proxy. It validates the Azure AD token, enforces rate limits, and rewrites headers.
The validate-jwt policy caches the OIDC discovery document and JWKS keys. If your Azure AD app registration rotates signing keys (standard behaviour), APIM will auto-refresh within the configured TTL. Do not pin to specific key IDs — let the policy fetch from the OIDC jwks_uri.

Step 3: Per-IP rate limiting (secondary policy)

Apply this at the operation level on POST /v1/chat/completions if you want IP-level throttling in addition to per-subscription limits:

Step 4: mTLS between APIM and Cognisafe proxy

For defence-in-depth, configure APIM to present a client certificate when calling the Cognisafe proxy backend. The proxy then validates that the certificate is from APIM before accepting the request.

Upload the client certificate to APIM

Reference the certificate in the backend policy

Configure the Cognisafe proxy to require client certs

In your AKS Ingress (or directly in the Go proxy), set ssl_verify_client on (NGINX) or implement tls.RequireAndVerifyClientCert in the Go TLS config. Add the APIM client certificate’s CA to the proxy’s trusted CA pool.

Step 5: OAuth2 product and subscription setup

Step 6: Send APIM access logs to Azure Monitor

Query APIM gateway logs in Log Analytics:

Step 7: End-to-end test

1

Obtain an Azure AD token

2

Call the APIM endpoint

3

Verify Cognisafe received the request

Troubleshooting