---
title: "Discussion on \"Building an AI Gateway in .NET\" | Hashnode"
description: "Discussion on \"Building an AI Gateway in .NET\". How to centralise model access, resilience, routing, telemetry and cost tracking without dragging business logic into a shared AI service."
url: "https://hashnode.com/posts/building-an-ai-gateway-in-net/6a527d71a7a8fb34334b9feb"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Building an AI Gateway in .NET](https://dotnetdigest.com/building-an-ai-gateway-in-net?utm_source=hashnode&utm_medium=feed)

How to centralise model access, resilience, routing, telemetry and cost tracking without dragging business logic into a shared AI service.

Jul 11 · 18 min read · dotnetdigest.com  
Read the article

-   [#ai](https://hashnode.com/tag/ai)
-   [#artificial-intelligence](https://hashnode.com/tag/artificial-intelligence)
-   [#programming-blogs](https://hashnode.com/tag/programming-blogs)
-   [#software-development](https://hashnode.com/tag/software-development)
-   [#software-engineering](https://hashnode.com/tag/software-engineering)
-   [#software-architecture](https://hashnode.com/tag/software-architecture)
-   [#microsoft](https://hashnode.com/tag/microsoft)
-   [#dotnet](https://hashnode.com/tag/dotnet)
-   [#csharp](https://hashnode.com/tag/csharp)
-   [#ai-engineering](https://hashnode.com/tag/ai-engineering)

## Written by

[Patrick Kearns](https://hashnode.com/@fullstackcity)

@fullstackcity · Dublin

  
[View profile](https://hashnode.com/@fullstackcity)

Senior .Net Engineer

Senior Software Engineer specialising in cloud architecture, distributed systems, and modern .NET development, with over two decades of experience designing and delivering enterprise platforms in financial, insurance, and high-scale commercial environments. My focus is on building systems that are reliable, scalable, and maintainable over the long term. I’ve led modernisation initiatives moving legacy platforms to cloud-native Azure architectures, designed high-throughput streaming solutions to eliminate performance bottlenecks, and implemented secure microservices environments using container-based deployment models and event-driven integration patterns. From an architecture perspective, I have strong practical experience applying approaches such as Vertical Slice Architecture, Domain-Driven Design, Clean Architecture, and Hexagonal Architecture. I’m particularly interested in modular system design that balances delivery speed with long-term sustainability, and I enjoy solving complex problems involving distributed workflows, performance optimisation, and system reliability. I enjoy mentoring engineers, contributing to architectural decisions, and helping teams simplify complex systems into clear, maintainable designs. I’m always open to connecting with other engineers, architects, and technology leaders working on modern cloud and distributed system challenges.

## Responses 6

Markdown supported · ⌘↵ to post

[Julian Neagu](https://hashnode.com/@julianneagulab)

[Jul 14](https://hashnode.com/posts/building-an-ai-gateway-in-net/6a527d71a7a8fb34334b9feb/comment/6a56245125bf29b82122213b)

liked the point about not turning the gateway into an agent framework. seen too many shared services become a place where every ai feature gets dumped.

[Kartik N V J K](https://hashnode.com/@kartik-nvj)

[Jul 13](https://hashnode.com/posts/building-an-ai-gateway-in-net/6a527d71a7a8fb34334b9feb/comment/6a5532f7937fe7fca7a4636c)

The strongest point is that the boundary matters more than whether it's a separate service, an in-process abstraction around IChatClient gives you consistent retries, telemetry, and prompt versioning without another container. It quietly fixes the "nobody can say which feature caused last month's spend" problem, since one path lets you attribute cost and latency per feature. Do you keep prompt version control inside the gateway next to routing, or in each feature so the gateway stays transport-only?

[Ahmet Özel](https://hashnode.com/@ahmetozel)

[Jul 12](https://hashnode.com/posts/building-an-ai-gateway-in-net/6a527d71a7a8fb34334b9feb/comment/6a52fd4fd4edccbbe2c63bea)

A gateway becomes much more valuable once it owns observability and policy, not just provider routing. I would record model/prompt version, token and latency budgets, retry reason, cache hit, and structured-output validation result per request. Then retries can be limited by an end-to-end deadline instead of multiplying timeouts across layers. For safety, idempotency keys and per-operation policies also help prevent a state-changing tool call from being repeated after a transient model or network failure.

[Jul 12](https://hashnode.com/posts/building-an-ai-gateway-in-net/6a527d71a7a8fb34334b9feb/comment/6a52fd4fd4edccbbe2c63bea#reply-6a5355dc4082d2579493a89d)

Absolutely. The post is intentionally a high-level architectural overview not a complete production blueprint.

[Ahmet Özel](https://hashnode.com/@ahmetozel)

[Oct 4](https://hashnode.com/posts/building-an-ai-gateway-in-net/6a527d71a7a8fb34334b9feb/comment/6a52fd4fd4edccbbe2c63bea#reply-6ac29a64c53a302552cf1fa7)

That is a fair scope correction: an architectural overview does not need to become a complete operational checklist. I would keep my additions as a possible follow-up rather than imply the overview is incomplete.

The one boundary worth carrying into that follow-up is ownership of the end-to-end deadline. If the feature and the gateway each retry independently, individually reasonable settings can exceed the caller's budget. A small request timeline showing which layer owns cancellation and remaining time would explain the issue without turning the gateway into an agent framework.
