aix.config

Central configuration for AIX (single source of truth for defaults).

This module is the SSOT for *what model (and related parameters) each AIX function uses by default*. Instead of scattering hardcoded DFLT_* constants across modules, every function resolves its defaults from a single, layered configuration.

Resolution layers, highest precedence first:

  1. Explicit call argument – e.g. chat(..., model=...) always wins (handled at the call site, not here).

  2. Runtime override – configure() swaps the active config; using() scopes an override to a with block.

  3. Environment variables – AIX_CHAT_MODEL, AIX_CHAT_TEMPERATURE, AIX_EMBEDDING_MODEL, AIX_IMAGE_MODEL, AIX_TTS_MODEL, AIX_TTS_VOICE, AIX_TRANSCRIPTION_MODEL, …

  4. User config file – a TOML file at <app config dir>/config.toml (override the path with the AIX_CONFIG_FILE environment variable).

  5. Shipped defaults – the dataclass field defaults below.

The schema is a set of frozen dataclasses (immutable). A module-level *active config* pointer holds the currently resolved AixConfig; configure() and using() swap that pointer rather than mutating in place (using swaps a context-local overlay, so concurrent with blocks in different threads or asyncio tasks are isolated).

Examples

>>> from aix import config
>>> c = config.get_config()
>>> isinstance(c.chat.model, str)
True

Scoped override (does not leak outside the block):

>>> with config.using(chat_model="some/model"):
...     config.get_config().chat.model
'some/model'
>>> config.get_config().chat.model == c.chat.model
True

TOML config file shape:

[chat]
model = "openai/gpt-4o-mini"
temperature = 1.0

[embeddings]
model = "text-embedding-3-small"

[image]
model = "dall-e-3"
size = "1024x1024"
edit_model = "dall-e-2"

[audio]
tts_model = "tts-1"
tts_voice = "alloy"
transcription_model = "whisper-1"

[vision]
model = "gpt-4o-mini"

[aliases]
fast = "openai/gpt-4o-mini"
best = "anthropic/claude-sonnet-4"

Functions

load_config([path, environ])

Resolve an AixConfig from shipped defaults, TOML file, and env.

get_config()

Return the current active AixConfig.

set_config(config)

Replace the active config wholesale.

configure(**overrides)

Apply runtime overrides to the active config and return it.

using(**overrides)

Context manager applying scoped overrides, restored on exit.

config_file_path()

Path to the user config file (env AIX_CONFIG_FILE overrides default).

resolve_model(model, *[, config])

Resolve a semantic alias ("fast", "best", ...) to a concrete model id.

Classes

ChatConfig([model, temperature, max_tokens, ...])

Defaults for chat / ask / complete / sample / prompt_func.

EmbeddingConfig([model, batch_size])

Defaults for embeddings / embed.

ImageConfig([model, size, quality, ...])

Defaults for generate_image / generate_images and the edit/variation calls.

AudioConfig([tts_model, tts_voice, ...])

Defaults for text_to_speech / transcribe / translate_audio.

VideoConfig([provider])

Defaults for generate_video (provider-dependent).

VisionConfig([model])

Defaults for describe_image (image→text).

AixConfig([chat, embeddings, image, audio, ...])

Top-level AIX configuration (single source of truth for defaults).

class aix.config.AixConfig(chat=ChatConfig(), embeddings=EmbeddingConfig(), image=ImageConfig(), audio=AudioConfig(), video=VideoConfig(), vision=VisionConfig(), aliases=<factory>)[source]

Bases: object

Top-level AIX configuration (single source of truth for defaults).

class aix.config.AudioConfig(tts_model='gpt-4o-mini-tts', tts_voice='alloy', tts_speed=1.0, transcription_model='whisper-1')[source]

Bases: object

Defaults for text_to_speech / transcribe / translate_audio.

class aix.config.ChatConfig(model='gpt-4.1-mini', temperature=1.0, max_tokens=None, sample_concurrency=5, schema_max_repairs=1)[source]

Bases: object

Defaults for chat / ask / complete / sample / prompt_func.

