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:
- Hardcoded defaults – sensible out of the box
- appsettings.json – standard .NET configuration
- Environment variables – for secrets and deployment overrides
- 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
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.
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.
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.
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.