Architecture
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 After import, the effective endpoint clients call is:
/v1/chat/completions, /v1/completions, /v1/embeddings, etc.https://cognisafe-apim.azure-api.net/llm/v1/chat/completions3
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: APIs →
Cognisafe LLM Gateway → Settings → Web 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.Step 3: Per-IP rate limiting (secondary policy)
Apply this at the operation level onPOST /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), setssl_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
Step 7: End-to-end test
1
Obtain an Azure AD token
2
Call the APIM endpoint
3
Verify Cognisafe received the request