class aix.config.EmbeddingConfig(model='text-embedding-3-small', batch_size=512)[source]

Bases: object

Defaults for embeddings / embed.

class aix.config.ImageConfig(model='openai/gpt-image-1.5', size='1024x1024', quality='auto', num_images=1, edit_model='openai/gpt-image-1.5', variation_model='dall-e-2')[source]

Bases: object

Defaults for generate_image / generate_images and the edit/variation calls.

OpenAI retired the DALL-E models from its images endpoint (dall-e-3 returns “does not exist” as of late 2026), so the defaults are the gpt-image family: openai/gpt-image-1.5 for generation and edits (the provider prefix is explicit because LiteLLM’s model map does not yet know the name). quality for that family is one of low, medium, high or auto (DALL-E’s standard/hd are rejected). Variations are still a DALL-E 2 feature with no gpt-image equivalent; variation_model is kept for callers whose provider still serves it.

class aix.config.VideoConfig(provider=None)[source]

Bases: object

Defaults for generate_video (provider-dependent).

class aix.config.VisionConfig(model='gpt-4o-mini')[source]

Bases: object

Defaults for describe_image (image→text).

The default is a cheap, vision-capable OpenAI model so it works with the same OPENAI_API_KEY most users already have; override per call (describe_image(..., model=...)), via configure(vision_model=...), or the [vision] TOML section to route to Claude / Gemini / etc.

aix.config.config_file_path()[source]

Path to the user config file (env AIX_CONFIG_FILE overrides default).

Return type:

str

aix.config.configure(**overrides)[source]

Apply runtime overrides to the active config and return it.

Examples

>>> from aix import config
>>> _ = config.configure(chat_model="openai/gpt-4o-mini")
>>> config.get_config().chat.model
'openai/gpt-4o-mini'
>>> _ = config.configure(chat={"temperature": 0.2})
>>> config.get_config().chat.temperature
0.2
Return type:

AixConfig

aix.config.get_config()[source]

Return the current active AixConfig.

Inside a using() block this is the scoped config of the current thread or asyncio task; otherwise the process-wide config.

Return type:

AixConfig

aix.config.load_config(path=None, *, environ=None)[source]

Resolve an AixConfig from shipped defaults, TOML file, and env.

Precedence (low to high): shipped defaults < TOML file < environment variables. Runtime overrides (configure()/using()) and explicit call arguments sit above this and are applied elsewhere.

Parameters:
Return type:

AixConfig

Returns:

A fully resolved AixConfig.

aix.config.resolve_model(model, *, config=None)[source]

Resolve a semantic alias ("fast", "best", …) to a concrete model id.

Plain substitution: if model is a key in the active aliases table it is replaced (following chains, with cycle protection). Anything that is not an alias – including every literal model id like "gpt-4o" – is returned unchanged. None passes through (callers apply their own default first).

Note

aliases share a namespace with literal model ids, so an unknown name is treated as a literal id, not an error. Inspect available aliases via aix.get_config().aliases.

Examples

>>> from aix import config
>>> config.resolve_model("fast") in config.DEFAULT_ALIASES.values()
True
>>> config.resolve_model("gpt-4o")  # not an alias -> unchanged
'gpt-4o'
>>> config.resolve_model(None) is None
True
Return type:

Optional[str]

aix.config.set_config(config)[source]

Replace the active config wholesale. Returns the new active config.

Inside a using() block this replaces only that block’s scoped config (it is discarded on exit); outside, it replaces the process-wide config.

Return type:

AixConfig

aix.config.using(**overrides)[source]

Context manager applying scoped overrides, restored on exit.

The override lives in a ContextVar, so it is private to the current thread / asyncio task: concurrent using() blocks do not leak into each other, nor into code running outside any block. A thread you start yourself typically begins with an empty context and sees the process-wide config (carry a scope into it with contextvars.copy_context()); aix’s own worker pools (sample, batch_chat…) propagate it. An asyncio task created inside the block keeps the scope for its lifetime.

Examples

>>> from aix import config
>>> with config.using(chat_temperature=0.0) as c:
...     c.chat.temperature
0.0
Return type:

Iterator[AixConfig]