Hazina FluentAPI: One Interface for Every LLM Provider
Hazina Framework

Hazina FluentAPI: One Interface for Every LLM Provider

One of the most frustrating things about working with AI APIs is that every provider has a different SDK, different request format, and different response structure. Hazina’s FluentAPI solves this with a unified interface that works with OpenAI, Anthropic, and more.

The Problem

Without Hazina, switching from OpenAI to Anthropic means rewriting your integration code. Different parameter names, different streaming patterns, different error handling. Multiply this across a production app and you have a maintenance nightmare.

The Solution: One API to Rule Them All

using Hazina.AI.FluentAPI.Core;

// Simple question
var answer = await Hazina.AskAsync("Explain quantum computing in simple terms");

// With system prompt
var answer = await Hazina.AskAsync(
    "Translate this to Dutch",
    systemPrompt: "You are a professional translator"
);

Provider Configuration

Hazina supports multiple LLM providers through a clean configuration pattern:

using Hazina.AI.FluentAPI.Configuration;

// OpenAI
QuickSetup.SetupOpenAI(apiKey, model: "gpt-4o");

// Anthropic
QuickSetup.SetupAnthropic(apiKey, model: "claude-sonnet-4-5-20250929");

// Multiple providers simultaneously
QuickSetup.SetupAndConfigure(config => {
    config.AddOpenAI(openAiKey);
    config.AddAnthropic(anthropicKey);
    config.DefaultProvider = "anthropic";
});

Streaming Responses

For real-time output (like a chat interface), Hazina supports streaming out of the box:

await foreach (var chunk in Hazina.StreamAsync("Write a short story"))
{
    Console.Write(chunk);
}

The streaming interface is provider-agnostic – same code whether you’re using OpenAI or Anthropic.

Conversation History

For multi-turn conversations, use the conversation builder:

var conversation = Hazina.CreateConversation()
    .WithSystemPrompt("You are a helpful coding assistant")
    .AddUserMessage("How do I sort a list in C#?")
    .AddAssistantMessage("You can use LINQ: list.OrderBy(x => x)")
    .AddUserMessage("What about descending order?");

var response = await conversation.SendAsync();

Why This Matters

The FluentAPI isn’t just syntactic sugar. It’s a strategic abstraction that lets you:

  • Switch providers without changing application code
  • A/B test different models easily
  • Fall back to alternative providers when one is down
  • Keep your codebase clean and testable

In the next post, we’ll look at how Hazina’s configuration system gives you fine-grained control over every aspect of the AI pipeline.

Frequently Asked Questions

What is Hazina FluentAPI?

Hazina FluentAPI is a unified interface designed to simplify the integration of various AI providers like OpenAI and Anthropic. It eliminates the need for different SDKs and response structures, allowing developers to work seamlessly across multiple LLMs.

How does Hazina FluentAPI handle streaming responses?

Hazina FluentAPI supports real-time output using a provider-agnostic streaming interface. This means you can receive streaming responses from any supported provider, such as OpenAI or Anthropic, using the same code.

Can I switch AI providers easily with Hazina?

Yes, Hazina FluentAPI allows you to switch between different AI providers without rewriting your application code. This feature enables developers to maintain a clean codebase while easily A/B testing or falling back to alternative models.

How do I set up multiple LLM providers with Hazina?

Setting up multiple LLM providers with Hazina is straightforward using the QuickSetup configuration. You can add different providers like OpenAI and Anthropic, specify your API keys, and choose a default provider, all while keeping your configuration clean and manageable.

Terug naar overzicht

Frequently Asked Questions

How does Hazina's FluentAPI simplify working with different LLM providers? +

Hazina's FluentAPI provides a unified interface that eliminates the need to rewrite integration code when switching between LLM providers like OpenAI and Anthropic. This is achieved by standardizing request formats, parameter names, and error handling across different APIs.

What is the purpose of the conversation builder in Hazina's FluentAPI? +

The conversation builder allows users to manage multi-turn conversations by adding user and assistant messages efficiently. It streamlines the process of handling dialogues, enabling developers to create more interactive applications.

Can Hazina's FluentAPI handle streaming responses, and how does it work? +

Yes, Hazina's FluentAPI supports streaming responses out of the box, allowing for real-time output. Developers can use the same code for streaming regardless of the provider, making it easy to implement chat interfaces.

What configuration options does Hazina provide for setting up multiple LLM providers? +

Hazina offers a clean configuration pattern that allows developers to set up multiple LLM providers simultaneously, such as OpenAI and Anthropic. Users can specify default providers and manage API keys easily through the QuickSetup methods.

How does the FluentAPI contribute to maintaining a clean codebase? +

The FluentAPI acts as a strategic abstraction that enables developers to switch providers, A/B test models, and handle provider downtimes without altering application code. This approach helps keep the codebase organized and testable.

ENNL