LyraLearn AI Learning Platform
Exams
← Module 7 Β· AI Integration Scenarios
🎧 Listen

Calling LLMs from .NET

Sooner or later the interviewer drops out of architecture and into code: "Walk me through how you'd actually call a model from our ASP.NET Core app." This is a chance to show that an LLM endpoint is, to a .NET developer, a slow, expensive, occasionally flaky HTTP dependency β€” and that you already know how to treat those.

The shape of a good answer

Start with the client: a typed HttpClient registered via AddHttpClient<ITranscriptAiClient, TranscriptAiClient>(), pointed at an OpenAI-compatible or Azure OpenAI endpoint. That buys you DI, HttpClientFactory handler pooling, and one place to attach resilience policies. Then hit the operational beats out loud:

The follow-ups they will ask

"What if it's slow?" β€” Separate interactive from batch. Interactive calls stream and show progress; transcript batches run in a background service (hosted service or queue) so a web request never waits minutes. Cache repeated prompts where results are deterministic enough, and measure latency percentiles, not averages.

"How do you test it?" β€” Two layers. Unit tests mock the typed client interface β€” controllers and services are tested with canned responses, including malformed JSON and timeouts. Model quality is tested separately with an evaluation set: real prompts, expected outputs, scored offline on every prompt or model change. Never let "the model is nondeterministic" become an excuse for zero tests.

Red flags

Practice prompts

  1. Sketch the TranscriptAiClient interface and its registration in Program.cs on a whiteboard.
  2. The model starts returning 429s during a submission surge β€” narrate your mitigation, in order.
  3. Explain to a reviewer why your integration tests don't call the real model β€” and what does.
🧠 Quiz yourself on this lesson →

Ask the AI Tutor

Grounded in the course lessons β€” it cites its sources and says when it doesn't know.