The Power of AI with Delphi: How Dext Framework Simplifies Gemini Integration

I see many articles out there showing complex AI integrations using a “fruit salad” of technologies: heavy JS frameworks on the front, layer upon layer on the back. Sometimes, it seems that to be “modern”, you need to complicate things.
But Delphi has always been about simplicity and power. And with the Dext Framework, this philosophy reaches a new level.
I decided to prove that it’s possible to create a modern AI chat, with a premium look and high performance, using only Delphi and a simple HTML/Tailwind frontend — all served by a single binary. No unnecessary “back and forth”, just clean code straight to the point.
The result? Clean, high-performance, and extremely productive code.
The Architecture: Less is More
Section titled “The Architecture: Less is More”The secret of this project is the Full Stack Delphi concept. Instead of separating the frontend and backend into different ecosystems that barely talk to each other, we use Dext to unify the experience. The Delphi server not only processes the AI logic but also delivers static files in an optimized way.
What we used in this project:
Section titled “What we used in this project:”- Minimal API Style: No heavy controllers. Routes defined fluently and directly in the
.dpr. - Serving Static Files: One line of code to serve your entire frontend (
wwwroot). The UI is simple on purpose, focused on demonstrating rapid AI integration. - Smart Model Binding: Dext receives JSON from the frontend and automatically transforms it into a validated Delphi
record. - Dependency Injection (DI): Native instance management with
TActivator. - Async RestClient: Non-blocking communication with the Gemini API using
.Await. - Attribute Validation: Ensuring data arrives correctly using
[Required].
The Frontend: Modern and Fast
Section titled “The Frontend: Modern and Fast”For the frontend, no complex configurations. We used a simple index.html with Tailwind CSS for a premium Glassmorphism look, consuming our Delphi API via fetch.

Dext serves this file automatically through the .UseStaticFiles('wwwroot') middleware.
[!TIP] Evolving the UI: Although we used pure HTML for this example, Dext offers powerful template engines like the Dext Template Engine (AST-based, Razor-style) and native support for Web Stencils (Delphi 12.2+). This allows you to create dynamic and complex views on the server (SSR) with the same ease.
Diving into the Code
Section titled “Diving into the Code”1. The Server (Minimal API)
Section titled “1. The Server (Minimal API)”See how simple it is to configure the server. We use logging and exception handling middlewares that greatly facilitate debugging during development.
program DextGeminiServer;
uses Dext, Dext.Web, Dext.Net.RestClient, Gemini.Models;
begin var App := WebApplication;
App.Builder .UseDeveloperExceptionPage .UseHttpLogging .UseStaticFiles('wwwroot')
// AI API Route .MapPost<TChatRequest, IResult>('/ia/ask', function(Req: TChatRequest): IResult begin var Response := RestClient(AgentModelUrl) .PostJson(TDextJson.Serialize(TGeminiRequest.Create(Req.question))) .Await;
if Response.StatusCode = HttpStatus.OK then begin var Gemini := TDextJson.Deserialize<TGeminiResponse>(Response.ContentString); Result := Results.Ok(TChatResponse.Create(Gemini.FirstText)); end else Result := Results.Problem('Gemini API Error'); end);
App.Run;end.2. Modeling with Records and DI
Section titled “2. Modeling with Records and DI”Forget complex classes for DTOs. In Dext, we use records to map JSON, which reduces memory consumption and simplifies the code.
type TChatRequest = record public [Required] question: string; end;Conclusion: Why Dext?
Section titled “Conclusion: Why Dext?”The point here isn’t to say one technology is better than another, but to show the power of choice. With the Dext Framework, the Delphi developer gains modern superpowers:
- Productivity: Less repetitive code (boilerplate).
- Modernity: Patterns used by the largest tech companies (Minimal APIs, Async/Await).
- Performance: Low resource consumption and high response speed.
If you want to take your Delphi applications to the next level and integrate with the latest in Artificial Intelligence, Dext is the way.
What do you think of this approach? Are you already using AI in your Delphi projects? Let’s talk in the comments!
#Delphi #DextFramework #AI #Gemini #WebDevelopment #Backend #Productivity
Dext Documentation: Read the Technical Details