📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you keep the cost of an LLM feature under control in production? Cover model choice, prompt and history trimming, caching, output caps and budgets per user or tenant.

Beginner Theory Beginner ai azure-openai caching llm-cost microsoft-extensions-ai rate-limiting

🎯 Key points

  • Log InputTokenCount / OutputTokenCount from ChatResponse.Usage per feature and tenant
  • Azure Cost Management budgets and alerts on the Azure OpenAI resource
  • Smaller model for routing, classification and extraction
  • Trim history, shorten system prompt, retrieve instead of stuffing
  • Cap ChatOptions.MaxOutputTokens per use case
  • UseDistributedCache() over IDistributedCache for identical prompts; provider prompt caching for shared prefixes
  • Per-user or per-tenant token budgets with rate limiting
  • Re-run evaluation after every cost optimisation

⏱ 30-second answer

Measure first: log input and output tokens per request from ChatResponse.Usage and chart cost per feature and per tenant; set Azure Cost Management budgets and alerts on the Azure OpenAI / Foundry resource so spend never surprises you. Then reduce:

  • Use a smaller model for simple steps (routing, classification, extraction), trim history and system prompts, and use retrieval instead of stuffing whole documents.
  • Cap ChatOptions.MaxOutputTokens, and cache repeated answers with Microsoft.Extensions.AI's UseDistributedCache() on the ChatClientBuilder (it wraps an ASP.NET Core IDistributedCache such as Redis; exact-match only, so it helps for identical prompts).
  • Enforce budgets per user or tenant with rate limiting.

Re-run your evaluation set after each change, because a cost cut that silently lowers quality is a false saving.

🔍 What the interviewer is checking

Checks whether they can turn token knowledge into concrete cost controls and measure them.

Green flags

  • Measures tokens per request before optimising
  • Names model tiering, output caps and caching with their limits
  • Mentions per-tenant budgets and Azure spend alerts

Red flags

  • "Just use a cheaper model" with no check on quality
  • No idea where token counts come from

↩ Usually asked after

More in .NET and AI

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me