This episode shifts focus from logging to architecture. Instead of the console app calling Azure OpenAI directly, it now calls through Azure API Management, which sits in front of the model and takes over key management, rate limiting, and its own diagnostic logging. The client switches to a generic OpenAI client with a custom HTTP client injecting an APIM subscription key, while APIM itself handles rewriting the URL path and injecting the real model key on the backend. The benefit is that client applications never need to know the model’s key or exact endpoint, multiple teams can share one model safely with separate subscription keys, and token usage becomes queryable per subscription and per API in Application Insights, which sets up nicely for managing AI costs across an organization rather than a single app.

The code for this sample is here: https://github.com/michaelstephensonuk/azure-ai-samples/tree/main/04.helloworld.via.api.management

 

Buy Me A Coffee