Hazina Configuration: Fine-Tuning Your AI Pipeline
Hazina Framework

Hazina Configuration: Fine-Tuning Your AI Pipeline

Default settings are great for getting started, but production applications need fine-grained control. Hazina’s layered configuration system lets you tune everything from token limits to retry policies – without cluttering your code.

Configuration Layers

Hazina uses a cascading configuration model:

  1. Hardcoded defaults – sensible out of the box
  2. appsettings.json – standard .NET configuration
  3. Environment variables – for secrets and deployment overrides
  4. Code-based setup – for dynamic or programmatic configuration

appsettings.json Example

{
  "Hazina": {
    "AI": {
      "DefaultProvider": "openai",
      "OpenAI": {
        "ApiKey":  - , // Use env var instead
        "Model": "gpt-4o",
        "MaxTokens": 4096,
        "Temperature": 0.7
      },
      "Anthropic": {
        "ApiKey":  - ,
        "Model": "claude-sonnet-4-5-20250929",
        "MaxTokens": 4096
      }
    },
    "Storage": {
      "Type": "sqlite",
      "ConnectionString": "Data Source=hazina.db"
    }
  }
}

Programmatic Configuration

builder.Services.AddHazina(config => {
    config.AI.DefaultProvider = "openai";
    config.AI.MaxTokens = 8192;
    config.AI.Temperature = 0.3f; // More deterministic
    config.AI.RetryPolicy = new RetryPolicy {
        MaxRetries = 3,
        BackoffMultiplier = 2.0
    };

    config.Storage.UseSqlite("hazina.db");
    // Or for production:
    // config.Storage.UsePostgreSQL(connectionString);
});

Environment Variable Overrides

Any configuration value can be overridden via environment variables using the double-underscore convention:

HAZINA__AI__DEFAULTPROVIDER=anthropic
HAZINA__AI__MAXTOKENS=8192
HAZINA__STORAGE__TYPE=postgresql

Per-Request Overrides

Need different settings for a specific call? Override inline:

var response = await Hazina.AskAsync("Summarize this document",
    options: new RequestOptions {
        Model = "gpt-4o-mini",  // Cheaper model for simple tasks
        MaxTokens = 500,
        Temperature = 0.0f       // Deterministic
    });

Configuration Validation

Hazina validates your configuration at startup and provides clear error messages:

// This will throw with a helpful message:
// "No API key configured for provider 'openai'.
//  Set OPENAI_API_KEY environment variable or configure via appsettings.json"

No more silent failures or cryptic 401 errors. Hazina tells you exactly what’s wrong.

In the next post, we’ll explore the Generic API Framework – Hazina’s approach to eliminating boilerplate CRUD code.

Frequently Asked Questions

How can I fine-tune the Hazina AI configuration?

You can fine-tune the Hazina AI configuration using its layered configuration system, which includes hardcoded defaults, appsettings.json, environment variables, and programmatic setups. This allows you to customize settings like token limits, retry policies, and model choices without cluttering your code.

What are the options for overriding Hazina configuration values?

Hazina configuration values can be overridden using environment variables with a double-underscore convention, allowing for easy deployment overrides. Additionally, you can set per-request overrides directly in the code for specific calls, customizing options like model and token limits.

How does Hazina validate configuration settings?

Hazina validates your configuration at startup and provides clear error messages if something is wrong, such as missing API keys. This prevents silent failures and helps you quickly identify and resolve issues, improving the reliability of your AI application.

What types of storage does Hazina support?

Hazina supports multiple storage types, including SQLite for development and PostgreSQL for production environments. You can specify your storage type and connection string in the configuration to ensure your application meets its data management needs.

Terug naar overzicht

Frequently Asked Questions

What are the layers of configuration that Hazina supports? +

Hazina supports a cascading configuration model that includes hardcoded defaults, appsettings.json for standard .NET configuration, environment variables for secrets and deployment overrides, and code-based setup for dynamic configuration.

How can I override configuration values for Hazina using environment variables? +

You can override any configuration value in Hazina using the double-underscore convention, such as HAZINA__AI__DEFAULTPROVIDER=anthropic or HAZINA__STORAGE__TYPE=postgresql.

What kind of validation does Hazina provide for configuration settings? +

Hazina validates your configuration at startup and provides clear error messages, helping to identify issues like missing API keys with specific feedback, which prevents silent failures.

How can I set different settings for a specific request in Hazina? +

You can override settings for a specific call by using inline overrides in the request options, for example, specifying a different model or adjusting MaxTokens and Temperature parameters directly in the AskAsync method.

What is an example of programmatic configuration in Hazina? +

An example of programmatic configuration in Hazina includes setting the default AI provider, adjusting MaxTokens and Temperature, and defining a RetryPolicy, all done through the AddHazina method within the service configuration.

ENNL