> built 2026-11-23 07:25 UTC from 2859d9c (master) · aix 0.0.62. Details: build_info.json

# index.html.md

<!-- generated by epythet -->

# AIX: Artificial Intelligence eXtensions

A clean, pythonic facade for common AI operations that abstracts away provider-specific details and complexities.

**Philosophy**: Make AI interactions as simple and intuitive as Python itself, while maintaining the power and flexibility needed for production use.

## Installation

```bash
pip install aix
```

`aix` is a headless facade and keeps its hard dependencies minimal — the base
install only pulls in [`litellm`](https://github.com/BerriAI/litellm) (the
provider backend) and `config2py` (for reading API keys / config). Optional
capabilities live in extras and are imported lazily, raising a clear install
hint if their backend is missing:

```bash
pip install "aix[image]"      # image generation helpers (Pillow)
pip install "aix[video]"      # local text-to-video (diffusers, torch)
pip install "aix[discovery]"  # model discovery via OpenRouter / Ollama (requests)
pip install "aix[google]"     # legacy Google Gemini backend
pip install "aix[openai]"     # legacy OpenAI (oa) backend
pip install "aix[all]"        # all optional backends
```

With a Claude subscription and the [Claude Code CLI](https://docs.claude.com/en/docs/claude-code/setup) installed, `chat("...", model="claude-cli/haiku")` (or `sonnet`, `opus`) runs the prompt through `claude -p` with no API key. The CLI has no sampling controls, so `temperature`, `max_tokens`, `stream` and the like raise `ValueError`; the cost it reports is `claude_cli_cost(complete(...))`.

## Quick Start

<!-- wads-docs: skip needs a provider API key -->
```python
from aix import chat, embeddings, prompt_func, models
from aix import generate_image, text_to_speech, transcribe

# Simple chat
response = chat("What is 2+2?")
print(response)  # "The answer is 4."

# Create prompt-based functions
translate = prompt_func("Translate to French: {text}")
result = translate(text="Hello world")
print(result)  # "Bonjour le monde"

# Get embeddings
vecs = list(embeddings(["hello", "world"]))
print(len(vecs))  # 2

# Generate images
image = generate_image("A serene mountain landscape")
image.save("landscape.png")

# Text to speech
audio = text_to_speech("Hello, world!")
audio.save("hello.mp3")

# Speech to text
text = transcribe("recording.mp3")

# Discover available models
models.discover()
print(list(models)[:5])  # ['openai/gpt-4o', 'openai/gpt-4o-mini', ...]
```

## Configuration

`aix` works with zero configuration — every function ships with sensible default
models. When you want to change *which model a function uses by default* (and
related parameters like temperature, image size, or TTS voice), there is a single
source of truth: `aix.config`.

Defaults are resolved in layers, **highest precedence first**:

1. **Explicit call argument** — `chat("hi", model="...")` always wins.
2. **Runtime override** — `aix.configure(...)` (persistent) or `aix.using(...)` (scoped).
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 (see below).
5. **Shipped defaults** — the built-in values.

<!-- wads-docs: skip needs a provider API key -->
```python
import aix

# Inspect the active configuration
cfg = aix.get_config()
cfg.chat.model  # 'gpt-4.1-mini'
cfg.embeddings.model  # 'text-embedding-3-small'

# Persistently change a default (everything below an explicit arg still respects it)
aix.configure(chat_model="anthropic/claude-sonnet-4", chat_temperature=0.2)

# Scoped override that restores on exit
with aix.using(chat_model="openai/gpt-4o-mini"):
    aix.chat("quick + cheap question")
# back to the configured default here
```

### Semantic aliases

Pass an intent-level name instead of a concrete model id. Shipped aliases:
`fast` (cheap/low-latency), `best` (highest quality), `cheap` (cheapest).

<!-- wads-docs: skip needs a provider API key -->
```python
aix.chat("hard question", model="best")  # -> resolves via the alias table
aix.chat("quick question", model="fast")

# Add or override aliases (merges with the shipped set)
aix.configure(aliases={"smart": "anthropic/claude-sonnet-4"})
aix.resolve_model("smart")  # 'anthropic/claude-sonnet-4'
```

Aliases share a namespace with literal model ids: a name that is not a registered
alias (e.g. `"gpt-4o"`) is passed through unchanged. Inspect available aliases via
`aix.get_config().aliases`.

### Config file

Create a TOML file at your platform’s app-config dir (or point `AIX_CONFIG_FILE`
at any path):

```toml
[chat]
model = "gpt-4.1-mini"
temperature = 1.0

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

[image]
model = "openai/gpt-image-1.5"
size = "1024x1024"
edit_model = "openai/gpt-image-1.5"

[audio]
tts_model = "gpt-4o-mini-tts"
tts_voice = "alloy"
transcription_model = "whisper-1"

[aliases]              # semantic names -> concrete ids (override the shipped set)
fast = "gpt-4.1-mini"
best = "anthropic/claude-sonnet-4"
```

Find the active path with `aix.config.config_file_path()`. Environment variables
override file values; explicit call arguments override everything.

## Providing credentials

Every key-requiring function (`chat`, `embeddings`, `generate_image`,
`text_to_speech`, `transcribe`, `generate_video`, …) resolves its API key
through one documented path. The resolution order, highest precedence first:

1. **Explicit argument** — `chat("hi", api_key="sk-...")` (keyword-only, on every
   key-requiring function).
2. **Provider environment variable** — the canonical name for the model’s
   provider (see the table below). A project `.env` is *softly* discovered when
   `python-dotenv` is installed; an explicitly exported variable always wins over
   a `.env` value.
3. **AIX config store** — a per-user store in your app-config folder, keyed by the
   canonical env-var name (so the store and the env layer share one namespace).
4. **(Interactive only) prompt + persist** — in a REPL, AIX can ask once and save
   the key to the config store.

The provider is inferred from the model id, so you rarely name it yourself:

```python
import aix

aix.chat("Hello", model="gpt-4o")  # uses OPENAI_API_KEY
aix.chat("Hi", model="claude-sonnet-4")  # uses ANTHROPIC_API_KEY
aix.chat("Yo", api_key="sk-...")  # explicit key wins

# Check what's discoverable (values are never shown — availability only):
aix.check_keys()
# {'openai': {'available': True, 'env_vars': ['OPENAI_API_KEY'], 'source': 'env'}, ...}
```

When a required key is missing, you get an actionable `MissingCredentialError`
naming *which* key, *how* to set it, and *where* to get one — instead of a cryptic
provider error:

```python
>>> aix.chat("hi", model="gpt-4o")
aix.credentials.MissingCredentialError: No API key found for provider 'openai'
(model 'gpt-4o'). Set OPENAI_API_KEY via one of:
  - export it:  export OPENAI_API_KEY=...
  - add it to a .env file in your project, or
  - store it in the AIX config store under the key 'OPENAI_API_KEY'.
Get a key at: https://platform.openai.com/api-keys
```

### Provider → environment variable

| Provider       | Environment variable                   | Get a key                                   |
|----------------|----------------------------------------|---------------------------------------------|
| OpenAI         | `OPENAI_API_KEY`                       | https://platform.openai.com/api-keys        |
| Anthropic      | `ANTHROPIC_API_KEY`                    | https://console.anthropic.com/settings/keys |
| Google Gemini  | `GEMINI_API_KEY` (or `GOOGLE_API_KEY`) | https://aistudio.google.com/apikey          |
| OpenRouter     | `OPENROUTER_API_KEY`                   | https://openrouter.ai/keys                  |
| Mistral        | `MISTRAL_API_KEY`                      | https://console.mistral.ai/api-keys/        |
| Cohere         | `COHERE_API_KEY`                       | https://dashboard.cohere.com/api-keys       |
| Groq           | `GROQ_API_KEY`                         | https://console.groq.com/keys               |
| DeepSeek       | `DEEPSEEK_API_KEY`                     | https://platform.deepseek.com/api_keys      |
| xAI            | `XAI_API_KEY`                          | https://console.x.ai/                       |
| Perplexity     | `PERPLEXITYAI_API_KEY`                 | https://www.perplexity.ai/settings/api      |
| Runway (video) | `RUNWAY_API_KEY`                       | https://app.runwayml.com/                   |

The full mapping is `aix.PROVIDER_ENV_VARS`. Keys are never logged, and the config
store lives in your user app-config folder — never in the repo.

## Core Features

### 1. Chat Interface

Clean, provider-agnostic chat completions:

<!-- wads-docs: skip needs an Anthropic API key -->
```python
from aix import chat

# Simple text prompt
response = chat("Explain quantum computing in one sentence")

# With specific model
response = chat("Hello!", model="gpt-4o-mini")

# With message history
messages = [
    {"role": "user", "content": "My name is Alice"},
    {"role": "assistant", "content": "Nice to meet you, Alice!"},
    {"role": "user", "content": "What's my name?"},
]
response = chat(messages, model="gpt-4o")

# Streaming responses
for chunk in chat("Count to 5", stream=True):
    print(chunk, end="", flush=True)

# Stateful conversations
from aix import chat_with_history

session = chat_with_history("You are a helpful math tutor")
response = session.send("What is 2+2?")
response = session.send("And if I add 3 to that?")  # Remembers context
```

`chat()` returns only the first choice’s text. When you need the rest of the response (every one of `n` choices, token usage, why each choice stopped, the model that actually served the call), use `complete()`, which takes the same arguments and returns a `Completion`:

<!-- wads-docs: skip needs an Anthropic API key -->
```python
from aix import complete, Usage

c = complete("Name a color", n=3, temperature=1.0)
c.texts  # ('Blue', 'Green', 'Red')     -- all n choices
c.finish_reasons  # ('stop', 'stop', 'stop')     -- 'length' means truncated by max_tokens
c.usage  # Usage(prompt_tokens=11, completion_tokens=6, total_tokens=17, cached_prompt_tokens=0, ...)
c.model  # the model id the provider reports having served
c.text  # first choice, i.e. what chat() would return
c.raw  # the untouched LiteLLM response

# Usage values add up, for cost reporting. usage is None when a provider reports none.
cs = [complete(q) for q in questions]
total = sum((c.usage for c in cs if c.usage), Usage())
```

To ask the same question several times (agreement, stability, majority vote), use `sample()`. It sends one request with provider-side `n` when LiteLLM reports that the model supports it, and otherwise makes `n` independent requests concurrently. It records which path it took, because the two are not the same statistical object:

<!-- wads-docs: skip needs an Anthropic API key -->
```python
import json
from aix import sample

s = sample(
    'Is a tomato a fruit? Reply as JSON {"answer": bool}',
    n=5,
    temperature=1.0,
    parse=json.loads,
)
s.strategy  # 'provider_n', 'independent' or 'mixed'
s.payloads  # parsed answers (None where parsing failed)
[x.finish_reason for x in s]  # 'content_filter' means refused, 'length' means truncated
s.usage  # total tokens across every request that reported usage
s.n_requests  # how many requests were made
```

A failed request does not discard the work already paid for. By default `sample()` raises `SamplingError` once the launched requests finish, and the partial batch is on its `.samples`. With `on_error="record"`, the failure is stored on that sample’s `.error` instead. A `seed` is sent as-is with a provider-side `n` request; each independent request gets a seed derived from `(seed, index)`.

`constrained_answer(..., n=k)` now runs its `k` calls concurrently too (`concurrency=`, default from config `chat.sample_concurrency`).

#### Seeds, determinism, and asking before calling

`complete()` and `sample()` take a keyword-only `seed`. Its support is provider-dependent, and even where it is supported, determinism is best-effort. So before you read run-to-run variance as a property of the model, check two things:

<!-- wads-docs: skip needs an Anthropic API key -->
```python
from aix import supports, complete

supports("gpt-4o-mini", "seed")  # True  -- LiteLLM forwards seed (best-effort)
supports(
    "anthropic/claude-sonnet-4", "seed"
)  # False -- seed would be dropped or rejected
supports("gpt-4o-mini", "n")  # provider-side n (what sample() prefers)
supports(
    "gpt-4o-mini", "response_schema"
)  # strict/schema structured output (response_schema=)

a = complete("...", seed=7, temperature=0)
b = complete("...", seed=7, temperature=0)
a.system_fingerprint == b.system_fingerprint  # if this differs, the backend changed: the comparison is void
```

`supports(model, param)` wraps LiteLLM’s `get_supported_openai_params`, and `"response_schema"` is answered by `supports_response_schema`. It is conservative: `False` means “not known to work”, so if you branch on it you take the path that works everywhere. `True` only means LiteLLM forwards the parameter. A router such as OpenRouter can still drop `seed` or `n` upstream, and seeding is best-effort on every provider (reasoning models may ignore it). That is why the fingerprint check matters. Each `Sample` from `sample()` also carries its `system_fingerprint`.

### 2. Embeddings

Generate vector embeddings for semantic search and similarity:

<!-- wads-docs: skip needs a provider API key -->
```python
from aix import embeddings, embed, cosine_similarity, find_most_similar

# Batch embeddings
texts = ["cat", "dog", "bird"]
vecs = list(embeddings(texts))

# Single text
vec = embed("Hello, world!")

# Compute similarity
v1 = embed("cat")
v2 = embed("kitten")
similarity = cosine_similarity(v1, v2)  # High similarity

# Find most similar documents
query = "What is machine learning?"
docs = [
    "Machine learning is a type of AI",
    "Python is a programming language",
    "Neural networks are used in deep learning",
]
results = find_most_similar(query, docs, top_k=2)
# Returns: [('Machine learning is a type of AI', 0.95), ...]

# Caching for efficiency
from aix import EmbeddingCache

cache = EmbeddingCache()
v1 = cache.embed("hello")  # API call
v2 = cache.embed("hello")  # From cache
```

### 3. Prompt-Based Functions

Transform natural language prompts into reusable Python functions:

```python
from aix import prompt_func, prompt_to_text, prompt_to_json

# Simple text generation
summarize = prompt_func("Summarize this text: {text}")
summary = summarize(text="Long article...")

# Structured output
extract_person = prompt_func(
    "Extract person information from: {text}",
    output_schema={"name": str, "age": int, "email": str},
)
result = extract_person(text="Contact John at john@example.com. He is 30 years old.")
# Returns: {'name': 'John', 'age': 30, 'email': 'john@example.com'}

# Multiple parameters
compare = prompt_func("Compare {item1} and {item2} in terms of {aspect}")
result = compare(item1="Python", item2="JavaScript", aspect="learning curve")

# Pre-built common functions
from aix import common_funcs

summary = common_funcs.summarize(text="Long article...")
keywords = common_funcs.extract_keywords(text="Article about AI and ML")
sentiment = common_funcs.sentiment(text="I love this product!")

# Create custom collections
from aix import PromptFuncs

my_funcs = PromptFuncs(model="gpt-4o")
my_funcs.add("analyze", "Analyze this code: {code}")
my_funcs.add("fix_bugs", "Fix bugs in: {code}")

result = my_funcs.analyze(code="def foo(): return bar")
```

#### `prompt_func` and prompt-optimisation frameworks

`prompt_func` is for prompts whose template is *data*: a string constant, or a template loaded from a store at run time. Parameters and `{name:default}` defaults come from the template, `egress=` turns the reply into a typed value, and model and credentials come from aix’s configuration. If you would rather declare inputs and outputs and let a framework write and optimise the prompt against a metric, use [DSPy](https://github.com/stanfordnlp/dspy) instead; it does a different job. If your prompts are hand-written Python functions that return a string, [Mirascope](https://github.com/Mirascope/mirascope) fits that style.

#### Enforced, validated structured output

`output_schema` above is flat and only requested in the prompt; nothing checks the reply against it. For anything nested (objects inside objects, arrays of objects, enums, required vs optional), pass `response_schema=`, either a Pydantic model or a JSON Schema dict. It works on `complete()`, `sample()` and `prompt_func()`:

<!-- wads-docs: skip needs an Anthropic API key -->
```python
from typing import Literal
from pydantic import BaseModel
from aix import complete, prompt_func


class Span(BaseModel):
    start: int
    end: int


class Judgement(BaseModel):
    value: Literal["yes", "no", "unsure"]
    confidence: float
    evidence: list[Span]


judge = prompt_func("Does this text claim {claim}? {text}", response_schema=Judgement)
judge(
    claim="...", text="..."
)  # -> Judgement(value='yes', confidence=0.8, evidence=[...])

c = complete("...", response_schema=Judgement)
c.value  # the validated Judgement (raises SchemaValidationError if still invalid)
c.schema_mode  # 'strict' | 'schema' | 'json_mode' -- how the provider enforced it
c.repairs  # extra requests made to fix invalid replies (their tokens are in c.usage)
```

The provider enforces the schema as strongly as the model allows:

- **`strict`**: a strict `json_schema` response format, which constrains decoding. Used when LiteLLM’s `supports_response_schema(model)` is true and the schema is strict-compatible (every object closes `additionalProperties` and requires all of its properties; Pydantic models are converted to that form automatically).
- **`schema`**: the same format, non-strict, for a schema that is not strict-compatible.
- **`json_mode`**: JSON mode plus the schema written into the prompt, for models without schema support (or whose support is unknown).
- **`prompt`**: the schema in the prompt only, for models LiteLLM knows accept no `response_format` at all.

A schema whose root is not an object (a list, a union, a `RootModel`) is sent wrapped as `{"value": ...}`, since providers only constrain objects. It is unwrapped for you after validation.

Every reply is also validated client-side. An invalid reply is re-asked up to `max_repairs` times (default from config `chat.schema_max_repairs`, which is 1), and each repair request shows the model its error. A refusal is recorded and never re-asked. A failed repair request is recorded on that choice; the other choices are kept.

### 4. Model Discovery & Selection

Discover and filter models across providers:

<!-- wads-docs: skip needs network discovery (models.discover) and an API key to chat -->
```python
from aix import models

# Discover available models
models.discover("openrouter")  # Fetch 400+ models from OpenRouter

# List all models
all_models = list(models)

# Get specific model info
info = models["openai/gpt-4o"]
print(info.provider)  # 'openai'
print(info.context_size)  # 128000

# Filter models
openai_models = models.filter(provider="openai")
cheap_models = models.filter(
    custom_filter=lambda m: m.cost_per_token.get("input", 0) < 0.001
)
local_models = models.filter(is_local=True)

# Search models
results = models.search("gpt-4")
results = models.search("claude")

# Get recommendations
recommended = models.recommend(
    task="chat", max_cost_per_mtok=5.0, min_context_size=16000
)

# Use with chat
model = models["gpt-4o-mini"]
response = chat("Hello", model=model.id)
```

### 5. Batch Operations

Process multiple requests efficiently:

<!-- wads-docs: skip needs a provider API key -->
```python
from aix import batch_chat, batch_embeddings, BatchProcessor

# Batch chat
prompts = ["What is 2+2?", "What is 3+3?", "What is 5+5?"]
results = list(batch_chat(prompts, batch_size=10, max_workers=5))

# Batch embeddings
texts = ["hello", "world", "foo", "bar"] * 100
vectors = list(batch_embeddings(texts, batch_size=20, show_progress=True))

# Generic batch processing
from aix import batch_process


def analyze(text):
    return chat(f"Analyze sentiment: {text}")


texts = ["I love it!", "It's okay", "Terrible"]
results = list(batch_process(texts, analyze, batch_size=5, retry_attempts=3))

# Stateful batch processor
processor = BatchProcessor(show_progress=True)
results = processor.process_chats(prompts)
processor.save_results("output.json")
```

### 6. Image Generation

Generate images from text descriptions:

<!-- wads-docs: skip needs a provider API key -->
```python
from aix import generate_image, generate_images

# Simple image generation
image = generate_image("A serene mountain landscape at sunset")
image.save("landscape.png")

# High quality with DALL-E 3
image = generate_image(
    "Abstract art with vibrant colors", model="openai/gpt-image-1.5", quality="high"
)

# Generate multiple variations
images = generate_images("A cute robot waving hello", n=3, size="512x512")
for i, img in enumerate(images):
    img.save(f"robot_{i}.png")

# Edit existing images
from aix import edit_image

edited = edit_image("photo.jpg", "Add a rainbow in the sky", mask_path="sky_mask.png")

# Create variations
from aix import create_variation

variations = create_variation("original.png", n=3)
```

### 7. Audio Operations

Text-to-speech and speech-to-text:

<!-- wads-docs: skip needs a provider API key -->
```python
from aix import text_to_speech, transcribe, transcribe_with_timestamps

# Text to speech
audio = text_to_speech("Hello, world!")
audio.save("hello.mp3")

# Different voices
audio = text_to_speech("This is a test", voice="nova", speed=1.2)

# Transcribe audio
text = transcribe("recording.mp3")
print(text)  # "This is the transcribed text"

# With language hint
text = transcribe("spanish_audio.mp3", language="es")

# Detailed transcription with timestamps
result = transcribe_with_timestamps("lecture.mp3")
for segment in result.segments:
    print(f"[{segment['start']:.2f}] {segment['text']}")

# Translate audio to English
from aix import translate_audio

english_text = translate_audio("spanish_audio.mp3")
```

### 8. Video Generation (Coming Soon)

Video generation with provider-specific implementations:

<!-- wads-docs: skip video providers are not configured by default (raises NotImplementedError) -->
```python
from aix import generate_video, get_video_providers

# Check available providers
providers = get_video_providers()
print(providers)  # ['runway', 'pika', ...]

# Generate video (requires provider setup)
video = generate_video(
    "A cat walking through a garden", duration=5, resolution="1920x1080"
)
video.save("cat_video.mp4")

# Animate static image
from aix import animate_image_to_video

video = animate_image_to_video(
    "landscape.jpg", prompt="Gentle camera pan across the scene"
)
```

**Note**: Video generation requires additional provider setup (Runway, Pika, etc.) and API keys.

## OpenRouter Integration

[OpenRouter](https://openrouter.ai) provides a single API key for 400+ models from 60+ providers. This is recommended for:

- **Getting started quickly** - One key vs. managing many
- **Experimenting** - Easy access to models from OpenAI, Anthropic, Google, etc.
- **Production flexibility** - Switch providers without code changes

### Setup

1. Get API key from https://openrouter.ai
2. Set environment variable:
   ```bash
   export OPENROUTER_API_KEY=your-key-here
   ```
3. Use OpenRouter models:
   <!-- wads-docs: skip needs an OpenRouter API key; indented list fence -->
   ```python
   # Prefix models with 'openrouter/'
   chat("Hello", model="openrouter/openai/gpt-4o")
   chat("Hello", model="openrouter/anthropic/claude-3.5-sonnet")

   # Discover available models
   models.discover("openrouter")
   ```

All standard AIX features work with OpenRouter models.

## Architecture

AIX follows the **i2mint philosophy** of clean, functional interfaces:

- **Mapping interfaces** for collections (models, registries)
- **Functional approach** over verbose OOP
- **Lazy evaluation** via generators where appropriate
- **Protocol-based design** for flexibility

### Backend: LiteLLM

AIX uses [LiteLLM](https://github.com/BerriAI/litellm) as the backend for provider interactions, but wraps it in clean, pythonic interfaces. Users never need to interact with LiteLLM directly.

**Supported Providers** (via LiteLLM):

- OpenAI
- Anthropic (Claude)
- Google (Gemini)
- Mistral
- Cohere
- And 100+ more

#### `import aix` does not touch the network

LiteLLM fetches its model-cost map over HTTPS **as a side effect of being
imported**. `aix` therefore resolves LiteLLM on the *first call* rather than at
import time, so importing `aix` (or any of its submodules) opens no outbound
connection: a server cold start doesn’t block on it, an offline or
restricted-egress deployment doesn’t eat a connect timeout, and a test suite
that merely imports `aix` stays hermetic. The first actual provider call pays
the import, and gets the live cost map — so provider resolution is unaffected.

If you also want the *first call* to stay offline, set LiteLLM’s own knob in
your environment. `aix` deliberately never sets it for you — it is a
whole-process setting, so the choice is the operator’s:

```bash
export LITELLM_LOCAL_MODEL_COST_MAP=1
```

The trade-off: LiteLLM then reads the cost map bundled in its wheel, which is a
snapshot. Bare model names newer than your installed `litellm` release may stop
resolving — pass those provider-prefixed (`"openai/gpt-5.2"` rather than
`"gpt-5.2"`), which works either way.

## Design Patterns

### From `oa` (OpenAI facade)

AIX builds on patterns from the `oa` package:OpenRouter

- Simple chat interface with smart defaults
- Template-based function creation
- Structured output support
- Batch processing capabilities

### From `i2` (Signature manipulation)

- Clean function signatures
- Flexible parameter handling
- Decorator-based composition

### From `dol` (Storage abstraction)

- Mapping-based interfaces
- Persistent storage options
- Cache management

## Advanced Usage

### Custom Model Sources

<!-- wads-docs: skip needs network access (OpenRouter discovery) -->
```python
from aix.ai_models import ModelManager, OpenRouterSource

manager = ModelManager()
source = OpenRouterSource()
manager.register_source("openrouter", source)
models = manager.discover_from_source("openrouter")
```

### Connector-Specific Metadata

<!-- wads-docs: skip fragment; models comes from the discovery example above -->
```python
# Get provider-specific parameters
metadata = models.get_connector_metadata("openai/gpt-4o", "openai")
# Use with native SDK: openai.ChatCompletion.create(**metadata, messages=[...])
```

### Error Handling

```python
from aix import chat

try:
    response = chat("Hello", model="nonexistent-model")
except Exception as e:
    print(f"Error: {e}")
```

## Backward Compatibility

The legacy `chat_funcs` and `chat_models` interfaces are still available:

```python
from aix import chat_funcs, chat_models

# Old style (still works)
list(chat_funcs)  # ['gpt-4o', 'gpt-4o-mini', ...]
response = chat_funcs.gpt_4o("Hello")

# Model metadata
info = chat_models["gpt-4o"]
# {'price_per_million_tokens': 5.0, 'provider': 'openai', ...}
```

However, the new interfaces (`chat`, `embeddings`, `prompt_func`, `models`) are recommended for new code.

## Examples

### Semantic Search

<!-- wads-docs: skip needs a provider API key -->
```python
from aix import embed, cosine_similarity

# Build document index
docs = ["AI is the future", "Python is great", "Machine learning works"]
doc_vecs = [embed(doc) for doc in docs]

# Search
query_vec = embed("artificial intelligence")
similarities = [cosine_similarity(query_vec, dv) for dv in doc_vecs]
best_match = docs[similarities.index(max(similarities))]
print(best_match)  # "AI is the future"
```

### Data Extraction Pipeline

```python
from aix import prompt_func, batch_process

# Define extraction function
extract = prompt_func(
    "Extract product info from: {text}",
    output_schema={"name": str, "price": float, "category": str},
)

# Process many product descriptions
descriptions = [...]  # Your data
results = list(
    batch_process(
        descriptions, lambda d: extract(text=d), batch_size=10, show_progress=True
    )
)
```

### Multi-Model Comparison

<!-- wads-docs: skip needs a provider API key -->
```python
from aix import chat

prompt = "Explain quantum computing in one sentence"

# Try different models
for model_id in ["gpt-4o-mini", "claude-sonnet-4", "gemini-1.5-flash"]:
    response = chat(prompt, model=model_id)
    print(f"{model_id}: {response}")
```

## Documentation

- **API Reference**: See docstrings in each module
- **Examples**: Check `examples/` directory
- **GitHub**: https://github.com/thorwhalen/aix

## Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

## License

Apache 2.0

## Credits

Built with:

- [LiteLLM](https://github.com/BerriAI/litellm) - Multi-provider backend
- [i2](https://github.com/i2mint/i2) - Signature manipulation utilities
- [dol](https://github.com/i2mint/dol) - Storage abstraction patterns
- [oa](https://github.com/thorwhalen/oa) - OpenAI facade inspiration

## What AIX is NOT

AIX is NOT an AI agent framework. For that, see the separate `aw` package. AIX focuses on foundational AI operations (chat, embeddings, etc.) that can be used to build agents and other applications.

<p class="epythet-aggregates">This documentation as a single file: <a href="aix.md">aix.md</a> (Markdown, for agents).</p>


# _autosummary/aix.ai_models.base.html.md

# aix.ai_models.base

Core types for AI model management.

This module provides a unified interface for managing, discovering, and
connecting to AI models across multiple providers and deployment methods.

### Classes

| [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)()                              | Abstract base for model connectors/clients.              |
|-------------------------------------------------------------------------------------------|----------------------------------------------------------|
| [`ConnectorRegistry`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ConnectorRegistry)()                      | Registry for managing model connectors.                  |
| [`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)(id, provider[, context_size, ...]) | Represents an AI model with its metadata.                |
| [`ModelRegistry`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelRegistry)(\*[, storage_path])        | Registry for managing AI models using Mapping interface. |
| [`ModelSource`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelSource)()                            | Abstract base for model discovery sources.               |

### *class* aix.ai_models.base.Connector

Bases: [`ABC`](https://docs.python.org/3/library/abc.html#abc.ABC)

Abstract base for model connectors/clients.

#### *abstractmethod* format_metadata(model)

Format model metadata for this connector.

Returns a dict that can be used to instantiate/connect via this connector.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *abstract property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.base.ConnectorRegistry

Bases: [`MutableMapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableMapping)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)]

Registry for managing model connectors.

```pycon
>>> registry = ConnectorRegistry()
>>> class MyConnector(Connector):
...     @property
...     def name(self) -> str:
...         return "my_connector"
...     def format_metadata(self, model: Model) -> dict[str, Any]:
...         return {"model": model.id}
>>> connector = MyConnector()
>>> registry[connector.name] = connector
>>> "my_connector" in registry
True
```

### *class* aix.ai_models.base.Model(id, provider, context_size=None, is_local=False, capabilities=dict(), cost_per_token=dict(), tags=set(), connector_metadata=dict(), custom_metadata=dict())

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Represents an AI model with its metadata.

```pycon
>>> model = Model(
...     id="gpt-4",
...     provider="openai",
...     context_size=8192,
...     is_local=False
... )
>>> model.id
'gpt-4'
```

#### matches_filter(\*\*criteria)

Check if model matches given criteria.

```pycon
>>> model = Model(id="gpt-4", provider="openai", is_local=False)
>>> model.matches_filter(provider="openai")
True
>>> model.matches_filter(is_local=True)
False
```

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### to_dict()

Convert model to dictionary representation.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

### *class* aix.ai_models.base.ModelRegistry(, storage_path=None)

Bases: [`MutableMapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableMapping)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

Registry for managing AI models using Mapping interface.

```pycon
>>> registry = ModelRegistry()
>>> registry["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> "gpt-4" in registry
True
>>> len(registry)
1
```

#### filter(, provider=None, is_local=None, min_context_size=None, max_context_size=None, has_capabilities=None, tags=None, custom_filter=None)

Filter models by multiple criteria.

```pycon
>>> registry = ModelRegistry()
>>> registry["gpt-4"] = Model(id="gpt-4", provider="openai", context_size=8192)
>>> registry["llama2"] = Model(id="llama2", provider="ollama", is_local=True)
>>> local_models = registry.filter(is_local=True)
>>> len(local_models)
1
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

### *class* aix.ai_models.base.ModelSource

Bases: [`ABC`](https://docs.python.org/3/library/abc.html#abc.ABC)

Abstract base for model discovery sources.

#### *abstractmethod* discover_models()

Discover available models from this source.

Yields Model instances for each discovered model.

* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]


# _autosummary/aix.ai_models.html.md

# aix.ai_models

AI Model Management Module.

A unified interface for managing AI models across multiple providers.

Basic usage:

```pycon
>>> from aix.ai_models import get_manager
>>> manager = get_manager()
>>> _ = manager.discover_from_source("openrouter", auto_register=True, verbose=False)
>>> models = manager.list_models(provider="openai")
```

Custom filtering:

```pycon
>>> cheap_models = manager.list_models(
...     custom_filter=lambda m: m.cost_per_token.get("input", 0) < 0.001
... )
```

Get connector-specific metadata:

```pycon
>>> openai_meta = manager.get_connector_metadata("openai/gpt-4", "openai")
>>> # Use with: openai.ChatCompletion.create(**openai_meta, messages=[...])
```

### Functions

| [`get_manager`](_autosummary/aix.ai_models.html.md#aix.ai_models.get_manager)([storage_path])   | Get a pre-configured model manager.   |
|--------------------------------------------------------------------------------|---------------------------------------|

### Classes

| [`Model`](_autosummary/aix.ai_models.html.md#aix.ai_models.Model)(id, provider[, context_size, ...])    | Represents an AI model with its metadata.                        |
|----------------------------------------------------------------------------------------------|------------------------------------------------------------------|
| [`ModelRegistry`](_autosummary/aix.ai_models.html.md#aix.ai_models.ModelRegistry)(\*[, storage_path])           | Registry for managing AI models using Mapping interface.         |
| [`ModelSource`](_autosummary/aix.ai_models.html.md#aix.ai_models.ModelSource)()                               | Abstract base for model discovery sources.                       |
| [`Connector`](_autosummary/aix.ai_models.html.md#aix.ai_models.Connector)()                                 | Abstract base for model connectors/clients.                      |
| [`ConnectorRegistry`](_autosummary/aix.ai_models.html.md#aix.ai_models.ConnectorRegistry)()                         | Registry for managing model connectors.                          |
| [`OpenRouterSource`](_autosummary/aix.ai_models.html.md#aix.ai_models.OpenRouterSource)(\*[, timeout])             | Discover models from OpenRouter's public API.                    |
| [`OllamaSource`](_autosummary/aix.ai_models.html.md#aix.ai_models.OllamaSource)(\*[, base_url, timeout])       | Discover locally installed Ollama models.                        |
| [`ProviderAPISource`](_autosummary/aix.ai_models.html.md#aix.ai_models.ProviderAPISource)(provider_name, \*[, ...]) | Discover models from a provider's API (OpenAI, Anthropic, etc.). |
| [`OpenAIConnector`](_autosummary/aix.ai_models.html.md#aix.ai_models.OpenAIConnector)()                           | Format metadata for OpenAI Python client.                        |
| [`OpenRouterConnector`](_autosummary/aix.ai_models.html.md#aix.ai_models.OpenRouterConnector)()                       | Connector for OpenRouter API.                                    |
| [`LangChainConnector`](_autosummary/aix.ai_models.html.md#aix.ai_models.LangChainConnector)()                        | Connector for LangChain library.                                 |
| [`OllamaConnector`](_autosummary/aix.ai_models.html.md#aix.ai_models.OllamaConnector)()                           | Format metadata for direct Ollama API calls.                     |
| [`DSPyConnector`](_autosummary/aix.ai_models.html.md#aix.ai_models.DSPyConnector)()                             | Format metadata for DSPy framework.                              |
| [`ModelManager`](_autosummary/aix.ai_models.html.md#aix.ai_models.ModelManager)(\*[, storage_path])            | Unified interface for AI model management.                       |

### *class* aix.ai_models.Connector

Bases: [`ABC`](https://docs.python.org/3/library/abc.html#abc.ABC)

Abstract base for model connectors/clients.

#### *abstractmethod* format_metadata(model)

Format model metadata for this connector.

Returns a dict that can be used to instantiate/connect via this connector.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *abstract property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.ConnectorRegistry

Bases: [`MutableMapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableMapping)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)]

Registry for managing model connectors.

```pycon
>>> registry = ConnectorRegistry()
>>> class MyConnector(Connector):
...     @property
...     def name(self) -> str:
...         return "my_connector"
...     def format_metadata(self, model: Model) -> dict[str, Any]:
...         return {"model": model.id}
>>> connector = MyConnector()
>>> registry[connector.name] = connector
>>> "my_connector" in registry
True
```

### *class* aix.ai_models.DSPyConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Format metadata for DSPy framework.

#### format_metadata(model)

Format for DSPy.

```pycon
>>> connector = DSPyConnector()
>>> model = Model(id="gpt-4", provider="openai")
>>> metadata = connector.format_metadata(model)
>>> "model" in metadata
True
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.LangChainConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Connector for LangChain library.

#### format_metadata(model)

Format for LangChain.

```pycon
>>> connector = LangChainConnector()
>>> model = Model(id="gpt-4", provider="openai")
>>> metadata = connector.format_metadata(model)
>>> metadata["model_name"]
'gpt-4'
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.Model(id, provider, context_size=None, is_local=False, capabilities=dict(), cost_per_token=dict(), tags=set(), connector_metadata=dict(), custom_metadata=dict())

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Represents an AI model with its metadata.

```pycon
>>> model = Model(
...     id="gpt-4",
...     provider="openai",
...     context_size=8192,
...     is_local=False
... )
>>> model.id
'gpt-4'
```

#### matches_filter(\*\*criteria)

Check if model matches given criteria.

```pycon
>>> model = Model(id="gpt-4", provider="openai", is_local=False)
>>> model.matches_filter(provider="openai")
True
>>> model.matches_filter(is_local=True)
False
```

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### to_dict()

Convert model to dictionary representation.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

### *class* aix.ai_models.ModelManager(, storage_path=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Unified interface for AI model management.

Combines model registry, sources, and connectors into a single facade.

```pycon
>>> manager = ModelManager()
>>> manager.register_connector(OpenAIConnector())
>>> len(manager.connectors)
1
```

#### add_model_tag(model_id, \*tags)

Add tags to a model.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.add_model_tag("gpt-4", "fast", "expensive")
>>> "fast" in manager.models["gpt-4"].tags
True
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### *property* connectors *: [ConnectorRegistry](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ConnectorRegistry)*

Access to connector registry.

#### create_model_group(group_name, model_ids)

Create a named group of models using tags.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.models["claude-3"] = Model(id="claude-3", provider="anthropic")
>>> manager.create_model_group("premium", ["gpt-4", "claude-3"])
>>> premium = manager.list_models(tags=["group:premium"])
>>> len(premium)
2
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### discover_all(, auto_register=True)

Discover models from all registered sources.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]]
* **Returns:**
  Dict mapping source name to list of discovered models

#### discover_from_source(source_name, , auto_register=True, verbose=True)

Discover models from a registered source.

* **Parameters:**
  * **source_name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name of registered source
  * **auto_register** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, automatically add discovered models to registry
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of discovered models

#### get_connector_metadata(model_id, connector_name)

Get formatted metadata for a specific connector.

* **Parameters:**
  * **model_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – ID of the model
  * **connector_name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name of the connector to format for
* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]
* **Returns:**
  Dict with metadata formatted for the specified connector

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.register_connector(OpenAIConnector())
>>> meta = manager.get_connector_metadata("gpt-4", "openai")
>>> meta["model"]
'gpt-4'
```

#### get_model(model_id)

Get a specific model by ID.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> model = manager.get_model("gpt-4")
>>> model.id
'gpt-4'
```

* **Return type:**
  [`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)

#### list_model_groups()

List all model groups.

* **Returns:**
  ‘ prefix)
* **Return type:**
  [`set`](https://docs.python.org/3/builtins/stdtypes.html#set)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### list_models(, provider=None, is_local=None, min_context_size=None, max_context_size=None, has_capabilities=None, tags=None, custom_filter=None)

List models with optional filtering.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.models["llama2"] = Model(id="llama2", provider="ollama", is_local=True)
>>> local = manager.list_models(is_local=True)
>>> len(local)
1
>>> local[0].id
'llama2'
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

#### list_sources()

List registered source names.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### *property* models *: [ModelRegistry](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelRegistry)*

Access to model registry for direct manipulation.

```pycon
>>> manager = ModelManager()
>>> manager.models["test"] = Model(id="test", provider="test")
>>> "test" in manager.models
True
```

#### register_connector(connector)

Register a model connector.

```pycon
>>> manager = ModelManager()
>>> connector = OpenAIConnector()
>>> manager.register_connector(connector)
>>> connector.name in manager.connectors
True
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### register_source(name, source)

Register a model discovery source.

```pycon
>>> manager = ModelManager()
>>> source = OpenRouterSource()
>>> manager.register_source("openrouter", source)
>>> "openrouter" in manager.list_sources()
True
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### set_custom_metadata(model_id, key, value)

Set custom metadata on a model.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.set_custom_metadata("gpt-4", "my_note", "Use for production")
>>> manager.models["gpt-4"].custom_metadata["my_note"]
'Use for production'
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* aix.ai_models.ModelRegistry(, storage_path=None)

Bases: [`MutableMapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.MutableMapping)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

Registry for managing AI models using Mapping interface.

```pycon
>>> registry = ModelRegistry()
>>> registry["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> "gpt-4" in registry
True
>>> len(registry)
1
```

#### filter(, provider=None, is_local=None, min_context_size=None, max_context_size=None, has_capabilities=None, tags=None, custom_filter=None)

Filter models by multiple criteria.

```pycon
>>> registry = ModelRegistry()
>>> registry["gpt-4"] = Model(id="gpt-4", provider="openai", context_size=8192)
>>> registry["llama2"] = Model(id="llama2", provider="ollama", is_local=True)
>>> local_models = registry.filter(is_local=True)
>>> len(local_models)
1
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

### *class* aix.ai_models.ModelSource

Bases: [`ABC`](https://docs.python.org/3/library/abc.html#abc.ABC)

Abstract base for model discovery sources.

#### *abstractmethod* discover_models()

Discover available models from this source.

Yields Model instances for each discovered model.

* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

### *class* aix.ai_models.OllamaConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Format metadata for direct Ollama API calls.

#### format_metadata(model)

Format for Ollama API.

```pycon
>>> connector = OllamaConnector()
>>> model = Model(id="ollama/llama2", provider="ollama", is_local=True)
>>> model.connector_metadata["ollama"] = {"name": "llama2"}
>>> metadata = connector.format_metadata(model)
>>> metadata["model"]
'llama2'
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.OllamaSource(, base_url='http://localhost:11434', timeout=10)

Bases: [`ModelSource`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelSource)

Discover locally installed Ollama models.

Queries the Ollama API for models available on the local machine.

#### discover_models()

Fetch locally installed Ollama models.

```pycon
>>> source = OllamaSource()
>>> models = list(source.discover_models())  # May be empty if Ollama not running
>>> all(m.is_local for m in models)
True
```

* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

### *class* aix.ai_models.OpenAIConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Format metadata for OpenAI Python client.

Provides model metadata in format expected by openai.ChatCompletion.create().

#### format_metadata(model)

Format model metadata for this connector.

Returns a dict that can be used to instantiate/connect via this connector.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.OpenRouterConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Connector for OpenRouter API.

#### format_metadata(model)

Formats metadata for OpenRouter, which uses the model ID directly.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.OpenRouterSource(, timeout=30)

Bases: [`ModelSource`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelSource)

Discover models from OpenRouter’s public API.

OpenRouter maintains a comprehensive registry of models across providers.

#### discover_models()

Fetch models from OpenRouter API.

```pycon
>>> source = OpenRouterSource()
>>> models = list(source.discover_models())
>>> len(models) > 0  # Should find many models
True
```

* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

### *class* aix.ai_models.ProviderAPISource(provider_name, , api_key=None, base_url='https://api.openai.com/v1', timeout=30)

Bases: [`ModelSource`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelSource)

Discover models from a provider’s API (OpenAI, Anthropic, etc.).

Generic source for providers with /v1/models endpoint.

#### discover_models()

Fetch models from provider API.

Requires valid API key for the provider.

* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

### aix.ai_models.get_manager(storage_path=None)

Get a pre-configured model manager.

```pycon
>>> manager = get_manager()
>>> len(manager.connectors) > 0
True
```

* **Return type:**
  [`ModelManager`](_autosummary/aix.ai_models.manager.html.md#aix.ai_models.manager.ModelManager)

### Modules

| [`base`](_autosummary/aix.ai_models.base.html.md#module-aix.ai_models.base)       | Core types for AI model management.                       |
|---------------------------------------------------------------------------------------|-----------------------------------------------------------|
| [`manager`](_autosummary/aix.ai_models.manager.html.md#module-aix.ai_models.manager) | Unified model management interface.                       |
| [`sources`](_autosummary/aix.ai_models.sources.html.md#module-aix.ai_models.sources) | Concrete implementations of model sources and connectors. |


# _autosummary/aix.ai_models.manager.html.md

# aix.ai_models.manager

Unified model management interface.

Provides a high-level API for managing AI models across providers.

### Functions

| [`get_manager`](_autosummary/aix.ai_models.manager.html.md#aix.ai_models.manager.get_manager)([storage_path])   | Get a pre-configured model manager.   |
|--------------------------------------------------------------------------------|---------------------------------------|

### Classes

| [`ModelManager`](_autosummary/aix.ai_models.manager.html.md#aix.ai_models.manager.ModelManager)(\*[, storage_path])   | Unified interface for AI model management.   |
|-------------------------------------------------------------------------------------|----------------------------------------------|

### *class* aix.ai_models.manager.ModelManager(, storage_path=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Unified interface for AI model management.

Combines model registry, sources, and connectors into a single facade.

```pycon
>>> manager = ModelManager()
>>> manager.register_connector(OpenAIConnector())
>>> len(manager.connectors)
1
```

#### add_model_tag(model_id, \*tags)

Add tags to a model.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.add_model_tag("gpt-4", "fast", "expensive")
>>> "fast" in manager.models["gpt-4"].tags
True
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### *property* connectors *: [ConnectorRegistry](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ConnectorRegistry)*

Access to connector registry.

#### create_model_group(group_name, model_ids)

Create a named group of models using tags.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.models["claude-3"] = Model(id="claude-3", provider="anthropic")
>>> manager.create_model_group("premium", ["gpt-4", "claude-3"])
>>> premium = manager.list_models(tags=["group:premium"])
>>> len(premium)
2
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### discover_all(, auto_register=True)

Discover models from all registered sources.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]]
* **Returns:**
  Dict mapping source name to list of discovered models

#### discover_from_source(source_name, , auto_register=True, verbose=True)

Discover models from a registered source.

* **Parameters:**
  * **source_name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name of registered source
  * **auto_register** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, automatically add discovered models to registry
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of discovered models

#### get_connector_metadata(model_id, connector_name)

Get formatted metadata for a specific connector.

* **Parameters:**
  * **model_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – ID of the model
  * **connector_name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Name of the connector to format for
* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]
* **Returns:**
  Dict with metadata formatted for the specified connector

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.register_connector(OpenAIConnector())
>>> meta = manager.get_connector_metadata("gpt-4", "openai")
>>> meta["model"]
'gpt-4'
```

#### get_model(model_id)

Get a specific model by ID.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> model = manager.get_model("gpt-4")
>>> model.id
'gpt-4'
```

* **Return type:**
  [`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)

#### list_model_groups()

List all model groups.

* **Returns:**
  ‘ prefix)
* **Return type:**
  [`set`](https://docs.python.org/3/builtins/stdtypes.html#set)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### list_models(, provider=None, is_local=None, min_context_size=None, max_context_size=None, has_capabilities=None, tags=None, custom_filter=None)

List models with optional filtering.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.models["llama2"] = Model(id="llama2", provider="ollama", is_local=True)
>>> local = manager.list_models(is_local=True)
>>> len(local)
1
>>> local[0].id
'llama2'
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

#### list_sources()

List registered source names.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### *property* models *: [ModelRegistry](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelRegistry)*

Access to model registry for direct manipulation.

```pycon
>>> manager = ModelManager()
>>> manager.models["test"] = Model(id="test", provider="test")
>>> "test" in manager.models
True
```

#### register_connector(connector)

Register a model connector.

```pycon
>>> manager = ModelManager()
>>> connector = OpenAIConnector()
>>> manager.register_connector(connector)
>>> connector.name in manager.connectors
True
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### register_source(name, source)

Register a model discovery source.

```pycon
>>> manager = ModelManager()
>>> source = OpenRouterSource()
>>> manager.register_source("openrouter", source)
>>> "openrouter" in manager.list_sources()
True
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### set_custom_metadata(model_id, key, value)

Set custom metadata on a model.

```pycon
>>> manager = ModelManager()
>>> manager.models["gpt-4"] = Model(id="gpt-4", provider="openai")
>>> manager.set_custom_metadata("gpt-4", "my_note", "Use for production")
>>> manager.models["gpt-4"].custom_metadata["my_note"]
'Use for production'
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### aix.ai_models.manager.get_manager(storage_path=None)

Get a pre-configured model manager.

```pycon
>>> manager = get_manager()
>>> len(manager.connectors) > 0
True
```

* **Return type:**
  [`ModelManager`](_autosummary/aix.ai_models.manager.html.md#aix.ai_models.manager.ModelManager)


# _autosummary/aix.ai_models.sources.html.md

# aix.ai_models.sources

Concrete implementations of model sources and connectors.

This module provides ready-to-use sources for discovering models
and connectors for formatting metadata for different clients.

### Classes

| [`DSPyConnector`](_autosummary/aix.ai_models.sources.html.md#aix.ai_models.sources.DSPyConnector)()                             | Format metadata for DSPy framework.                              |
|----------------------------------------------------------------------------------------------|------------------------------------------------------------------|
| [`LangChainConnector`](_autosummary/aix.ai_models.sources.html.md#aix.ai_models.sources.LangChainConnector)()                        | Connector for LangChain library.                                 |
| [`OllamaConnector`](_autosummary/aix.ai_models.sources.html.md#aix.ai_models.sources.OllamaConnector)()                           | Format metadata for direct Ollama API calls.                     |
| [`OllamaSource`](_autosummary/aix.ai_models.sources.html.md#aix.ai_models.sources.OllamaSource)(\*[, base_url, timeout])       | Discover locally installed Ollama models.                        |
| [`OpenAIConnector`](_autosummary/aix.ai_models.sources.html.md#aix.ai_models.sources.OpenAIConnector)()                           | Format metadata for OpenAI Python client.                        |
| [`OpenRouterConnector`](_autosummary/aix.ai_models.sources.html.md#aix.ai_models.sources.OpenRouterConnector)()                       | Connector for OpenRouter API.                                    |
| [`OpenRouterSource`](_autosummary/aix.ai_models.sources.html.md#aix.ai_models.sources.OpenRouterSource)(\*[, timeout])             | Discover models from OpenRouter's public API.                    |
| [`ProviderAPISource`](_autosummary/aix.ai_models.sources.html.md#aix.ai_models.sources.ProviderAPISource)(provider_name, \*[, ...]) | Discover models from a provider's API (OpenAI, Anthropic, etc.). |

### *class* aix.ai_models.sources.DSPyConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Format metadata for DSPy framework.

#### format_metadata(model)

Format for DSPy.

```pycon
>>> connector = DSPyConnector()
>>> model = Model(id="gpt-4", provider="openai")
>>> metadata = connector.format_metadata(model)
>>> "model" in metadata
True
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.sources.LangChainConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Connector for LangChain library.

#### format_metadata(model)

Format for LangChain.

```pycon
>>> connector = LangChainConnector()
>>> model = Model(id="gpt-4", provider="openai")
>>> metadata = connector.format_metadata(model)
>>> metadata["model_name"]
'gpt-4'
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.sources.OllamaConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Format metadata for direct Ollama API calls.

#### format_metadata(model)

Format for Ollama API.

```pycon
>>> connector = OllamaConnector()
>>> model = Model(id="ollama/llama2", provider="ollama", is_local=True)
>>> model.connector_metadata["ollama"] = {"name": "llama2"}
>>> metadata = connector.format_metadata(model)
>>> metadata["model"]
'llama2'
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.sources.OllamaSource(, base_url='http://localhost:11434', timeout=10)

Bases: [`ModelSource`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelSource)

Discover locally installed Ollama models.

Queries the Ollama API for models available on the local machine.

#### discover_models()

Fetch locally installed Ollama models.

```pycon
>>> source = OllamaSource()
>>> models = list(source.discover_models())  # May be empty if Ollama not running
>>> all(m.is_local for m in models)
True
```

* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

### *class* aix.ai_models.sources.OpenAIConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Format metadata for OpenAI Python client.

Provides model metadata in format expected by openai.ChatCompletion.create().

#### format_metadata(model)

Format model metadata for this connector.

Returns a dict that can be used to instantiate/connect via this connector.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.sources.OpenRouterConnector

Bases: [`Connector`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Connector)

Connector for OpenRouter API.

#### format_metadata(model)

Formats metadata for OpenRouter, which uses the model ID directly.

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

#### *property* name *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

Unique identifier for this connector.

### *class* aix.ai_models.sources.OpenRouterSource(, timeout=30)

Bases: [`ModelSource`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelSource)

Discover models from OpenRouter’s public API.

OpenRouter maintains a comprehensive registry of models across providers.

#### discover_models()

Fetch models from OpenRouter API.

```pycon
>>> source = OpenRouterSource()
>>> models = list(source.discover_models())
>>> len(models) > 0  # Should find many models
True
```

* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]

### *class* aix.ai_models.sources.ProviderAPISource(provider_name, , api_key=None, base_url='https://api.openai.com/v1', timeout=30)

Bases: [`ModelSource`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.ModelSource)

Discover models from a provider’s API (OpenAI, Anthropic, etc.).

Generic source for providers with /v1/models endpoint.

#### discover_models()

Fetch models from provider API.

Requires valid API key for the provider.

* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]


# _autosummary/aix.audio.html.md

# aix.audio

Audio operations interface for AIX.

Provides text-to-speech (TTS) and speech-to-text (transcription) capabilities.

### Examples

Text to speech:

```pycon
>>> from aix.audio import text_to_speech
>>> audio = text_to_speech("Hello, world!")
>>> audio.save("hello.mp3")
```

Transcription:

```pycon
>>> from aix.audio import transcribe
>>> text = transcribe("speech.mp3")
>>> print(text)
'Hello, this is a test recording.'
```

### Functions

| [`text_to_speech`](_autosummary/aix.audio.html.md#aix.audio.text_to_speech)(text, \*[, model, voice, ...])    | Convert text to speech audio.                 |
|---------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [`transcribe`](_autosummary/aix.audio.html.md#aix.audio.transcribe)(audio, \*[, engine, model, ...])      | Transcribe audio to text.                     |
| [`transcribe_with_timestamps`](_autosummary/aix.audio.html.md#aix.audio.transcribe_with_timestamps)(audio, \*[, ...])     | Transcribe audio with detailed timestamps.    |
| [`translate_audio`](_autosummary/aix.audio.html.md#aix.audio.translate_audio)(audio, \*[, model, prompt, ...]) | Translate audio from any language to English. |

### Classes

| [`GeneratedAudio`](_autosummary/aix.audio.html.md#aix.audio.GeneratedAudio)(data[, model, text, voice, ...])   | Wrapper for generated audio.   |
|----------------------------------------------------------------------------------------------------|--------------------------------|
| [`TranscriptionResult`](_autosummary/aix.audio.html.md#aix.audio.TranscriptionResult)(text[, language, ...])        | Result of audio transcription. |

### *class* aix.audio.GeneratedAudio(data, model=None, text=None, voice=None, format='mp3')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Wrapper for generated audio.

Provides convenient access to audio data and saving.

### Examples

```pycon
>>> audio = GeneratedAudio(data=b'...', model="tts-1")
>>> audio.save("output.mp3")
>>> data = audio.as_bytes()
```

#### as_bytes()

Get audio as bytes.

* **Return type:**
  [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)
* **Returns:**
  Audio data as bytes

#### play()

Play the audio.

Requires a system audio player or library like pygame/pyaudio.

### Examples

```pycon
>>> audio.play()
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### save(path)

Save audio to file.

* **Parameters:**
  **path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Output file path
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### Examples

```pycon
>>> audio.save("output.mp3")
>>> audio.save("speech.wav")
```

### *class* aix.audio.TranscriptionResult(text, language=None, duration=None, segments=None, model=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Result of audio transcription.

Contains the transcribed text and optional metadata like segments and timestamps.

### Examples

```pycon
>>> result = TranscriptionResult(text="Hello world")
>>> print(result.text)
'Hello world'
```

### aix.audio.text_to_speech(text, , model=None, voice=None, speed=None, response_format='mp3', api_key=None, \*\*kwargs)

Convert text to speech audio.

* **Parameters:**
  * **text** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text to convert to speech
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – TTS model to use (e.g., ‘tts-1’, ‘tts-1-hd’)
  * **voice** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Voice to use (‘alloy’, ‘echo’, ‘fable’, ‘onyx’, ‘nova’, ‘shimmer’)
  * **speed** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Playback speed (0.25 to 4.0)
  * **response_format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Audio format (‘mp3’, ‘opus’, ‘aac’, ‘flac’)
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedAudio`](_autosummary/aix.audio.html.md#aix.audio.GeneratedAudio)
* **Returns:**
  GeneratedAudio object
* **Raises:**
  [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed

### Examples

```pycon
>>> from aix.audio import text_to_speech
>>> audio = text_to_speech("Hello, how are you?")
>>> audio.save("greeting.mp3")
```

```pycon
>>> # Different voice and speed
>>> audio = text_to_speech(
...     "This is a test.",
...     voice="nova",
...     speed=1.2
... )
```

```pycon
>>> # High quality
>>> audio = text_to_speech(
...     "Important announcement",
...     model="tts-1-hd",
...     voice="onyx"
... )
```

### aix.audio.transcribe(audio, , engine=None, model=None, language=None, prompt=None, response_format='text', temperature=None, timestamp_granularities=None, api_key=None, \*\*kwargs)

Transcribe audio to text.

By default this routes through LiteLLM (OpenAI-style transcription). Pass
`engine=` to instead delegate to a `scribed` backend — one façade over
many ASR engines (local Whisper / faster-whisper / vosk, or cloud Deepgram /
AssemblyAI / Groq / ElevenLabs / Google …) with speaker diarization and
SRT/VTT output. The return type is unchanged either way, so existing callers
are unaffected.

* **Parameters:**
  * **audio** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`BinaryIO`](https://docs.python.org/3/library/typing.html#typing.BinaryIO), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)]) – Audio file path, file object, or bytes.
  * **engine** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional `scribed` backend id (e.g. `"faster-whisper"`,
    `"deepgram"`). When given, transcription is delegated to scribed
    (which resolves that engine’s own credentials); the LiteLLM path is
    bypassed. Requires `pip install 'aix[scribed]'`. See
    `scribed.list_backends()`.
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Transcription model (e.g. `'whisper-1'`); for a scribed engine,
    the engine-specific model (e.g. a Whisper size).
  * **language** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Source language (ISO-639-1 code, e.g. `'en'`, `'es'`).
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional text to guide the model’s style (LiteLLM path).
  * **response_format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – `'text'` (default) → `str`; `'srt'`/`'vtt'` →
    subtitle `str` (scribed path); else → [`TranscriptionResult`](_autosummary/aix.audio.html.md#aix.audio.TranscriptionResult).
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Sampling temperature (LiteLLM path).
  * **timestamp_granularities** ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Timestamp types (‘word’, ‘segment’) (LiteLLM path).
  * **\*\*kwargs** – Additional parameters (forwarded to LiteLLM, or to the scribed
    backend — e.g. `diarize=True`).
* **Return type:**
  [`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`TranscriptionResult`](_autosummary/aix.audio.html.md#aix.audio.TranscriptionResult)]
* **Returns:**
  `str` for `response_format` in {text, srt, vtt}, else a
  [`TranscriptionResult`](_autosummary/aix.audio.html.md#aix.audio.TranscriptionResult).

### Examples

```pycon
>>> from aix.audio import transcribe
>>> text = transcribe("recording.mp3")
>>> # delegate to a scribed engine (local, free, diarized SRT):
>>> srt = transcribe(
...     "meeting.wav", engine="faster-whisper", response_format="srt"
... )
>>> dg = transcribe(
...     "call.mp3", engine="deepgram", diarize=True,
...     response_format="verbose_json",
... )
```

### aix.audio.transcribe_with_timestamps(audio, , granularity='segment', model=None, \*\*kwargs)

Transcribe audio with detailed timestamps.

* **Parameters:**
  * **audio** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`BinaryIO`](https://docs.python.org/3/library/typing.html#typing.BinaryIO), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)]) – Audio file path, file object, or bytes
  * **granularity** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Timestamp granularity (‘word’ or ‘segment’)
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Transcription model
  * **\*\*kwargs** – Additional parameters for transcribe()
* **Return type:**
  [`TranscriptionResult`](_autosummary/aix.audio.html.md#aix.audio.TranscriptionResult)
* **Returns:**
  TranscriptionResult with detailed segments

### Examples

```pycon
>>> from aix.audio import transcribe_with_timestamps
>>> result = transcribe_with_timestamps("lecture.mp3")
>>> for segment in result.segments:
...     start = segment['start']
...     end = segment['end']
...     text = segment['text']
...     print(f"[{start:.2f}-{end:.2f}] {text}")
```

### aix.audio.translate_audio(audio, , model=None, prompt=None, api_key=None, \*\*kwargs)

Translate audio from any language to English.

#### NOTE
Currently uses Whisper’s translation capability which translates to English.

* **Parameters:**
  * **audio** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`BinaryIO`](https://docs.python.org/3/library/typing.html#typing.BinaryIO), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)]) – Audio file path, file object, or bytes
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Translation model (typically ‘whisper-1’)
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional text to guide translation
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)
* **Returns:**
  Translated text in English

### Examples

```pycon
>>> from aix.audio import translate_audio
>>> english_text = translate_audio("spanish_audio.mp3")
>>> print(english_text)
'This is the English translation.'
```


# _autosummary/aix.batches.html.md

# aix.batches

Batch processing interface for AIX.

Efficiently process multiple prompts or embeddings in batches.

An item whose call raises does not stop the batch: its slot holds a
[`BatchError`](_autosummary/aix.batches.html.md#aix.batches.BatchError) – a `str` subclass equal to the `"ERROR: <message>"`
text these functions have always produced, but carrying the real exception so a
failure can be told apart from a model reply that happens to start “ERROR:”.
Pass `on_error='raise'` or `on_error='skip'` to opt out of that slot.

### Examples

Batch chat:

```pycon
>>> from aix.batches import batch_chat
>>> prompts = ["What is 2+2?", "What is 3+3?", "What is 4+4?"]
>>> results = list(batch_chat(prompts))
>>> len(results)
3
```

Batch embeddings:

```pycon
>>> from aix.batches import batch_embeddings
>>> texts = ["hello", "world", "foo", "bar"]
>>> vectors = list(batch_embeddings(texts))
>>> len(vectors)
4
```

### Functions

| [`batch_chat`](_autosummary/aix.batches.html.md#aix.batches.batch_chat)(prompts, \*[, model, batch_size, ...])   | Process multiple chat prompts in batches.                     |
|------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
| [`batch_embeddings`](_autosummary/aix.batches.html.md#aix.batches.batch_embeddings)(segments, \*[, model, ...])        | Generate embeddings for multiple texts in batches.            |
| [`batch_process`](_autosummary/aix.batches.html.md#aix.batches.batch_process)(items, process_func, \*[, ...])       | Generic batch processing with parallel execution and retries. |

### Classes

| [`BatchError`](_autosummary/aix.batches.html.md#aix.batches.BatchError)(exception, \*[, index, message])        | A batch result slot standing in for an item that raised.       |
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| [`BatchProcessor`](_autosummary/aix.batches.html.md#aix.batches.BatchProcessor)(\*[, batch_size, max_workers, ...]) | Stateful batch processor for managing long-running operations. |

### *class* aix.batches.BatchError(exception, , index=None, message=None)

Bases: [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

A batch result slot standing in for an item that raised.

Subclasses `str` so it *is* the `"ERROR: ..."` string these functions
have always put in the failed slot – comparisons, `.startswith`,
slicing, JSON serialisation and logging all behave identically. What it
adds is the ability to tell a failure apart from a model that legitimately
replied with text starting “ERROR:”, and to reach the original exception.

#### exception

The exception that was caught.

* **Type:**
  [`BaseException`](https://docs.python.org/3/builtins/exceptions.html#BaseException)

#### index

Position of the failed item in the input, when known.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

### Examples

```pycon
>>> err = BatchError(RuntimeError("rate limit exceeded"), index=1)
>>> err == "ERROR: rate limit exceeded"
True
>>> isinstance(err, str), isinstance(err.exception, RuntimeError)
(True, True)
>>> err.index
1
```

### *class* aix.batches.BatchProcessor(, batch_size=None, max_workers=None, show_progress=True)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Stateful batch processor for managing long-running operations.

Provides a higher-level interface for batch processing with
progress tracking, error handling, and result caching.

### Examples

```pycon
>>> processor = BatchProcessor(show_progress=True)
>>> results = processor.process_chats(prompts)
>>> processor.save_results("output.json")
```

#### clear()

Clear stored results and errors.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### process_chats(prompts, \*\*kwargs)

Process chat prompts and store results.

* **Parameters:**
  * **prompts** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]]]) – Prompts to process
  * **\*\*kwargs** – Additional parameters for batch_chat()
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]
* **Returns:**
  List of results

#### process_embeddings(texts, \*\*kwargs)

Process embeddings and store results.

* **Parameters:**
  * **texts** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Texts to embed
  * **\*\*kwargs** – Additional parameters for batch_embeddings()
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]]
* **Returns:**
  List of embedding vectors

#### save_results(filepath)

Save results to file.

* **Parameters:**
  **filepath** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Path to save results (JSON)
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### aix.batches.batch_chat(prompts, , model=None, batch_size=None, max_workers=None, show_progress=False, on_error='return', \*\*chat_kwargs)

Process multiple chat prompts in batches.

This function processes multiple prompts efficiently by:

1. Chunking prompts into batches
2. Processing batches in parallel where possible
3. Yielding results in the same order as input

* **Parameters:**
  * **prompts** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]]]) – Iterable of prompts (strings or message lists)
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use for all prompts
  * **batch_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of prompts to process in each batch
  * **max_workers** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum number of parallel workers
  * **show_progress** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, print progress information
  * **on_error** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'return'`, `'raise'`, `'skip'`]) – What to do with a prompt whose call raised.
    `'return'` (default) yields a `BatchError` in that slot, keeping
    the stream the same length and order as the input.
    `'raise'` stops after the batch in which the first failure landed
    and re-raises the lowest-indexed exception of that batch.
    `'skip'` omits the failed slots from the stream.
  * **\*\*chat_kwargs** – Additional parameters passed to chat()
* **Yields:**
  Responses in the same order as input prompts. A prompt that raised
  yields a `BatchError` – a `str` subclass equal to `"ERROR: <message>"`,
  carrying the original exception on `.exception`.
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `on_error` is not one of ‘return’, ‘raise’, ‘skip’.
* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### Examples

```pycon
>>> from aix.batches import batch_chat
>>> prompts = [
...     "What is 2+2?",
...     "What is 3+3?",
...     "What is 5+5?"
... ]
>>> results = list(batch_chat(prompts))
>>> len(results)
3
```

```pycon
>>> # With specific model
>>> results = list(batch_chat(
...     prompts,
...     model="gpt-4o-mini",
...     batch_size=5
... ))
```

```pycon
>>> # Process large dataset
>>> def generate_prompts():
...     for i in range(100):
...         yield f"Explain concept {i}"
>>> results = batch_chat(
...     generate_prompts(),
...     show_progress=True
... )
>>> for i, result in enumerate(results):
...     print(f"Result {i}: {result[:50]}...")
```

```pycon
>>> # Tell a failure apart from a reply that starts with "ERROR:"
>>> for result in batch_chat(prompts):
...     if isinstance(result, BatchError):
...         raise result.exception
```

### aix.batches.batch_embeddings(segments, , model=None, batch_size=None, show_progress=False, \*\*embedding_kwargs)

Generate embeddings for multiple texts in batches.

For efficiency, this function processes embeddings in chunks,
as most embedding APIs can handle multiple texts per request.

* **Parameters:**
  * **segments** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Iterable of text strings to embed
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Embedding model to use
  * **batch_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of texts per batch
  * **show_progress** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, print progress information
  * **\*\*embedding_kwargs** – Additional parameters for embeddings()
* **Yields:**
  Vector embeddings in the same order as input
* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]]

### Examples

```pycon
>>> from aix.batches import batch_embeddings
>>> texts = ["hello", "world", "foo", "bar"] * 25  # 100 texts
>>> vectors = list(batch_embeddings(
...     texts,
...     batch_size=10,
...     show_progress=True
... ))
>>> len(vectors)
100
```

```pycon
>>> # Process large dataset efficiently
>>> def read_documents():
...     # Generator that yields documents
...     for i in range(1000):
...         yield f"Document {i} content"
>>> all_vectors = []
>>> for vec in batch_embeddings(read_documents()):
...     all_vectors.append(vec)
```

### aix.batches.batch_process(items, process_func, , batch_size=None, max_workers=None, show_progress=False, retry_attempts=None, retry_delay=None, on_error='return')

Generic batch processing with parallel execution and retries.

This is a general-purpose batch processor that can be used for
any operation, not just chat or embeddings.

* **Parameters:**
  * **items** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – Items to process
  * **process_func** (`callable`) – Function to apply to each item
  * **batch_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Batch size for chunking
  * **max_workers** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum parallel workers
  * **show_progress** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Show progress information
  * **retry_attempts** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of retry attempts on failure
  * **retry_delay** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Delay between retries (seconds)
  * **on_error** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'return'`, `'raise'`, `'skip'`]) – What to do with an item still failing after every retry.
    `'return'` (default) yields a `BatchError` in that slot, `'raise'`
    re-raises, `'skip'` omits it. See [`batch_chat()`](_autosummary/aix.batches.html.md#aix.batches.batch_chat).
* **Yields:**
  Results in same order as input. An item that raised yields a
  `BatchError` – a `str` subclass equal to `"ERROR: <message>"`,
  carrying the original exception on `.exception`.
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `on_error` is not one of ‘return’, ‘raise’, ‘skip’.
* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

### Examples

```pycon
>>> from aix.batches import batch_process
>>> from aix.chat import chat
```

```pycon
>>> # Custom processing function
>>> def analyze_sentiment(text):
...     return chat(f"Analyze sentiment: {text}")
```

```pycon
>>> texts = ["I love this!", "This is terrible", "It's okay"]
>>> results = list(batch_process(
...     texts,
...     analyze_sentiment,
...     batch_size=5
... ))
```

```pycon
>>> # With retries for flaky operations
>>> def flaky_api_call(item):
...     # Some API that might fail
...     return call_api(item)
```

```pycon
>>> results = batch_process(
...     items,
...     flaky_api_call,
...     retry_attempts=3,
...     retry_delay=2.0
... )
```


# _autosummary/aix.calllog.html.md

# aix.calllog

An opt-in log of aix model calls: the resolved model, the caller, the outcome.

Off by default. Nothing is recorded unless a logger is installed, so a failing model
choice (a typo’d alias, a retired model, a missing key) can go unnoticed only when you
have not asked to see it. Three ways to turn it on, from narrowest to widest:

- per call, a keyword-only callback: `chat("hi", on_call=print)`;
- per process or block, `set_call_logger(fn)` / `with call_logger(fn): ...`;
- from the environment, `AIX_CALL_LOG=/path/to/calls.jsonl` writes one JSON line per
  call with [`jsonl_logger()`](_autosummary/aix.calllog.html.md#aix.calllog.jsonl_logger) (the prompt and the reply are never recorded).

A logger is any `fn(record: CallRecord) -> None`. It runs after the call, and an
exception inside it is swallowed so logging can never break a model call.

```pycon
>>> seen = []
>>> with call_logger(seen.append):
...     with _record("chat", "gpt-x", None):
...         pass
>>> seen[0].function, seen[0].model, seen[0].ok
('chat', 'gpt-x', True)
```

### Module Attributes

| [`ENV_VAR`](_autosummary/aix.calllog.html.md#aix.calllog.ENV_VAR)   | Environment variable holding the path of a JSON-lines file; setting it enables logging.   |
|------------------------------------------------------------|-------------------------------------------------------------------------------------------|

### Functions

| [`set_call_logger`](_autosummary/aix.calllog.html.md#aix.calllog.set_call_logger)(logger)   | Install `logger` for this context (`None` turns logging off).   |
|----------------------------------------------------------------------------|-----------------------------------------------------------------|
| [`call_logger`](_autosummary/aix.calllog.html.md#aix.calllog.call_logger)(logger)       | Log calls made inside the `with` block to `logger`.             |
| [`jsonl_logger`](_autosummary/aix.calllog.html.md#aix.calllog.jsonl_logger)(path)        | A logger that appends one JSON line per call to `path`.         |

### Classes

| [`CallRecord`](_autosummary/aix.calllog.html.md#aix.calllog.CallRecord)(function, model, caller, ok, seconds)   | One aix call: which function, the model it resolved to, who called, how it ended.   |
|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|

### *class* aix.calllog.CallRecord(function, model, caller, ok, seconds, error=None, time=0.0)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One aix call: which function, the model it resolved to, who called, how it ended.

### aix.calllog.ENV_VAR *= 'AIX_CALL_LOG'*

Environment variable holding the path of a JSON-lines file; setting it enables logging.

### aix.calllog.call_logger(logger)

Log calls made inside the `with` block to `logger`.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterator)[[`None`](https://docs.python.org/3/builtins/constants.html#None)]

### aix.calllog.jsonl_logger(path)

A logger that appends one JSON line per call to `path`.

* **Return type:**
  [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[`CallRecord`](_autosummary/aix.calllog.html.md#aix.calllog.CallRecord)], [`None`](https://docs.python.org/3/builtins/constants.html#None)]

### aix.calllog.set_call_logger(logger)

Install `logger` for this context (`None` turns logging off).

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)


# _autosummary/aix.capabilities.html.md

# aix.capabilities

What a model supports, asked before calling it.

Providers differ in which OpenAI-style parameters they honour (`n`, `seed`,
`response_format`…). LiteLLM knows, per model, through
`get_supported_openai_params`; this module puts a small, total (never
raising) question in front of it, so callers can *choose* a degraded path
rather than discover one silently.

Besides request parameter names, [`supports()`](_autosummary/aix.capabilities.html.md#aix.capabilities.supports) answers a few *capabilities*
that are not a single parameter (see [`CAPABILITIES`](_autosummary/aix.capabilities.html.md#aix.capabilities.CAPABILITIES)), e.g.
`"response_schema"`: whether the model takes a JSON-Schema-constrained
`response_format` (what `aix.complete(..., response_schema=...)` uses for
its `"strict"` / `"schema"` modes).

Why ask about `seed` in particular: a run-to-run difference with a seed the
provider *ignored* means nothing about model stability. `supports(model,
"seed") is False` rules a seed out; `True` only says LiteLLM forwards it –
seeded sampling is best-effort on every provider, and a router may drop it
upstream (compare
[`aix.Completion.system_fingerprint`](_autosummary/aix.html.md#aix.Completion.system_fingerprint) across runs: a change means the
serving backend changed, which voids the comparison).

```pycon
>>> supports("gpt-4o-mini", "n")
True
>>> supports("anthropic/claude-sonnet-4-20250514", "n")
False
```

### Module Attributes

| [`CAPABILITIES`](_autosummary/aix.capabilities.html.md#aix.capabilities.CAPABILITIES)   | Capabilities [`supports()`](_autosummary/aix.capabilities.html.md#aix.capabilities.supports) answers that are not one request parameter, mapped to the `model -> bool` check behind each.   |
|-----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

### Functions

| [`supports`](_autosummary/aix.capabilities.html.md#aix.capabilities.supports)(model, param)    | Whether `model` is known to accept `param` -- i.e. whether LiteLLM *forwards* it to the provider for this model.   |
|----------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
| [`supported_params`](_autosummary/aix.capabilities.html.md#aix.capabilities.supported_params)([model]) | The OpenAI-style parameters LiteLLM says `model` accepts.                                                          |

### aix.capabilities.CAPABILITIES *= {'response_schema': <function \_supports_response_schema>}*

Capabilities [`supports()`](_autosummary/aix.capabilities.html.md#aix.capabilities.supports) answers that are not one request parameter,
mapped to the `model -> bool` check behind each.

### aix.capabilities.supported_params(model=None)

The OpenAI-style parameters LiteLLM says `model` accepts.

`None` when that is unknown (LiteLLM cannot place the model, or is not
installed) – which is not the same as “supports nothing”.

* **Parameters:**
  **model** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Model id or alias; `None` means the configured chat default.
* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`frozenset`](https://docs.python.org/3/builtins/stdtypes.html#frozenset)]

### aix.capabilities.supports(model, param)

Whether `model` is known to accept `param` – i.e. whether LiteLLM
*forwards* it to the provider for this model.

Conservative: `False` when support is unknown (or for a non-string
`param`), so a caller that branches on it takes the path that works
everywhere. `True` is not a guarantee that the parameter has an effect:
a router (OpenRouter…) can forward `seed` / `n` to an upstream model
that drops them, and a provider can deprecate or ignore a parameter
(seeding is best-effort everywhere; reasoning models may ignore it).

* **Parameters:**
  * **model** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Model id or alias; `None` means the configured chat default.
  * **param** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – An OpenAI-style request parameter name (`"n"`, `"seed"`,
    `"response_format"`…) or a capability in [`CAPABILITIES`](_autosummary/aix.capabilities.html.md#aix.capabilities.CAPABILITIES)
    (`"response_schema"`).
* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

```pycon
>>> supports("gpt-4o-mini", "seed")
True
>>> supports("gpt-4o-mini", "response_schema")
True
```


# _autosummary/aix.claude_cli.html.md

# aix.claude_cli

A chat backend that runs prompts through the Claude Code CLI (`claude -p`).

With a Claude subscription and the CLI installed, `claude -p` answers prompts without
an API key, billed to the subscription. Use a model id with the `claude-cli/` prefix
and [`aix.chat()`](_autosummary/aix.html.md#aix.chat) / [`aix.complete()`](_autosummary/aix.html.md#aix.complete) route it here instead of to LiteLLM:

```default
>>> from aix import chat
>>> chat("Say hi in one word.", model="claude-cli/haiku")
'Hi!'
```

The CLI exposes no sampling controls, so `temperature`, `max_tokens`, `seed`,
`stream` and the like raise `ValueError` instead of being ignored in silence. The
cost the CLI reports is on `Completion.raw["total_cost_usd"]` (see
[`claude_cli_cost()`](_autosummary/aix.claude_cli.html.md#aix.claude_cli.claude_cli_cost)).

### Notes

`ANTHROPIC_API_KEY` is removed from the child environment (the CLI would
otherwise bill that key, not the subscription); `--bare` is never used, since it skips
the keychain read that finds the subscription login; the call runs in a neutral cwd with
no tools, MCP servers, slash commands or session persistence.

### Module Attributes

| [`UNSUPPORTED_PARAMS`](_autosummary/aix.claude_cli.html.md#aix.claude_cli.UNSUPPORTED_PARAMS)   | refused, not dropped.   |
|-----------------------------------------------------------------------|-------------------------|

### Functions

| [`check_claude_cli`](_autosummary/aix.claude_cli.html.md#aix.claude_cli.check_claude_cli)()                              | Raise `RuntimeError` with an install hint when `claude` is not on PATH.                                                               |
|--------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
| [`claude_cli_complete`](_autosummary/aix.claude_cli.html.md#aix.claude_cli.claude_cli_complete)(messages, \*, model[, ...]) | Run `messages` through `claude -p` and return an [`aix.chat.Completion`](_autosummary/aix.html.md#aix.Completion). |
| [`claude_cli_cost`](_autosummary/aix.claude_cli.html.md#aix.claude_cli.claude_cli_cost)(completion)                     | The cost in USD the CLI reported for `completion` (notional on a subscription).                                                       |
| [`is_claude_cli_model`](_autosummary/aix.claude_cli.html.md#aix.claude_cli.is_claude_cli_model)(model)                      | Whether `model` names this backend.                                                                                                   |
| [`refuse_unsupported`](_autosummary/aix.claude_cli.html.md#aix.claude_cli.refuse_unsupported)(\*\*params)                  | Raise `ValueError` for any set parameter the CLI cannot honour.                                                                       |

### aix.claude_cli.UNSUPPORTED_PARAMS *= ('temperature', 'max_tokens', 'seed', 'response_format', 'response_schema')*

refused, not dropped.

* **Type:**
  `chat`/`complete` arguments the CLI cannot honour

### aix.claude_cli.check_claude_cli()

Raise `RuntimeError` with an install hint when `claude` is not on PATH.

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### aix.claude_cli.claude_cli_complete(messages, , model, timeout=600, cwd=None, extra_args=(), runner=None)

Run `messages` through `claude -p` and return an [`aix.chat.Completion`](_autosummary/aix.html.md#aix.Completion).

`model` is `"claude-cli/<name>"` (`haiku`, `sonnet`, `opus` or a full id).
`runner` is the `subprocess.run` seam (default: looked up at call time). A CLI error
(`is_error`, or a `terminal_reason` other than `completed`) raises `RuntimeError`.

### aix.claude_cli.claude_cli_cost(completion)

The cost in USD the CLI reported for `completion` (notional on a subscription).

* **Return type:**
  [`float`](https://docs.python.org/3/builtins/functions.html#float)

### aix.claude_cli.is_claude_cli_model(model)

Whether `model` names this backend.

```pycon
>>> is_claude_cli_model("claude-cli/haiku"), is_claude_cli_model("gpt-4o")
(True, False)
```

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### aix.claude_cli.refuse_unsupported(\*\*params)

Raise `ValueError` for any set parameter the CLI cannot honour.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)


# _autosummary/aix.config.html.md

# 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()`](_autosummary/aix.config.html.md#aix.config.configure) swaps the active config; [`using()`](_autosummary/aix.config.html.md#aix.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`](_autosummary/aix.config.html.md#aix.config.AixConfig); [`configure()`](_autosummary/aix.config.html.md#aix.config.configure)
and [`using()`](_autosummary/aix.config.html.md#aix.config.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

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

Scoped override (does not leak outside the block):

```pycon
>>> 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:

```default
[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`](_autosummary/aix.config.html.md#aix.config.load_config)([path, environ])       | Resolve an [`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig) from shipped defaults, TOML file, and env.   |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------|
| [`get_config`](_autosummary/aix.config.html.md#aix.config.get_config)()                       | Return the current active [`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig).                              |
| [`set_config`](_autosummary/aix.config.html.md#aix.config.set_config)(config)                 | Replace the active config wholesale.                                                                               |
| [`configure`](_autosummary/aix.config.html.md#aix.config.configure)(\*\*overrides)           | Apply runtime overrides to the active config and return it.                                                        |
| [`using`](_autosummary/aix.config.html.md#aix.config.using)(\*\*overrides)               | Context manager applying scoped overrides, restored on exit.                                                       |
| [`config_file_path`](_autosummary/aix.config.html.md#aix.config.config_file_path)()                 | Path to the user config file (env `AIX_CONFIG_FILE` overrides default).                                            |
| [`resolve_model`](_autosummary/aix.config.html.md#aix.config.resolve_model)(model, \*[, config]) | Resolve a semantic alias (`"fast"`, `"best"`, ...) to a concrete model id.                                         |

### Classes

| [`ChatConfig`](_autosummary/aix.config.html.md#aix.config.ChatConfig)([model, temperature, max_tokens, ...])   | Defaults for `chat` / `ask` / `complete` / `sample` / `prompt_func`.            |
|------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
| [`EmbeddingConfig`](_autosummary/aix.config.html.md#aix.config.EmbeddingConfig)([model, batch_size])                | Defaults for `embeddings` / `embed`.                                            |
| [`ImageConfig`](_autosummary/aix.config.html.md#aix.config.ImageConfig)([model, size, quality, ...])            | Defaults for `generate_image` / `generate_images` and the edit/variation calls. |
| [`AudioConfig`](_autosummary/aix.config.html.md#aix.config.AudioConfig)([tts_model, tts_voice, ...])            | Defaults for `text_to_speech` / `transcribe` / `translate_audio`.               |
| [`VideoConfig`](_autosummary/aix.config.html.md#aix.config.VideoConfig)([provider])                             | Defaults for `generate_video` (provider-dependent).                             |
| [`VisionConfig`](_autosummary/aix.config.html.md#aix.config.VisionConfig)([model])                               | Defaults for `describe_image` (image→text).                                     |
| [`AixConfig`](_autosummary/aix.config.html.md#aix.config.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>)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#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')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#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)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

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

### *class* aix.config.EmbeddingConfig(model='text-embedding-3-small', batch_size=512)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#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')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#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)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Defaults for `generate_video` (provider-dependent).

### *class* aix.config.VisionConfig(model='gpt-4o-mini')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#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()

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

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### aix.config.configure(\*\*overrides)

Apply runtime overrides to the active config and return it.

### Examples

```pycon
>>> 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`](_autosummary/aix.config.html.md#aix.config.AixConfig)

### aix.config.get_config()

Return the current active [`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig).

Inside a [`using()`](_autosummary/aix.config.html.md#aix.config.using) block this is the scoped config of the current thread or
asyncio task; otherwise the process-wide config.

* **Return type:**
  [`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig)

### aix.config.load_config(path=None, , environ=None)

Resolve an [`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig) from shipped defaults, TOML file, and env.

Precedence (low to high): shipped defaults < TOML file < environment variables.
Runtime overrides ([`configure()`](_autosummary/aix.config.html.md#aix.config.configure)/[`using()`](_autosummary/aix.config.html.md#aix.config.using)) and explicit call arguments
sit above this and are applied elsewhere.

* **Parameters:**
  * **path** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Optional explicit TOML path. Defaults to [`config_file_path()`](_autosummary/aix.config.html.md#aix.config.config_file_path).
  * **environ** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Mapping`](https://docs.python.org/3/library/typing.html#typing.Mapping)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]) – Optional environment mapping (defaults to `os.environ`).
* **Return type:**
  [`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig)
* **Returns:**
  A fully resolved [`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig).

### aix.config.resolve_model(model, , config=None)

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

```pycon
>>> 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`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### aix.config.set_config(config)

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

Inside a [`using()`](_autosummary/aix.config.html.md#aix.config.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`](_autosummary/aix.config.html.md#aix.config.AixConfig)

### aix.config.using(\*\*overrides)

Context manager applying scoped overrides, restored on exit.

The override lives in a [`ContextVar`](https://docs.python.org/3/library/contextvars.html#contextvars.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()`](https://docs.python.org/3/library/contextvars.html#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

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

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig)]


# _autosummary/aix.credentials.html.md

# aix.credentials

Unified, discoverable API-key / secret resolution for AIX.

Every key-requiring function in AIX (`chat`, `embeddings`, `generate_image`,
`text_to_speech`, `transcribe`, `generate_video`, …) resolves its
credentials through a single, documented path – instead of relying on LiteLLM’s
implicit environment reading, scattered `os.getenv` calls, or an orphaned
config getter.

Resolution layers, highest precedence first:

1. **Explicit argument** – `chat(..., api_key=...)`.
2. **Provider environment variable** – the canonical name for the inferred
   provider (e.g. `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `GEMINI_API_KEY`).
   A project `.env` is *softly* discovered when `python-dotenv` is installed
   (no hard dependency); explicit env vars always win over `.env` values.
3. **AIX config store** – a config2py central store in the user app-config
   folder, keyed by the canonical env-var name (so the store and the env layer
   share one namespace). See [`aix.util`](_autosummary/aix.util.html.md#module-aix.util).
4. **(REPL only) interactive prompt** – when `prompt_if_missing=True` *and*
   running interactively, ask once and persist to the config store.

The provider for a model id is inferred via LiteLLM’s `get_llm_provider`; a
small curated `PROVIDER_ENV_VARS` table maps each documented provider to
its env-var name(s) and console URL.

When a required key is genuinely absent, [`check_requirements()`](_autosummary/aix.credentials.html.md#aix.credentials.check_requirements) raises
[`MissingCredentialError`](_autosummary/aix.credentials.html.md#aix.credentials.MissingCredentialError) – naming *which* key is missing, *how* to set
it, and *where* to obtain one – rather than letting a cryptic, provider-specific
LiteLLM error surface late. This preflight is wired in via the
[`requires_credentials()`](_autosummary/aix.credentials.html.md#aix.credentials.requires_credentials) decorator so error-raising stays separate from
business logic.

### Examples

```pycon
>>> from aix.credentials import resolve_api_key, PROVIDER_ENV_VARS
>>> resolve_api_key("gpt-4o", api_key="sk-explicit")  # explicit wins
'sk-explicit'
>>> "openai" in PROVIDER_ENV_VARS
True
```

Security:
: Resolved key *values* are never logged or returned by diagnostics;
  [`check_keys()`](_autosummary/aix.credentials.html.md#aix.credentials.check_keys) reports availability only. Keys live in the user
  app-config folder, never in the repo.

### Module Attributes

| [`KEYLESS_MODEL_PREFIXES`](_autosummary/aix.credentials.html.md#aix.credentials.KEYLESS_MODEL_PREFIXES)   | Model-id prefixes whose provider runs locally and needs no API key (extend to add more).   |
|---------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|

### Functions

| [`is_keyless`](_autosummary/aix.credentials.html.md#aix.credentials.is_keyless)(model_or_provider)                    | True when the model is served by a local provider that needs no API key.     |
|---------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| [`infer_provider`](_autosummary/aix.credentials.html.md#aix.credentials.infer_provider)(model_or_provider)                | Infer the provider name from a model id (or pass through a provider name).   |
| [`provider_env_vars`](_autosummary/aix.credentials.html.md#aix.credentials.provider_env_vars)(provider)                      | Return the env-var name(s) for `provider` as a list (possibly empty).        |
| [`resolve_api_key`](_autosummary/aix.credentials.html.md#aix.credentials.resolve_api_key)(model_or_provider, \*[, ...])    | Resolve an API key for `model_or_provider` through the documented layers.    |
| [`check_requirements`](_autosummary/aix.credentials.html.md#aix.credentials.check_requirements)(model_or_provider, \*[, ...]) | Presence-only preflight: ensure a key for `model_or_provider` is resolvable. |
| [`requires_credentials`](_autosummary/aix.credentials.html.md#aix.credentials.requires_credentials)(default_model)              | Decorator: preflight credentials before the wrapped function runs.           |
| [`check_keys`](_autosummary/aix.credentials.html.md#aix.credentials.check_keys)([providers])                          | Report, per provider, whether a usable API key is discoverable.              |

### Exceptions

| [`MissingCredentialError`](_autosummary/aix.credentials.html.md#aix.credentials.MissingCredentialError)(model_or_provider, \*)   | Raised when a required API key cannot be resolved.   |
|--------------------------------------------------------------------------------------------------|------------------------------------------------------|

### aix.credentials.KEYLESS_MODEL_PREFIXES *: [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[str](https://docs.python.org/3/builtins/stdtypes.html#str), ...]* *= ('ollama/', 'ollama_chat/')*

Model-id prefixes whose provider runs locally and needs no API key (extend to add more).

### *exception* aix.credentials.MissingCredentialError(model_or_provider, , provider=None, env_names=None)

Bases: [`Exception`](https://docs.python.org/3/builtins/exceptions.html#Exception)

Raised when a required API key cannot be resolved.

The message names which key is missing, how to set it, and (when known)
where to obtain one. Key *values* are never included.

### aix.credentials.check_keys(providers=None)

Report, per provider, whether a usable API key is discoverable.

Never returns or logs key *values* – only availability and the env-var
name(s) checked. Useful for quick setup debugging.

* **Parameters:**
  **providers** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]) – Providers to check; defaults to every provider in
  `PROVIDER_ENV_VARS`.
* **Returns:**
  bool, “env_vars”: […],
  “source”: <where-found-or-None>}\`\`. `source` is `"env"`, `"store"`,
  or `None` (never the value itself).
* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### Examples

```pycon
>>> report = check_keys(["openai"])
>>> report["openai"]["available"]
True
```

### aix.credentials.check_requirements(model_or_provider, , api_key=None)

Presence-only preflight: ensure a key for `model_or_provider` is resolvable.

Does *not* validate the key over the network – only that one is discoverable
via [`resolve_api_key()`](_autosummary/aix.credentials.html.md#aix.credentials.resolve_api_key) (explicit arg, env/.env, or store). Raises
[`MissingCredentialError`](_autosummary/aix.credentials.html.md#aix.credentials.MissingCredentialError) with actionable guidance when absent.

Returns `True` when a key is available, or when the model is local and
needs none ([`is_keyless()`](_autosummary/aix.credentials.html.md#aix.credentials.is_keyless), e.g. `ollama/...`).

### Examples

```pycon
>>> check_requirements("gpt-4o", api_key="sk-explicit")
True
>>> check_requirements("ollama/mistral")
True
```

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### aix.credentials.infer_provider(model_or_provider)

Infer the provider name from a model id (or pass through a provider name).

Common model ids are classified offline by prefix (`MODEL_PREFIX_PROVIDERS`); anything else uses LiteLLM’s `get_llm_provider` when available. If `model_or_provider`
is already a known provider name (a key in `PROVIDER_ENV_VARS`), it is
returned as-is. Returns `None` if the provider cannot be determined.

### Examples

```pycon
>>> infer_provider("gpt-4o")
'openai'
>>> infer_provider("openrouter")  # already a provider name
'openrouter'
>>> infer_provider(None) is None
True
```

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### aix.credentials.is_keyless(model_or_provider)

True when the model is served by a local provider that needs no API key.

```pycon
>>> is_keyless("ollama/mistral:7b-instruct-q6_K")
True
>>> is_keyless("gpt-4o")
False
```

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### aix.credentials.provider_env_vars(provider)

Return the env-var name(s) for `provider` as a list (possibly empty).

### Examples

```pycon
>>> provider_env_vars("openai")
['OPENAI_API_KEY']
>>> provider_env_vars("gemini")
['GEMINI_API_KEY', 'GOOGLE_API_KEY']
>>> provider_env_vars("totally-unknown-provider")
[]
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### aix.credentials.requires_credentials(default_model)

Decorator: preflight credentials before the wrapped function runs.

Separates error-raising from business logic (per the AIX coding principles).
The wrapped function is expected to take keyword-only `model` and
`api_key` parameters. `default_model` is a zero-arg callable returning the
model the function would default to (read from the active config at call
time), so the preflight checks the *same* model the function will use.

* **Parameters:**
  **default_model** ([`Callable`](https://docs.python.org/3/library/typing.html#typing.Callable)[[], [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]) – Callable returning the default model id when the caller
  passes `model=None`.

### Examples

```pycon
>>> from aix import config
>>> @requires_credentials(lambda: config.get_config().chat.model)
... def f(*, model=None, api_key=None):
...     return "ran"
>>> f(api_key="sk-explicit")
'ran'
```

### aix.credentials.resolve_api_key(model_or_provider, , api_key=None, prompt_if_missing=False)

Resolve an API key for `model_or_provider` through the documented layers.

Layers, highest precedence first: explicit `api_key` argument, provider
environment variable (with soft `.env` discovery), the AIX config store,
and – only when `prompt_if_missing` is true *and* running interactively –
an interactive prompt that persists the answer.

* **Parameters:**
  * **model_or_provider** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – A model id (provider inferred via LiteLLM) or a
    provider name directly (e.g. `"openai"`).
  * **api_key** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – An explicit key; when given (non-empty) it is returned verbatim.
  * **prompt_if_missing** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If true, fall back to a REPL prompt + persist when no
    key is found elsewhere. Off by default so the common path never
    blocks on input.
* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]
* **Returns:**
  The resolved key, or `None` if genuinely absent.

### Examples

```pycon
>>> resolve_api_key("gpt-4o", api_key="sk-explicit")
'sk-explicit'
```


# _autosummary/aix.gen_ai.google_genai.html.md

# aix.gen_ai.google_genai

Google GenAI API functionality.

### Classes

| `Const`()   |    |
|-------------|----|


# _autosummary/aix.gen_ai.html.md

# aix.gen_ai

Generative AI modules.

### Functions

| [`chat`](_autosummary/aix.gen_ai.html.md#aix.gen_ai.chat)(prompt, \*, model, \*\*kwargs)   | Chat with the specified model.                    |
|----------------------------------------------------------------------------------------|---------------------------------------------------|
| [`chat_function_for_model`](_autosummary/aix.gen_ai.html.md#aix.gen_ai.chat_function_for_model)(model)        | Return the chat function for the specified model. |

### aix.gen_ai.chat(prompt, , model, \*\*kwargs)

Chat with the specified model.

### aix.gen_ai.chat_function_for_model(model)

Return the chat function for the specified model.

### Modules

| [`google_genai`](_autosummary/aix.gen_ai.google_genai.html.md#module-aix.gen_ai.google_genai)   | Google GenAI API functionality.                                                 |
|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
| [`openai_genai`](_autosummary/aix.gen_ai.openai_genai.html.md#module-aix.gen_ai.openai_genai)   | OpenAI GenAI API functionality (legacy backend, via the optional `oa` package). |


# _autosummary/aix.gen_ai.openai_genai.html.md

# aix.gen_ai.openai_genai

OpenAI GenAI API functionality (legacy backend, via the optional `oa` package).

`oa` is imported on the first call, never at `import aix` time: importing
`oa` resolves an OpenAI API key as a side effect – raising when none is
configured, and *prompting for one on stdin* in an interactive session – so an
eager import made `import aix` crash or block for anyone who has `oa`
installed but no key set ([https://github.com/thorwhalen/aix/issues/54](https://github.com/thorwhalen/aix/issues/54)).


# _autosummary/aix.html.md

# aix

AIX: Artificial Intelligence eXtensions

A clean, pythonic facade for common AI operations that abstracts away
provider-specific details and complexities.

Quick Start:

> ```pycon
> >>> from aix import chat, embeddings, prompt_func, models
> ```

> ### Simple chat

> ```pycon
> >>> response = chat("What is 2+2?")
> 'The answer is 4.'
> ```

> ### Create prompt-based functions

> ```pycon
> >>> translate = prompt_func("Translate to French: {text}")
> >>> translate(text="Hello world")
> 'Bonjour le monde'
> ```

> ### Get embeddings

> ```pycon
> >>> vecs = list(embeddings(["hello", "world"]))
> >>> len(vecs)
> 2
> ```

> ### Discover models

> ```pycon
> >>> models.discover()
> >>> list(models)[:5]
> ['openai/gpt-4o', 'openai/gpt-4o-mini', ...]
> ```

Main Features:

> - chat(): Simple chat interface across providers
> - complete(): The whole response (all n choices, usage, finish reasons)
> - sample(): n answers to one prompt, concurrently or via provider-side n
> - supports(): ask whether a model honours a parameter (seed, n, response_schema…)
> - embeddings(): Vector embeddings for text
> - prompt_func(): Create functions from prompt templates
> - models: Model discovery and selection
> - generate_image(): Text-to-image generation
> - text_to_speech(), transcribe(): Audio operations
> - generate_video(): Text-to-video generation (provider-dependent)
> - Batch operations for efficiency
> - Clean, i2mint-style Mapping interfaces

Backends:

> - Uses LiteLLM for provider interactions
> - Supports OpenAI, Anthropic, Google, and 100+ models
> - OpenRouter integration for multi-provider access

For detailed documentation, see: [https://github.com/thorwhalen/aix](https://github.com/thorwhalen/aix)

### Functions

| [`get_config`](_autosummary/aix.html.md#aix.get_config)()                                       | Return the current active [`AixConfig`](_autosummary/aix.html.md#aix.AixConfig).                                |
|-----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| [`set_config`](_autosummary/aix.html.md#aix.set_config)(config)                                 | Replace the active config wholesale.                                                                                 |
| [`configure`](_autosummary/aix.html.md#aix.configure)(\*\*overrides)                           | Apply runtime overrides to the active config and return it.                                                          |
| [`using`](_autosummary/aix.html.md#aix.using)(\*\*overrides)                               | Context manager applying scoped overrides, restored on exit.                                                         |
| [`load_config`](_autosummary/aix.html.md#aix.load_config)([path, environ])                       | Resolve an [`AixConfig`](_autosummary/aix.html.md#aix.AixConfig) from shipped defaults, TOML file, and env.     |
| [`resolve_model`](_autosummary/aix.html.md#aix.resolve_model)(model, \*[, config])                 | Resolve a semantic alias (`"fast"`, `"best"`, ...) to a concrete model id.                                           |
| [`call_logger`](_autosummary/aix.html.md#aix.call_logger)(logger)                                | Log calls made inside the `with` block to `logger`.                                                                  |
| [`set_call_logger`](_autosummary/aix.html.md#aix.set_call_logger)(logger)                            | Install `logger` for this context (`None` turns logging off).                                                        |
| [`jsonl_logger`](_autosummary/aix.html.md#aix.jsonl_logger)(path)                                 | A logger that appends one JSON line per call to `path`.                                                              |
| [`resolve_api_key`](_autosummary/aix.html.md#aix.resolve_api_key)(model_or_provider, \*[, ...])      | Resolve an API key for `model_or_provider` through the documented layers.                                            |
| [`check_requirements`](_autosummary/aix.html.md#aix.check_requirements)(model_or_provider, \*[, ...])   | Presence-only preflight: ensure a key for `model_or_provider` is resolvable.                                         |
| [`check_keys`](_autosummary/aix.html.md#aix.check_keys)([providers])                            | Report, per provider, whether a usable API key is discoverable.                                                      |
| [`chat`](_autosummary/aix.html.md#aix.chat)(prompt, \*[, model, temperature, ...])        | Send a chat prompt and get a response.                                                                               |
| [`complete`](_autosummary/aix.html.md#aix.complete)(prompt, \*[, model, temperature, ...])    | Send a chat prompt and get the whole response back as a [`Completion`](_autosummary/aix.html.md#aix.Completion). |
| [`ask`](_autosummary/aix.html.md#aix.ask)(question[, model])                             | Ask a single question and get an answer.                                                                             |
| [`sample`](_autosummary/aix.html.md#aix.sample)(prompt, \*, n[, temperature, seed, ...])    | Draw `n` answers to `prompt`, each with its finish reason and usage.                                                 |
| [`supports`](_autosummary/aix.html.md#aix.supports)(model, param)                             | Whether `model` is known to accept `param` -- i.e. whether LiteLLM *forwards* it to the provider for this model.     |
| [`supported_params`](_autosummary/aix.html.md#aix.supported_params)([model])                          | The OpenAI-style parameters LiteLLM says `model` accepts.                                                            |
| [`chat_with_history`](_autosummary/aix.html.md#aix.chat_with_history)([system_prompt, model])          | Create a stateful chat session that maintains conversation history.                                                  |
| [`embeddings`](_autosummary/aix.html.md#aix.embeddings)(segments, \*[, model, api_key])         | Generate embeddings for multiple text segments.                                                                      |
| [`embed`](_autosummary/aix.html.md#aix.embed)(text, \*[, model])                           | Generate embedding for a single text.                                                                                |
| [`cosine_similarity`](_autosummary/aix.html.md#aix.cosine_similarity)(vec1, vec2)                      | Compute cosine similarity between two vectors.                                                                       |
| [`find_most_similar`](_autosummary/aix.html.md#aix.find_most_similar)(query, candidates, \*[, ...])    | Find most similar texts to a query.                                                                                  |
| [`prompt_func`](_autosummary/aix.html.md#aix.prompt_func)(template, \*[, output_schema, ...])    | Create a callable function from a prompt template.                                                                   |
| [`prompt_to_text`](_autosummary/aix.html.md#aix.prompt_to_text)(template, \*\*kwargs)               | Create a function that returns text output.                                                                          |
| [`prompt_to_json`](_autosummary/aix.html.md#aix.prompt_to_json)(template, schema, \*\*kwargs)       | Create a function that returns structured JSON output.                                                               |
| [`constrained_answer`](_autosummary/aix.html.md#aix.constrained_answer)(prompt, valid_answers, \*)      | Get an answer from the LLM constrained to a set of valid answers or types.                                           |
| [`discover_available_models`](_autosummary/aix.html.md#aix.discover_available_models)([source, verbose])       | Discover available models from a source.                                                                             |
| [`get_model_info`](_autosummary/aix.html.md#aix.get_model_info)(model_id)                           | Get information about a specific model.                                                                              |
| [`find_models`](_autosummary/aix.html.md#aix.find_models)(query)                                 | Search for models matching a query.                                                                                  |
| [`batch_chat`](_autosummary/aix.html.md#aix.batch_chat)(prompts, \*[, model, batch_size, ...])  | Process multiple chat prompts in batches.                                                                            |
| [`batch_embeddings`](_autosummary/aix.html.md#aix.batch_embeddings)(segments, \*[, model, ...])       | Generate embeddings for multiple texts in batches.                                                                   |
| [`batch_process`](_autosummary/aix.html.md#aix.batch_process)(items, process_func, \*[, ...])      | Generic batch processing with parallel execution and retries.                                                        |
| [`generate_image`](_autosummary/aix.html.md#aix.generate_image)(prompt, \*[, model, size, ...])     | Generate a single image from a text prompt.                                                                          |
| [`generate_images`](_autosummary/aix.html.md#aix.generate_images)(prompt, \*[, n, model, size, ...]) | Generate multiple images from a text prompt.                                                                         |
| [`edit_image`](_autosummary/aix.html.md#aix.edit_image)(image_path, prompt, \*[, ...])          | Edit an existing image based on a prompt.                                                                            |
| [`create_variation`](_autosummary/aix.html.md#aix.create_variation)(image_path, \*[, model, ...])     | Create variations of an existing image.                                                                              |
| [`text_to_speech`](_autosummary/aix.html.md#aix.text_to_speech)(text, \*[, model, voice, ...])      | Convert text to speech audio.                                                                                        |
| [`transcribe`](_autosummary/aix.html.md#aix.transcribe)(audio, \*[, engine, model, ...])        | Transcribe audio to text.                                                                                            |
| [`transcribe_with_timestamps`](_autosummary/aix.html.md#aix.transcribe_with_timestamps)(audio, \*[, ...])       | Transcribe audio with detailed timestamps.                                                                           |
| [`translate_audio`](_autosummary/aix.html.md#aix.translate_audio)(audio, \*[, model, prompt, ...])   | Translate audio from any language to English.                                                                        |
| [`generate_video`](_autosummary/aix.html.md#aix.generate_video)(prompt, \*[, model, duration, ...]) | Generate a video from a text prompt.                                                                                 |
| [`animate_image_to_video`](_autosummary/aix.html.md#aix.animate_image_to_video)(image_path[, prompt, ...])  | Animate a static image into a video.                                                                                 |
| [`extend_video`](_autosummary/aix.html.md#aix.extend_video)(video_path[, prompt, ...])            | Extend an existing video with additional generated content.                                                          |
| [`get_video_providers`](_autosummary/aix.html.md#aix.get_video_providers)()                              | Get list of available video generation providers.                                                                    |
| [`describe_image`](_autosummary/aix.html.md#aix.describe_image)(image, \*[, prompt, model, ...])    | Describe (or answer a question about) `image` and return the text.                                                   |
| [`to_image_content`](_autosummary/aix.html.md#aix.to_image_content)(image, \*[, detail])              | Build a multimodal `image_url` content block for `image`.                                                            |
| [`compare_images`](_autosummary/aix.html.md#aix.compare_images)(candidate, reference, \*[, ...])    | Compare a `candidate` image to `reference` image(s) on a rubric.                                                     |

### Classes

| [`AixConfig`](_autosummary/aix.html.md#aix.AixConfig)([chat, embeddings, image, audio, ...])   | Top-level AIX configuration (single source of truth for defaults).                                                                                           |
|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`CallRecord`](_autosummary/aix.html.md#aix.CallRecord)(function, model, caller, ok, seconds)   | One aix call: which function, the model it resolved to, who called, how it ended.                                                                            |
| [`Completion`](_autosummary/aix.html.md#aix.Completion)(texts[, finish_reasons, usage, ...])    | Everything a chat completion returned, not just the first text.                                                                                              |
| [`Usage`](_autosummary/aix.html.md#aix.Usage)([prompt_tokens, completion_tokens, ...])     | Token counts billed for one call (or summed over several).                                                                                                   |
| [`Sample`](_autosummary/aix.html.md#aix.Sample)(text, payload[, finish_reason, ...])        | One drawn answer.                                                                                                                                            |
| [`Samples`](_autosummary/aix.html.md#aix.Samples)([samples, usage, n_requests, ...])         | The list of [`Sample`](_autosummary/aix.html.md#aix.Sample) returned by [`sample()`](_autosummary/aix.html.md#aix.sample), plus batch facts. |
| [`ResponseSchema`](_autosummary/aix.html.md#aix.ResponseSchema)(name, json_schema, ...[, ...])      | A normalized response schema: its JSON Schema, name, and validator.                                                                                          |
| [`ChatSession`](_autosummary/aix.html.md#aix.ChatSession)([system_prompt, model])                | Stateful chat session that maintains conversation history.                                                                                                   |
| [`EmbeddingCache`](_autosummary/aix.html.md#aix.EmbeddingCache)([model])                            | Cache for embeddings to avoid redundant API calls.                                                                                                           |
| [`PromptFuncs`](_autosummary/aix.html.md#aix.PromptFuncs)([model])                               | Collection of prompt-based functions.                                                                                                                        |
| [`ModelStore`](_autosummary/aix.html.md#aix.ModelStore)([storage_path, auto_discover])          | User-friendly interface for model discovery and selection.                                                                                                   |
| [`BatchProcessor`](_autosummary/aix.html.md#aix.BatchProcessor)(\*[, batch_size, max_workers, ...]) | Stateful batch processor for managing long-running operations.                                                                                               |
| [`BatchError`](_autosummary/aix.html.md#aix.BatchError)(exception, \*[, index, message])        | A batch result slot standing in for an item that raised.                                                                                                     |
| [`GeneratedImage`](_autosummary/aix.html.md#aix.GeneratedImage)([url, b64_json, model, ...])        | Wrapper for generated images.                                                                                                                                |
| [`GeneratedAudio`](_autosummary/aix.html.md#aix.GeneratedAudio)(data[, model, text, voice, ...])    | Wrapper for generated audio.                                                                                                                                 |
| [`TranscriptionResult`](_autosummary/aix.html.md#aix.TranscriptionResult)(text[, language, ...])         | Result of audio transcription.                                                                                                                               |
| [`GeneratedVideo`](_autosummary/aix.html.md#aix.GeneratedVideo)([url, data, model, prompt, ...])    | Wrapper for generated videos.                                                                                                                                |
| [`RubricVerdict`](_autosummary/aix.html.md#aix.RubricVerdict)(aspect, match, confidence[, note])   | A vision model's verdict on a single rubric aspect.                                                                                                          |
| [`ImageComparison`](_autosummary/aix.html.md#aix.ImageComparison)(match, confidence, explanation)    | Structured result of comparing a candidate image to reference(s).                                                                                            |

### Exceptions

| [`MissingCredentialError`](_autosummary/aix.html.md#aix.MissingCredentialError)(model_or_provider, \*)      | Raised when a required API key cannot be resolved.                                                           |
|-----------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|
| [`SamplingError`](_autosummary/aix.html.md#aix.SamplingError)(message, \*[, samples])              | A request inside [`sample()`](_autosummary/aix.html.md#aix.sample) failed (with `on_error="raise"`). |
| [`SchemaValidationError`](_autosummary/aix.html.md#aix.SchemaValidationError)(message, \*[, text, detail]) | A reply was not JSON, or did not match the response schema.                                                  |
| [`ConstraintViolation`](_autosummary/aix.html.md#aix.ConstraintViolation)(message, \*[, answer, ...])    | Raised when an LLM answer does not satisfy the requested constraint.                                         |

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

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

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

### *class* aix.BatchError(exception, , index=None, message=None)

Bases: [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

A batch result slot standing in for an item that raised.

Subclasses `str` so it *is* the `"ERROR: ..."` string these functions
have always put in the failed slot – comparisons, `.startswith`,
slicing, JSON serialisation and logging all behave identically. What it
adds is the ability to tell a failure apart from a model that legitimately
replied with text starting “ERROR:”, and to reach the original exception.

#### exception

The exception that was caught.

* **Type:**
  [`BaseException`](https://docs.python.org/3/builtins/exceptions.html#BaseException)

#### index

Position of the failed item in the input, when known.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

### Examples

```pycon
>>> err = BatchError(RuntimeError("rate limit exceeded"), index=1)
>>> err == "ERROR: rate limit exceeded"
True
>>> isinstance(err, str), isinstance(err.exception, RuntimeError)
(True, True)
>>> err.index
1
```

### *class* aix.BatchProcessor(, batch_size=None, max_workers=None, show_progress=True)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Stateful batch processor for managing long-running operations.

Provides a higher-level interface for batch processing with
progress tracking, error handling, and result caching.

### Examples

```pycon
>>> processor = BatchProcessor(show_progress=True)
>>> results = processor.process_chats(prompts)
>>> processor.save_results("output.json")
```

#### clear()

Clear stored results and errors.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### process_chats(prompts, \*\*kwargs)

Process chat prompts and store results.

* **Parameters:**
  * **prompts** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]]]) – Prompts to process
  * **\*\*kwargs** – Additional parameters for batch_chat()
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]
* **Returns:**
  List of results

#### process_embeddings(texts, \*\*kwargs)

Process embeddings and store results.

* **Parameters:**
  * **texts** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Texts to embed
  * **\*\*kwargs** – Additional parameters for batch_embeddings()
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]]
* **Returns:**
  List of embedding vectors

#### save_results(filepath)

Save results to file.

* **Parameters:**
  **filepath** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Path to save results (JSON)
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* aix.CallRecord(function, model, caller, ok, seconds, error=None, time=0.0)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One aix call: which function, the model it resolved to, who called, how it ended.

### *class* aix.ChatSession(system_prompt=None, , model=None, \*\*chat_kwargs)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Stateful chat session that maintains conversation history.

This class provides a convenient way to have multi-turn conversations
without manually managing message history.

### Examples

```pycon
>>> session = ChatSession()
>>> response = session.send("My name is Alice")
>>> response = session.send("What's my name?")
'Your name is Alice.'
```

#### clear_history(keep_system=True)

Clear conversation history.

* **Parameters:**
  **keep_system** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, preserve system message (if any)
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### send(message, \*\*kwargs)

Send a message and get a response.

* **Parameters:**
  * **message** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – User message to send
  * **\*\*kwargs** – Override chat parameters for this message
* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)
* **Returns:**
  Assistant’s response

### *class* aix.Completion(texts, finish_reasons=(), usage=None, model=None, raw=None, values=(), errors=(), schema_mode=None, repairs=0, system_fingerprint=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Everything a chat completion returned, not just the first text.

#### texts

The text of every choice, in order (`n` of them when `n` was
requested). A choice with no text content (e.g. a pure tool call)
is `""`; list-of-parts content is reduced to its joined text parts.
Tool calls themselves are not surfaced here – read them from `raw`.

* **Type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis)]

#### finish_reasons

Why each choice stopped (`"stop"`, `"length"`,
`"content_filter"`, `"tool_calls"`…), aligned with `texts`;
`None` where the provider did not say. `"length"` means the
text was truncated by `max_tokens`.

* **Type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)], [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis)]

#### usage

Tokens billed for the whole call (all choices together), or
`None` if the provider did not report usage (so filter before
summing: `sum((c.usage for c in cs if c.usage), Usage())`).

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Usage`](_autosummary/aix.html.md#aix.Usage)]

#### model

The model id the provider reports having served the call, which
can differ from the one requested (aliases, dated snapshots).

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### raw

The untouched LiteLLM response, for anything not surfaced here.

* **Type:**
  [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)

#### system_fingerprint

The provider’s identifier for the serving backend
configuration, when it reports one (OpenAI does). Seeded outputs
are only comparable across calls with the same fingerprint. A
response replayed from a cache carries its *original* fingerprint.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### values

With `response_schema=`: each choice’s validated value (a
Pydantic instance for a Pydantic schema), `None` where invalid.

* **Type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)

#### errors

Aligned with `values`: `None`, or why that choice has no
value – the [`SchemaValidationError`](_autosummary/aix.structured.html.md#aix.structured.SchemaValidationError) of a
reply still invalid after the repair retries (or a refusal), or the
exception a repair request raised.

* **Type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)

#### schema_mode

How the schema was enforced: `"strict"`, `"schema"`,
`"json_mode"` or `"prompt"` (see [`aix.structured`](_autosummary/aix.structured.html.md#module-aix.structured));
`None` without one.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### repairs

How many repair requests were made (their tokens are in `usage`).

* **Type:**
  [`int`](https://docs.python.org/3/builtins/functions.html#int)

```pycon
>>> c = Completion(texts=("a", "b"), finish_reasons=("stop", "length"))
>>> c.text, c.finish_reason
('a', 'stop')
```

#### *property* finish_reason *: [Optional](https://docs.python.org/3/library/typing.html#typing.Optional)[[str](https://docs.python.org/3/builtins/stdtypes.html#str)]*

The first choice’s finish reason.

#### *classmethod* from_response(response)

Build a [`Completion`](_autosummary/aix.html.md#aix.Completion) from a (non-streaming) LiteLLM response.

* **Return type:**
  [`Completion`](_autosummary/aix.html.md#aix.Completion)

#### *property* text *: [str](https://docs.python.org/3/builtins/stdtypes.html#str)*

The first choice’s text (`""` if there are no choices).

#### *property* value *: [Any](https://docs.python.org/3/library/typing.html#typing.Any)*

The first choice’s validated value (needs `response_schema=`).

Raises the recorded [`SchemaValidationError`](_autosummary/aix.structured.html.md#aix.structured.SchemaValidationError) if
that choice still did not validate after the repair retries.

### *exception* aix.ConstraintViolation(message, , answer=None, valid_answers=None)

Bases: [`ValueError`](https://docs.python.org/3/builtins/exceptions.html#ValueError)

Raised when an LLM answer does not satisfy the requested constraint.

A subclass of `ValueError` so that callers who already guard
[`constrained_answer()`](_autosummary/aix.html.md#aix.constrained_answer) with `except ValueError` keep working.

#### answer

The offending value, as it came back from the model.

#### valid_answers

The constraint the value failed, verbatim as passed in.

### Examples

```pycon
>>> violation = ConstraintViolation("nope", answer="nope", valid_answers=["a"])
>>> violation.answer, violation.valid_answers
('nope', ['a'])
>>> isinstance(violation, ValueError)
True
```

### *class* aix.EmbeddingCache(model=None, \*\*embedding_kwargs)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Cache for embeddings to avoid redundant API calls.

Useful when you need to embed the same texts multiple times.

### Examples

```pycon
>>> cache = EmbeddingCache()
>>> vec1 = cache.embed("hello")  # API call
>>> vec2 = cache.embed("hello")  # From cache
>>> vec1 == vec2
True
```

#### clear()

Clear the cache.

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### embed(text, force_refresh=False)

Get embedding for text, using cache if available.

* **Parameters:**
  * **text** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text to embed
  * **force_refresh** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, bypass cache and get fresh embedding
* **Return type:**
  [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]
* **Returns:**
  Vector embedding

#### embed_batch(texts, force_refresh=False)

Get embeddings for multiple texts, using cache when possible.

* **Parameters:**
  * **texts** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Texts to embed
  * **force_refresh** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, bypass cache
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]]
* **Returns:**
  List of embeddings in same order as input texts

### *class* aix.GeneratedAudio(data, model=None, text=None, voice=None, format='mp3')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Wrapper for generated audio.

Provides convenient access to audio data and saving.

### Examples

```pycon
>>> audio = GeneratedAudio(data=b'...', model="tts-1")
>>> audio.save("output.mp3")
>>> data = audio.as_bytes()
```

#### as_bytes()

Get audio as bytes.

* **Return type:**
  [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)
* **Returns:**
  Audio data as bytes

#### play()

Play the audio.

Requires a system audio player or library like pygame/pyaudio.

### Examples

```pycon
>>> audio.play()
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### save(path)

Save audio to file.

* **Parameters:**
  **path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Output file path
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### Examples

```pycon
>>> audio.save("output.mp3")
>>> audio.save("speech.wav")
```

### *class* aix.GeneratedImage(url=None, b64_json=None, model=None, prompt=None, revised_prompt=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Wrapper for generated images.

Provides convenient access to image data in various formats.

### Examples

```pycon
>>> img = GeneratedImage(url="https://...", model="gpt-image-1.5")
>>> img.save("output.png")
>>> img.show()
>>> data = img.as_bytes()
```

#### as_bytes()

Get image as bytes.

* **Return type:**
  [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)
* **Returns:**
  Image data as bytes

#### as_pil_image()

Get image as PIL Image object.

* **Returns:**
  PIL.Image object
* **Raises:**
  [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If PIL is not installed

#### save(path, format=None)

Save image to file.

* **Parameters:**
  * **path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Output file path
  * **format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image format (e.g., ‘PNG’, ‘JPEG’). Auto-detected from path if None.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### Examples

```pycon
>>> img.save("output.png")
>>> img.save("output.jpg", format="JPEG")
```

#### show()

Display the image.

Requires PIL (Pillow) to be installed.

### Examples

```pycon
>>> img.show()
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* aix.GeneratedVideo(url=None, data=None, model=None, prompt=None, duration=None, resolution=None, status='completed', task_id=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Wrapper for generated videos.

Provides convenient access to video data and metadata.

### Examples

```pycon
>>> video = GeneratedVideo(url="https://...")
>>> video.save("output.mp4")
>>> print(video.duration)
5.0
```

#### as_bytes()

Get video as bytes.

* **Return type:**
  [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)
* **Returns:**
  Video data as bytes

#### save(path)

Save video to file.

* **Parameters:**
  **path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Output file path
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### Examples

```pycon
>>> video.save("output.mp4")
```

#### wait_until_complete(max_wait=300, poll_interval=5)

Wait for video generation to complete (for async operations).

* **Parameters:**
  * **max_wait** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum time to wait in seconds
  * **poll_interval** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Time between status checks in seconds
* **Raises:**
  * [**TimeoutError**](https://docs.python.org/3/builtins/exceptions.html#TimeoutError) – If generation doesn’t complete within max_wait
  * [**RuntimeError**](https://docs.python.org/3/builtins/exceptions.html#RuntimeError) – If generation fails
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* aix.ImageComparison(match, confidence, explanation, aspects=tuple(), model=None, usage=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Structured result of comparing a candidate image to reference(s).

Behaves like an ordered, read-only mapping of `aspect -> RubricVerdict`
(`comparison["identity"]`, `in`, iteration, `len`) so per-aspect
lookups read naturally, while also carrying the overall verdict.

#### match

Overall pass/fail across the whole rubric.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### confidence

Overall confidence in `[0.0, 1.0]`.

* **Type:**
  [`float`](https://docs.python.org/3/builtins/functions.html#float)

#### explanation

A short overall summary of the comparison.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### aspects

The per-aspect verdicts, one [`RubricVerdict`](_autosummary/aix.html.md#aix.RubricVerdict) per
rubric item, in rubric order.

* **Type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`RubricVerdict`](_autosummary/aix.vision.html.md#aix.vision.RubricVerdict), [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis)]

#### model

The vision model id that produced the verdict.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### usage

Tokens billed for the comparison request (see
[`aix.Usage`](_autosummary/aix.html.md#aix.Usage)), or `None` if the provider did not report it.

* **Type:**
  [`Usage`](_autosummary/aix.html.md#aix.Usage) | [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### get(aspect, default=None)

Return the verdict for `aspect`, or `default` if absent.

* **Return type:**
  [`RubricVerdict`](_autosummary/aix.vision.html.md#aix.vision.RubricVerdict) | [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *exception* aix.MissingCredentialError(model_or_provider, , provider=None, env_names=None)

Bases: [`Exception`](https://docs.python.org/3/builtins/exceptions.html#Exception)

Raised when a required API key cannot be resolved.

The message names which key is missing, how to set it, and (when known)
where to obtain one. Key *values* are never included.

### *class* aix.ModelStore(storage_path=None, auto_discover=False)

Bases: [`Mapping`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Mapping)

User-friendly interface for model discovery and selection.

Provides a Mapping interface over the ModelManager with convenient
access patterns and integration with chat/embeddings functions.

### Examples

```pycon
>>> models = ModelStore()
>>> models.discover()  # Fetch available models
```

```pycon
>>> # List all models
>>> list(models)[:5]
['openai/gpt-4o', 'openai/gpt-4o-mini', ...]
```

```pycon
>>> # Get model info
>>> info = models['openai/gpt-4o']
>>> info.provider
'openai'
```

```pycon
>>> # Filter models
>>> openai_models = models.filter(provider='openai')
>>> local_models = models.filter(is_local=True)
```

```pycon
>>> # Use with chat
>>> from aix.chat import chat
>>> model = models['gpt-4o-mini']
>>> chat("Hello", model=model.id)
'Hello! How can I help you?'
```

#### by_provider(provider)

Get all models from a specific provider.

* **Parameters:**
  **provider** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Provider name
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of models

### Examples

```pycon
>>> models = ModelStore()
>>> openai_models = models.by_provider('openai')
```

#### by_task(task)

Get models suitable for a specific task.

* **Parameters:**
  **task** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Task name (‘chat’, ‘embedding’, ‘image’, etc.)
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of suitable models

### Examples

```pycon
>>> models = ModelStore()
>>> chat_models = models.by_task('chat')
```

#### discover(source='openrouter', auto_register=True, verbose=False)

Discover models from a source.

* **Parameters:**
  * **source** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Source name (‘openrouter’, ‘ollama’, etc.)
  * **auto_register** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, add discovered models to registry
  * **verbose** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, print progress information
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of discovered models

### Examples

```pycon
>>> models = ModelStore()
>>> discovered = models.discover('openrouter')
>>> len(discovered) > 100
True
```

#### filter(, provider=None, is_local=None, min_context_size=None, max_context_size=None, has_capabilities=None, tags=None, custom_filter=None)

Filter models by criteria.

* **Parameters:**
  * **provider** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Filter by provider name (‘openai’, ‘anthropic’, etc.)
  * **is_local** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Filter by local vs remote
  * **min_context_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Minimum context window size
  * **max_context_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum context window size
  * **has_capabilities** ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Required capabilities
  * **tags** ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Required tags
  * **custom_filter** (`callable`) – Custom filter function: f(Model) -> bool
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of models matching criteria

### Examples

```pycon
>>> models = ModelStore()
>>> models.discover(verbose=False)
```

```pycon
>>> # Get OpenAI models
>>> openai = models.filter(provider='openai')
```

```pycon
>>> # Get local models
>>> local = models.filter(is_local=True)
```

```pycon
>>> # Get cheap models
>>> cheap = models.filter(
...     custom_filter=lambda m: m.cost_per_token.get('input', 0) < 0.001
... )
```

```pycon
>>> # Combine criteria
>>> good_models = models.filter(
...     provider='openai',
...     min_context_size=8000,
...     custom_filter=lambda m: 'gpt-4' in m.id
... )
```

#### get_connector_metadata(model_id, connector)

Get connector-specific metadata for a model.

* **Parameters:**
  * **model_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model identifier
  * **connector** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Connector name (‘openai’, ‘openrouter’, etc.)
* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]
* **Returns:**
  Dict with connector-specific parameters

### Examples

```pycon
>>> models = ModelStore()
>>> meta = models.get_connector_metadata(
...     'openai/gpt-4o',
...     'openai'
... )
>>> meta['model']
'gpt-4o'
```

#### get_info(model_id)

Get detailed information about a model.

* **Parameters:**
  **model_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model identifier
* **Return type:**
  [`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)
* **Returns:**
  Model object with full metadata

### Examples

```pycon
>>> models = ModelStore()
>>> models.discover(verbose=False)
>>> info = models.get_info('openai/gpt-4o')
>>> info.context_size
128000
```

#### recommend(, task='chat', max_cost_per_mtok=None, min_context_size=None, prefer_local=False)

Get recommended models based on requirements.

* **Parameters:**
  * **task** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Primary task (‘chat’, ‘embedding’, etc.)
  * **max_cost_per_mtok** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Maximum cost per million tokens
  * **min_context_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Minimum required context size
  * **prefer_local** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Prefer local models if available
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of recommended models, sorted by suitability

### Examples

```pycon
>>> models = ModelStore()
>>> recommendations = models.recommend(
...     task='chat',
...     max_cost_per_mtok=5.0,
...     min_context_size=16000
... )
```

#### search(query)

Search models by text query.

Searches in model ID, provider, and tags.

* **Parameters:**
  **query** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Search query
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of matching models

### Examples

```pycon
>>> models = ModelStore()
>>> models.discover(verbose=False)
>>> results = models.search('gpt-4')
>>> len(results) > 0
True
```

### *class* aix.PromptFuncs(model=None, \*\*default_kwargs)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Collection of prompt-based functions.

Provides a namespace for organizing related prompt functions with
attribute-based access.

### Examples

```pycon
>>> funcs = PromptFuncs()
>>> funcs.add('summarize', "Summarize: {text}")
>>> funcs.add('translate', "Translate {text} to {language}")
>>> funcs.summarize(text="Long article...")
'Summary...'
>>> funcs.translate(text="Hello", language="Spanish")
'Hola'
```

#### add(name, template, , output_schema=None, \*\*kwargs)

Add a function to the collection.

* **Parameters:**
  * **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Function name (will be accessible as attribute)
  * **template** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Prompt template
  * **output_schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – Optional schema for structured output
  * **\*\*kwargs** – Additional parameters for prompt_func
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### keys()

Get all function names.

### *class* aix.ResponseSchema(name, json_schema, wire_schema, strict_compatible, source, wrapped=False, \_coerce_json=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

A normalized response schema: its JSON Schema, name, and validator.

Build it with [`from_schema()`](_autosummary/aix.html.md#aix.ResponseSchema.from_schema); [`aix.complete()`](_autosummary/aix.html.md#aix.complete) does that for you
from `response_schema=`.

#### name

The schema name sent to the provider.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### json_schema

The caller’s JSON Schema dict (what a value must match).

* **Type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

#### wire_schema

What is sent: `json_schema` itself, or wrapped as
`{"value": json_schema}` when its root is not an object.

* **Type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

#### strict_compatible

Whether `wire_schema` satisfies strict-mode rules.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### wrapped

Whether `wire_schema` is the `{"value": ...}` wrapper.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### source

What the caller passed (a dict or a Pydantic model class).

* **Type:**
  [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)

#### *classmethod* from_schema(schema)

Normalize a JSON Schema dict or a Pydantic model class.

* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – For anything else.
  * **jsonschema.SchemaError** – For a malformed JSON Schema dict.
* **Return type:**
  [`ResponseSchema`](_autosummary/aix.structured.html.md#aix.structured.ResponseSchema)

#### instruction()

The prompt text that asks for this schema (JSON / prompt modes, repairs).

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### mode_for(model)

The strongest enforcement mode available for `model` and this schema.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### response_format(mode)

The LiteLLM `response_format` for `mode` (`None` for `"prompt"`).

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

#### validate(text)

Parse and validate a reply; return the value (a model instance for Pydantic).

* **Raises:**
  [**SchemaValidationError**](_autosummary/aix.html.md#aix.SchemaValidationError) – If `text` is not JSON or does not match.
* **Return type:**
  [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)

### *class* aix.RubricVerdict(aspect, match, confidence, note='')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

A vision model’s verdict on a single rubric aspect.

#### aspect

The rubric item this verdict is about (e.g. `"identity"`).

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### match

Whether the candidate matches the reference for this aspect.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### confidence

The model’s self-reported confidence in `[0.0, 1.0]`.

* **Type:**
  [`float`](https://docs.python.org/3/builtins/functions.html#float)

#### note

A short free-text explanation of the verdict.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### *class* aix.Sample(text, payload, finish_reason=None, usage=None, strategy='independent', seed=None, error=None, system_fingerprint=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One drawn answer.

#### text

The raw text of this choice (`""` if its request failed).

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### payload

`parse(text)` when a `parse` function was given, else `text`;
`None` if the request or the parsing failed (see `error`).

* **Type:**
  [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)

#### finish_reason

Why this choice stopped. `"length"` = truncated,
`"content_filter"` = refused/filtered; check it before treating the
payload as a judgement.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### usage

Tokens for the request that produced *only this* sample, or
`None` when it shared a provider-side `n` request (whose usage
cannot be split per choice; see [`Samples.usage`](_autosummary/aix.html.md#aix.Samples.usage)).

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Usage`](_autosummary/aix.html.md#aix.Usage)]

#### strategy

How this sample was drawn: `"provider_n"` or `"independent"`.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### seed

The seed sent with its request, if any.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

#### error

The exception this sample’s request raised (with
`on_error="record"`) or that `parse` raised on its text.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Exception`](https://docs.python.org/3/builtins/exceptions.html#Exception)]

#### system_fingerprint

The serving backend’s fingerprint for its request,
when reported. Seeded samples are only comparable across equal
fingerprints (see [`aix.supports()`](_autosummary/aix.html.md#aix.supports) for whether `seed` is
honoured at all).

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### *property* ok *: [bool](https://docs.python.org/3/builtins/functions.html#bool)*

`True` when the request succeeded and the text parsed (if asked).

### *class* aix.Samples(samples=(), , strategy, usage=None, n_requests=0, n_usage_reports=0, fallback_error=None)

Bases: [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)

The list of [`Sample`](_autosummary/aix.html.md#aix.Sample) returned by [`sample()`](_autosummary/aix.html.md#aix.sample), plus batch facts.

It is a plain `list` otherwise: slicing or concatenating gives a `list`
without the batch attributes, which describe the whole draw only.

#### strategy

`"provider_n"`, `"independent"` or `"mixed"` (provider
`n` topped up with independent calls).

#### usage

Total tokens over every request that reported usage, or `None`
if none did. Compare `n_requests` with `n_usage_reports` to see
whether it is complete.

#### n_requests

How many requests were made (schema repair requests included).

#### n_usage_reports

How many of them reported usage (a completion’s repair
requests are counted with it when it reported usage). A provider
request refused with a 400 (see `fallback_error`) reports none.

#### fallback_error

With `strategy="auto"`: the error that made the
provider-side `n` request fall back to independent requests
(LiteLLM refusing `n`, or the provider rejecting it with a 400),
else `None`.

#### *property* errors *: [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[Exception](https://docs.python.org/3/builtins/exceptions.html#Exception), ...]*

Every recorded error (request or parse), in sample order.

### *exception* aix.SamplingError(message, , samples=None)

Bases: [`Exception`](https://docs.python.org/3/builtins/exceptions.html#Exception)

A request inside [`sample()`](_autosummary/aix.html.md#aix.sample) failed (with `on_error="raise"`).

No request is launched after the first failure, and the ones already in
flight are awaited, so the work already paid for is not lost: `samples`
holds every request that was made, failed ones included (as samples whose
`error` is set) – possibly fewer than `n`. The first failure is
`__cause__`.

### *exception* aix.SchemaValidationError(message, , text='', detail='')

Bases: [`ValueError`](https://docs.python.org/3/builtins/exceptions.html#ValueError)

A reply was not JSON, or did not match the response schema.

#### text

The reply that failed.

#### detail

The parse / validation message (what a repair prompt is told).

### *class* aix.TranscriptionResult(text, language=None, duration=None, segments=None, model=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Result of audio transcription.

Contains the transcribed text and optional metadata like segments and timestamps.

### Examples

```pycon
>>> result = TranscriptionResult(text="Hello world")
>>> print(result.text)
'Hello world'
```

### *class* aix.Usage(prompt_tokens=0, completion_tokens=0, total_tokens=0, cached_prompt_tokens=0, cache_creation_tokens=0, reasoning_tokens=0)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Token counts billed for one call (or summed over several).

`prompt_tokens` / `completion_tokens` / `total_tokens` are the headline
counts. The breakdowns – prompt tokens served from the provider’s cache
(`cached_prompt_tokens`), written to it (`cache_creation_tokens`), and
hidden reasoning tokens inside `completion_tokens` (`reasoning_tokens`)
– are priced differently by most providers, so cost reporting needs them.
Counts a provider did not report are `0`.

Usages add, and `sum` works when you give it a `Usage()` start (so an
empty batch is a zero `Usage`, not the integer `0`):

```pycon
>>> Usage(prompt_tokens=10, completion_tokens=5, total_tokens=15)
Usage(prompt_tokens=10, completion_tokens=5, total_tokens=15, cached_prompt_tokens=0, cache_creation_tokens=0, reasoning_tokens=0)
>>> sum([Usage(1, 2, 3), Usage(10, 20, 30)], Usage()).total_tokens
33
>>> sum([], Usage()) == Usage()
True
```

#### *classmethod* from_response(response)

Read the `usage` block of a LiteLLM response; `None` if absent.

```pycon
>>> u = Usage.from_response({"usage": {"prompt_tokens": 3, "completion_tokens": 4}})
>>> u.prompt_tokens, u.completion_tokens, u.total_tokens
(3, 4, 7)
>>> Usage.from_response({}) is None
True
```

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Usage`](_autosummary/aix.html.md#aix.Usage)]

### aix.animate_image_to_video(image_path, prompt=None, , model=None, duration=3.0, motion_strength=0.5, \*\*kwargs)

Animate a static image into a video.

* **Parameters:**
  * **image_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Path to the source image
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional text prompt to guide the animation
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video generation model to use
  * **duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Animation duration in seconds
  * **motion_strength** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Strength of motion (0.0 to 1.0)
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo object

### Examples

```pycon
>>> from aix.video import animate_image
>>> video = animate_image(
...     "landscape.jpg",
...     prompt="Gentle camera pan across the scene",
...     duration=4
... )
>>> video.save("animated_landscape.mp4")
```

### aix.ask(question, model=None, \*\*kwargs)

Ask a single question and get an answer.

This is a convenience wrapper around chat() for simple Q&A.

* **Parameters:**
  * **question** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The question to ask
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use
  * **\*\*kwargs** – Additional parameters for chat()
* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)
* **Returns:**
  The answer as a string

### Examples

```pycon
>>> from aix.chat import ask
>>> ask("What is the capital of France?")
'The capital of France is Paris.'
```

### aix.batch_chat(prompts, , model=None, batch_size=None, max_workers=None, show_progress=False, on_error='return', \*\*chat_kwargs)

Process multiple chat prompts in batches.

This function processes multiple prompts efficiently by:

1. Chunking prompts into batches
2. Processing batches in parallel where possible
3. Yielding results in the same order as input

* **Parameters:**
  * **prompts** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]]]) – Iterable of prompts (strings or message lists)
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use for all prompts
  * **batch_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of prompts to process in each batch
  * **max_workers** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum number of parallel workers
  * **show_progress** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, print progress information
  * **on_error** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'return'`, `'raise'`, `'skip'`]) – What to do with a prompt whose call raised.
    `'return'` (default) yields a `BatchError` in that slot, keeping
    the stream the same length and order as the input.
    `'raise'` stops after the batch in which the first failure landed
    and re-raises the lowest-indexed exception of that batch.
    `'skip'` omits the failed slots from the stream.
  * **\*\*chat_kwargs** – Additional parameters passed to chat()
* **Yields:**
  Responses in the same order as input prompts. A prompt that raised
  yields a `BatchError` – a `str` subclass equal to `"ERROR: <message>"`,
  carrying the original exception on `.exception`.
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `on_error` is not one of ‘return’, ‘raise’, ‘skip’.
* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### Examples

```pycon
>>> from aix.batches import batch_chat
>>> prompts = [
...     "What is 2+2?",
...     "What is 3+3?",
...     "What is 5+5?"
... ]
>>> results = list(batch_chat(prompts))
>>> len(results)
3
```

```pycon
>>> # With specific model
>>> results = list(batch_chat(
...     prompts,
...     model="gpt-4o-mini",
...     batch_size=5
... ))
```

```pycon
>>> # Process large dataset
>>> def generate_prompts():
...     for i in range(100):
...         yield f"Explain concept {i}"
>>> results = batch_chat(
...     generate_prompts(),
...     show_progress=True
... )
>>> for i, result in enumerate(results):
...     print(f"Result {i}: {result[:50]}...")
```

```pycon
>>> # Tell a failure apart from a reply that starts with "ERROR:"
>>> for result in batch_chat(prompts):
...     if isinstance(result, BatchError):
...         raise result.exception
```

### aix.batch_embeddings(segments, , model=None, batch_size=None, show_progress=False, \*\*embedding_kwargs)

Generate embeddings for multiple texts in batches.

For efficiency, this function processes embeddings in chunks,
as most embedding APIs can handle multiple texts per request.

* **Parameters:**
  * **segments** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Iterable of text strings to embed
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Embedding model to use
  * **batch_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of texts per batch
  * **show_progress** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, print progress information
  * **\*\*embedding_kwargs** – Additional parameters for embeddings()
* **Yields:**
  Vector embeddings in the same order as input
* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]]

### Examples

```pycon
>>> from aix.batches import batch_embeddings
>>> texts = ["hello", "world", "foo", "bar"] * 25  # 100 texts
>>> vectors = list(batch_embeddings(
...     texts,
...     batch_size=10,
...     show_progress=True
... ))
>>> len(vectors)
100
```

```pycon
>>> # Process large dataset efficiently
>>> def read_documents():
...     # Generator that yields documents
...     for i in range(1000):
...         yield f"Document {i} content"
>>> all_vectors = []
>>> for vec in batch_embeddings(read_documents()):
...     all_vectors.append(vec)
```

### aix.batch_process(items, process_func, , batch_size=None, max_workers=None, show_progress=False, retry_attempts=None, retry_delay=None, on_error='return')

Generic batch processing with parallel execution and retries.

This is a general-purpose batch processor that can be used for
any operation, not just chat or embeddings.

* **Parameters:**
  * **items** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – Items to process
  * **process_func** (`callable`) – Function to apply to each item
  * **batch_size** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Batch size for chunking
  * **max_workers** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum parallel workers
  * **show_progress** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Show progress information
  * **retry_attempts** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of retry attempts on failure
  * **retry_delay** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Delay between retries (seconds)
  * **on_error** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'return'`, `'raise'`, `'skip'`]) – What to do with an item still failing after every retry.
    `'return'` (default) yields a `BatchError` in that slot, `'raise'`
    re-raises, `'skip'` omits it. See [`batch_chat()`](_autosummary/aix.html.md#aix.batch_chat).
* **Yields:**
  Results in same order as input. An item that raised yields a
  `BatchError` – a `str` subclass equal to `"ERROR: <message>"`,
  carrying the original exception on `.exception`.
* **Raises:**
  [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `on_error` is not one of ‘return’, ‘raise’, ‘skip’.
* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]

### Examples

```pycon
>>> from aix.batches import batch_process
>>> from aix.chat import chat
```

```pycon
>>> # Custom processing function
>>> def analyze_sentiment(text):
...     return chat(f"Analyze sentiment: {text}")
```

```pycon
>>> texts = ["I love this!", "This is terrible", "It's okay"]
>>> results = list(batch_process(
...     texts,
...     analyze_sentiment,
...     batch_size=5
... ))
```

```pycon
>>> # With retries for flaky operations
>>> def flaky_api_call(item):
...     # Some API that might fail
...     return call_api(item)
```

```pycon
>>> results = batch_process(
...     items,
...     flaky_api_call,
...     retry_attempts=3,
...     retry_delay=2.0
... )
```

### aix.call_logger(logger)

Log calls made inside the `with` block to `logger`.

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterator)[[`None`](https://docs.python.org/3/builtins/constants.html#None)]

### aix.chat(prompt, , model=None, temperature=None, max_tokens=None, stream=False, api_key=None, \*\*kwargs)

Send a chat prompt and get a response.

This is the main chat interface for AIX. It abstracts away provider-specific
details and provides a clean, consistent API across all models.

* **Parameters:**
  * **prompt** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]]) – Either a string (becomes a user message) or a list of message dicts
    with ‘role’ and ‘content’ keys
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model identifier (e.g., ‘gpt-4o’, ‘claude-sonnet-4’,
    ‘openrouter/anthropic/claude-3.5-sonnet’). If None, uses default.
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Sampling temperature (0.0 = deterministic, 2.0 = creative).
    If None, uses default (1.0).
  * **max_tokens** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum tokens to generate. If None, uses model’s default.
  * **stream** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, return an iterator of text chunks. If False, return
    complete response as string.
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Explicit API key. If None, resolved from the environment / .env
    / AIX config store for the model’s provider (see aix.credentials).
  * **on_call** – Optional `fn(CallRecord)` called after the call with the resolved
    model, the caller and the outcome (opt-in call log, see [`aix.calllog`](_autosummary/aix.calllog.html.md#module-aix.calllog)).
  * **\*\*kwargs** – Additional provider-specific parameters passed to LiteLLM
* **Returns:**
  Complete response as string
  If stream=True: Iterator yielding text chunks as they arrive
* **Return type:**
  [`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]
* **Raises:**
  * [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If prompt format is invalid

### Examples

```pycon
>>> chat("What is Python?")
'Python is a high-level programming language...'
```

```pycon
>>> chat("Hello", model="gpt-4o")
'Hello! How can I assist you today?'
```

```pycon
>>> # Streaming response
>>> for chunk in chat("Count to 5", stream=True):
...     print(chunk, end='', flush=True)
1, 2, 3, 4, 5
```

```pycon
>>> # With message history
>>> messages = [
...     {"role": "system", "content": "You are a helpful assistant."},
...     {"role": "user", "content": "What is 2+2?"}
... ]
>>> chat(messages)
'2+2 equals 4.'
```

### aix.chat_with_history(system_prompt=None, , model=None, \*\*chat_kwargs)

Create a stateful chat session that maintains conversation history.

* **Parameters:**
  * **system_prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional system message to set context/behavior
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use for this session
  * **\*\*chat_kwargs** – Additional parameters passed to chat()
* **Return type:**
  [`ChatSession`](_autosummary/aix.html.md#aix.ChatSession)
* **Returns:**
  ChatSession object with send() method

### Examples

```pycon
>>> session = chat_with_history("You are a helpful math tutor")
>>> session.send("What is 2+2?")
'The answer is 4.'
>>> session.send("And if I add 3 to that?")
'That would be 7.'
>>> len(session.history)
5
```

### aix.check_keys(providers=None)

Report, per provider, whether a usable API key is discoverable.

Never returns or logs key *values* – only availability and the env-var
name(s) checked. Useful for quick setup debugging.

* **Parameters:**
  **providers** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]) – Providers to check; defaults to every provider in
  `PROVIDER_ENV_VARS`.
* **Returns:**
  bool, “env_vars”: […],
  “source”: <where-found-or-None>}\`\`. `source` is `"env"`, `"store"`,
  or `None` (never the value itself).
* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

### Examples

```pycon
>>> report = check_keys(["openai"])
>>> report["openai"]["available"]
True
```

### aix.check_requirements(model_or_provider, , api_key=None)

Presence-only preflight: ensure a key for `model_or_provider` is resolvable.

Does *not* validate the key over the network – only that one is discoverable
via [`resolve_api_key()`](_autosummary/aix.html.md#aix.resolve_api_key) (explicit arg, env/.env, or store). Raises
[`MissingCredentialError`](_autosummary/aix.html.md#aix.MissingCredentialError) with actionable guidance when absent.

Returns `True` when a key is available, or when the model is local and
needs none (`is_keyless()`, e.g. `ollama/...`).

### Examples

```pycon
>>> check_requirements("gpt-4o", api_key="sk-explicit")
True
>>> check_requirements("ollama/mistral")
True
```

* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

### aix.compare_images(candidate, reference, , rubric=('identity', 'costume', 'setting', 'lighting', 'props'), model=None, api_key=None, max_tokens=None, temperature=0.0, detail=None, instruction='You are a strict visual continuity supervisor. The FIRST image is the CANDIDATE; the remaining image(s) are the locked REFERENCE the candidate must match. Judge each rubric aspect INDEPENDENTLY (do not let one aspect color another). For each aspect decide whether the candidate matches the reference, give a confidence in [0.0, 1.0], and a short note explaining what matches or drifts. Then give an overall match (true only if every important aspect matches), an overall confidence, and a one-sentence explanation.', \*\*kwargs)

Compare a `candidate` image to `reference` image(s) on a rubric.

The explainable half of a reference supervisor: a vision model returns a
per-aspect pass/fail checklist (does the face match? the costume? the set?
the lighting? the props?) plus an overall verdict — the explainable layer
over a cheap numeric identity-cosine gate (which lives elsewhere, e.g.
lookbook). Built on [`to_image_content()`](_autosummary/aix.html.md#aix.to_image_content) (multi-image content block)
and the same multimodal `completion` path as [`describe_image()`](_autosummary/aix.html.md#aix.describe_image),
asked via a JSON contract for a structured answer.

The comparison is *pointwise* (each aspect judged on its own), not a ranked
pairwise comparison, to avoid position bias.

* **Parameters:**
  * **candidate** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – The image under review (URL / path / bytes / PIL image /
    `data:` URI — anything [`to_image_content()`](_autosummary/aix.html.md#aix.to_image_content) accepts).
  * **reference** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any), [`Sequence`](https://docs.python.org/3/library/typing.html#typing.Sequence)[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]]) – The locked reference — a single image *or* a sequence of
    images (a locked set) in the same flexible formats. An empty
    sequence is an error.
  * **rubric** ([`Sequence`](https://docs.python.org/3/library/typing.html#typing.Sequence)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – The aspects to evaluate, one verdict per item. Defaults to
    `DFLT_COMPARE_RUBRIC`; pass `DFLT_FILM_RUBRIC` (or any
    custom sequence) to override — e.g. `("face", "architecture",
    "props", "lighting")`. Must be non-empty.
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Vision-capable model id or alias. `None` → the configured
    default ([`aix.config.VisionConfig`](_autosummary/aix.config.html.md#aix.config.VisionConfig)).
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Explicit API key; `None` resolves it for the model’s
    provider from the environment / `.env` / config store.
  * **max_tokens** ([`int`](https://docs.python.org/3/builtins/functions.html#int) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Cap on generated tokens (`None` → provider default).
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Sampling temperature (default `0.0` for a stable,
    reproducible verdict; `None` → provider default).
  * **detail** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Image detail hint (`"low"` | `"high"` | `"auto"`),
    applied to every image block.
  * **instruction** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The system-style framing prepended to the rubric. Has a
    sensible default; override to retune the supervisor’s strictness.
  * **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any)) – Extra provider-specific params forwarded to LiteLLM.
* **Return type:**
  [`ImageComparison`](_autosummary/aix.vision.html.md#aix.vision.ImageComparison)
* **Returns:**
  An [`ImageComparison`](_autosummary/aix.html.md#aix.ImageComparison) — overall `match` / `confidence` /
  `explanation` plus an ordered, mapping-like collection of
  [`RubricVerdict`](_autosummary/aix.html.md#aix.RubricVerdict) (one per rubric aspect, keyed by aspect).
* **Raises:**
  * [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `rubric` is empty or `reference` is an empty
        sequence, or if the model’s reply can’t be parsed as the expected
        JSON verdict.

### Examples

Default rubric, single reference:

```pycon
>>> compare_images("gen.png", "ref.png")
ImageComparison(match=True, confidence=0.9, ...)
```

Filmmaking rubric, a locked reference *set*:

```pycon
>>> from aix.vision import DFLT_FILM_RUBRIC
>>> compare_images(
...     candidate="frame_042.png",
...     reference=["ref_front.png", "ref_side.png"],
...     rubric=DFLT_FILM_RUBRIC,
... )["face_identity"].match
True
```

### aix.complete(prompt, , model=None, temperature=None, max_tokens=None, n=1, seed=None, response_format=None, response_schema=None, max_repairs=None, api_key=None, \*\*kwargs)

Send a chat prompt and get the whole response back as a [`Completion`](_autosummary/aix.html.md#aix.Completion).

The non-lossy sibling of [`chat()`](_autosummary/aix.html.md#aix.chat): same inputs and defaults, but instead
of the first choice’s text it returns every choice (`texts`), why each one
stopped (`finish_reasons`), the tokens billed (`usage`), the model that
served the call, and the raw response.

* **Parameters:**
  * **prompt** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]]) – A string (becomes a user message) or a list of message dicts.
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model identifier or alias. If None, uses the configured default.
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Sampling temperature. If None, uses the configured default.
  * **max_tokens** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum tokens per choice. If None, uses the configured default.
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – How many choices to ask the provider for in this one call. Only
    sent when `n != 1`; providers without native `n` support reject
    it (see LiteLLM’s `get_supported_openai_params`).
  * **seed** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Best-effort reproducibility seed. Only sent when given. Support is
    provider-dependent (`aix.supports(model, "seed")`); where it is
    unsupported LiteLLM either drops it or rejects the call, and where
    it is supported determinism is still best-effort – compare
    `system_fingerprint` across calls before reading a difference
    as model instability.
  * **response_format** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – Passed through to LiteLLM (e.g. `{"type": "json_object"}`).
    Mutually exclusive with `response_schema`.
  * **response_schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – A JSON Schema dict or a Pydantic model class. The
    provider is asked to enforce it as strongly as the model allows
    (strict `json_schema` > non-strict `json_schema` > JSON mode plus
    the schema in the prompt; see [`aix.structured`](_autosummary/aix.structured.html.md#module-aix.structured)), and every
    choice is validated client-side into `values` / `errors`.
  * **max_repairs** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – With `response_schema`: how many times to re-ask for an
    invalid choice, showing the model its error (`None` = config
    `chat.schema_max_repairs`; `0` disables repair).
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Explicit API key; otherwise resolved as for [`chat()`](_autosummary/aix.html.md#aix.chat).
  * **\*\*kwargs** – Additional provider-specific parameters passed to LiteLLM.
* **Return type:**
  [`Completion`](_autosummary/aix.html.md#aix.Completion)
* **Returns:**
  A [`Completion`](_autosummary/aix.html.md#aix.Completion).
* **Raises:**
  * [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `n` is not a positive integer, or the prompt is invalid.

### Examples

```pycon
>>> c = complete("Name a color", n=3)
>>> c.texts, c.finish_reasons
(('Blue', 'Green', 'Red'), ('stop', 'stop', 'stop'))
>>> c.usage
Usage(prompt_tokens=11, completion_tokens=6, total_tokens=17)
>>> complete("Write an essay", max_tokens=5).finish_reason
'length'
```

Structured output, validated:

```pycon
>>> from pydantic import BaseModel
>>> class Verdict(BaseModel):
...     label: str
...     confidence: float
>>> c = complete("Is the sky green?", response_schema=Verdict)
>>> c.value, c.schema_mode
(Verdict(label='no', confidence=0.99), 'strict')
```

### aix.configure(\*\*overrides)

Apply runtime overrides to the active config and return it.

### Examples

```pycon
>>> 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`](_autosummary/aix.config.html.md#aix.config.AixConfig)

### aix.constrained_answer(prompt, valid_answers, , model=None, temperature=None, enhance_prompt=False, n=1, on_violation='raise', max_retries=0, concurrency=None)

Get an answer from the LLM constrained to a set of valid answers or types.

Uses JSON mode to ensure the LLM returns a valid response based on constraints.
More flexible than the oa version - works with any model that supports JSON mode
via LiteLLM.

This can be seen as a facade for some common structured output use cases, as well
as a convenient tool to do response statistics and validation (via n>1).

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The question or prompt to ask the LLM
  * **valid_answers** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)], [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`int`](https://docs.python.org/3/builtins/functions.html#int)], [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`float`](https://docs.python.org/3/builtins/functions.html#float)], [`type`](https://docs.python.org/3/builtins/functions.html#type), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`float`](https://docs.python.org/3/builtins/functions.html#float), [`float`](https://docs.python.org/3/builtins/functions.html#float)]]) – 

    Can be:
    - list[str]: List of valid string options
    - list[int]: List of valid integer options
    - list[float]: List of valid float options
    - bool: Constrains answer to True or False
    - int: Any integer
    - float: Any number
    - tuple[float, float]: Numerical range (min, max) inclusive
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The model to use for the LLM (default: uses DFLT_CHAT_MODEL)
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Temperature for sampling (default: None, uses model’s default).
    Higher values (e.g., 1.0) give more random/varied results.
    Lower values (e.g., 0.0) give more deterministic results.
  * **enhance_prompt** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, adds explicit instructions to the prompt about
    JSON formatting and constraints. If False (default), relies on
    response_format alone. Default is False to match oa behavior.
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of times to call the LLM (default: 1). The `n` calls are
    independent and run concurrently (see `concurrency`); each is
    validated (and retried) on its own. On the first failure no new
    call is started, but calls already in flight finish (and are
    billed) before the error propagates. For raw samples with finish
    reasons and usage, use [`aix.sample()`](_autosummary/aix.html.md#aix.sample).
  * **on_violation** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'raise'`, `'return'`]) – What to do when the model’s answer does not satisfy
    `valid_answers`. `'raise'` (default) raises `ConstraintViolation`.
    `'return'` returns the model’s value unchecked – the behaviour of
    this function before enforcement existed, kept as an escape hatch.
  * **max_retries** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – How many times to re-ask the model after a violation
    before giving up (default: 0, i.e. ask exactly once). Ignored when
    `on_violation='return'`, which never detects a violation.
  * **concurrency** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Max simultaneous calls when `n > 1` (default: config
    `chat.sample_concurrency`).
* **Returns:**
  One of the valid answers, respecting the type constraint.
  If n > 1, returns a list of answers.
* **Raises:**
  * [**ConstraintViolation**](_autosummary/aix.html.md#aix.ConstraintViolation) – If the answer is not a member of an options list,
        falls outside a `(min, max)` range, or cannot be converted to the
        declared type – unless `on_violation='return'`.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If the response is not JSON, or has no “answer” field.

### Examples

```pycon
>>> # String options
>>> answer = constrained_answer(
...     "Is Python compiled or interpreted?",
...     ["compiled", "interpreted", "both"]
... )
>>> answer in ["compiled", "interpreted", "both"]
True
```

```pycon
>>> # Boolean
>>> answer = constrained_answer(
...     "Is Python dynamically typed?",
...     bool
... )
>>> isinstance(answer, bool)
True
```

```pycon
>>> # Integer options
>>> answer = constrained_answer(
...     "How many wheels does a car have?",
...     [2, 3, 4, 6, 8]
... )
>>> answer in [2, 3, 4, 6, 8]
True
```

```pycon
>>> # Numerical range
>>> answer = constrained_answer(
...     "What is a reasonable hourly rate for a senior Python developer? (USD)",
...     (50.0, 300.0)
... )
>>> 50.0 <= answer <= 300.0
True
```

```pycon
>>> # Multiple samples for statistics
>>> answers = constrained_answer(
...     "Which is better: cats or dogs?",
...     ["cats", "dogs"],
...     n=10
... )
>>> len(answers)
10
```

```pycon
>>> # Tolerate an off-constraint answer instead of raising
>>> answer = constrained_answer(
...     "Is Python compiled or interpreted?",
...     ["compiled", "interpreted"],
...     on_violation="return",
... )
```

### aix.cosine_similarity(vec1, vec2)

Compute cosine similarity between two vectors.

* **Parameters:**
  * **vec1** ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]) – First vector
  * **vec2** ([`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]) – Second vector
* **Return type:**
  [`float`](https://docs.python.org/3/builtins/functions.html#float)
* **Returns:**
  Cosine similarity (between -1 and 1)

### Examples

```pycon
>>> from aix.embeddings import embed, cosine_similarity
>>> v1 = embed("cat")
>>> v2 = embed("kitten")
>>> similarity = cosine_similarity(v1, v2)
>>> similarity > 0.8
True
```

### aix.create_variation(image_path, , model=None, size=None, n=1, api_key=None, \*\*kwargs)

Create variations of an existing image.

* **Parameters:**
  * **image_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Path to the source image
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use (`None` = configured `image.variation_model`)
  * **size** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Output image size
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of variations to generate
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage)]]
* **Returns:**
  GeneratedImage or list of GeneratedImage objects

### Examples

```pycon
>>> from aix.image import create_variation
>>> variations = create_variation(
...     "original.png",
...     n=3,
...     size="512x512"
... )
>>> for i, var in enumerate(variations):
...     var.save(f"variation_{i}.png")
```

### aix.describe_image(image, , prompt='Describe this image in detail.', model=None, api_key=None, max_tokens=None, temperature=None, detail=None, \*\*kwargs)

Describe (or answer a question about) `image` and return the text.

The image→text primitive. `image` accepts a URL, a local path, raw bytes,
a PIL image, or a `data:` URI (see [`to_image_content()`](_autosummary/aix.html.md#aix.to_image_content)). `prompt` is
the instruction (default: a generic “describe this image”); pass a question
for VQA or a rubric for a judgement. Everything past `image` is keyword.

* **Parameters:**
  * **image** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – The image (URL / path / bytes / PIL image / `data:` URI).
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The text instruction accompanying the image.
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Vision-capable model id (e.g. `gpt-4o`, `claude-sonnet-4-6`,
    `gemini/gemini-1.5-pro`) or an alias. `None` → the configured
    default ([`aix.config.VisionConfig`](_autosummary/aix.config.html.md#aix.config.VisionConfig)).
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Explicit API key; `None` resolves it from the environment /
    `.env` / config store for the model’s provider.
  * **max_tokens** ([`int`](https://docs.python.org/3/builtins/functions.html#int) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Cap on generated tokens (`None` → provider default).
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Sampling temperature (`None` → provider default).
  * **detail** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Image detail hint (`"low"` | `"high"` | `"auto"`).
  * **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any)) – Extra provider-specific params forwarded to LiteLLM.
* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)
* **Returns:**
  The model’s text response.
* **Raises:**
  [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed.

```pycon
>>> describe_image("cat.jpg", prompt="Caption it.")
'A cat on a sofa.'
```

For usage, several samples (`n`) or validated structured output, send the
same image content through [`aix.complete()`](_autosummary/aix.html.md#aix.complete) (or [`aix.sample()`](_autosummary/aix.html.md#aix.sample)):

```pycon
>>> from aix import complete
>>> c = complete([{"role": "user", "content": [
...     {"type": "text", "text": "Caption it."}, to_image_content("cat.jpg")]}],
...     model="gpt-4o-mini", n=3)
>>> c.texts, c.usage
```

### aix.discover_available_models(source='openrouter', verbose=True)

Discover available models from a source.

Convenience function that uses the global models instance.

* **Parameters:**
  * **source** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Source name (‘openrouter’, ‘ollama’, etc.)
  * **verbose** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – Print progress information
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of discovered models

### Examples

```pycon
>>> from aix.models import discover_available_models
>>> models = discover_available_models('openrouter')
>>> len(models) > 100
True
```

### aix.edit_image(image_path, prompt, , mask_path=None, model=None, size=None, n=1, api_key=None, \*\*kwargs)

Edit an existing image based on a prompt.

* **Parameters:**
  * **image_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Path to the image to edit
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Description of the desired edit
  * **mask_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Optional path to mask image (transparent areas will be edited)
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use (`None` = configured `image.edit_model`)
  * **size** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Output image size
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of variations to generate
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage)]]
* **Returns:**
  GeneratedImage or list of GeneratedImage objects

### Examples

```pycon
>>> from aix.image import edit_image
>>> edited = edit_image(
...     "photo.png",
...     "Add a rainbow in the sky",
...     mask_path="sky_mask.png"
... )
>>> edited.save("edited_photo.png")
```

### aix.embed(text, , model=None, \*\*kwargs)

Generate embedding for a single text.

Convenience function for embedding a single text string.

* **Parameters:**
  * **text** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text string to embed
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model identifier
  * **\*\*kwargs** – Additional parameters for embeddings()
* **Return type:**
  [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]
* **Returns:**
  Vector embedding as sequence of floats

### Examples

```pycon
>>> from aix.embeddings import embed
>>> vec = embed("Hello, world!")
>>> len(vec)
1536
```

```pycon
>>> # Compare similarity
>>> import numpy as np
>>> v1 = np.array(embed("cat"))
>>> v2 = np.array(embed("kitten"))
>>> v3 = np.array(embed("computer"))
>>> # Cosine similarity
>>> np.dot(v1, v2) / (np.linalg.norm(v1) * np.linalg.norm(v2))
0.92  # High similarity
>>> np.dot(v1, v3) / (np.linalg.norm(v1) * np.linalg.norm(v3))
0.23  # Low similarity
```

### aix.embeddings(segments, , model=None, api_key=None, \*\*kwargs)

Generate embeddings for multiple text segments.

This is the main embedding interface for AIX. It abstracts away provider-specific
details and provides a clean, consistent API across all embedding models.

* **Parameters:**
  * **segments** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Iterable of text strings to embed
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model identifier (e.g., ‘text-embedding-3-small’, ‘text-embedding-ada-002’,
    ‘openrouter/openai/text-embedding-3-small’). If None, uses default.
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Explicit API key. If None, resolved from the environment / .env
    / AIX config store for the model’s provider (see aix.credentials).
  * **\*\*kwargs** – Additional provider-specific parameters passed to LiteLLM
* **Yields:**
  Vector embeddings as sequences of floats. Each embedding corresponds to
  one input segment in the same order.
* **Raises:**
  * [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If segments is empty or invalid
* **Return type:**
  [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]]

### Examples

```pycon
>>> from aix.embeddings import embeddings
>>> texts = ["cat", "dog", "bird"]
>>> vecs = list(embeddings(texts))
>>> len(vecs)
3
```

```pycon
>>> # With specific model
>>> vecs = list(embeddings(
...     ["hello", "world"],
...     model="text-embedding-3-large"
... ))
```

```pycon
>>> # Process in chunks for large datasets
>>> def chunk_texts(texts, size=100):
...     for i in range(0, len(texts), size):
...         yield texts[i:i+size]
>>> all_vecs = []
>>> for chunk in chunk_texts(large_dataset):
...     all_vecs.extend(embeddings(chunk))
```

### aix.extend_video(video_path, prompt=None, , extend_duration=2.0, model=None, \*\*kwargs)

Extend an existing video with additional generated content.

* **Parameters:**
  * **video_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Path to the source video
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional text prompt to guide the extension
  * **extend_duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – How many seconds to add
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video generation model
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo object with extended content

### Examples

```pycon
>>> from aix.video import extend_video
>>> extended = extend_video(
...     "original.mp4",
...     prompt="Continue the same scene",
...     extend_duration=3
... )
```

### aix.find_models(query)

Search for models matching a query.

Convenience function that uses the global models instance.

* **Parameters:**
  **query** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Search query
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)]
* **Returns:**
  List of matching models

### Examples

```pycon
>>> from aix.models import find_models
>>> results = find_models('claude')
>>> any('claude' in m.id.lower() for m in results)
True
```

### aix.find_most_similar(query, candidates, , model=None, top_k=5, \*\*kwargs)

Find most similar texts to a query.

* **Parameters:**
  * **query** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Sequence`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Sequence)[[`float`](https://docs.python.org/3/builtins/functions.html#float)]]) – Query text or pre-computed embedding vector
  * **candidates** ([`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Candidate texts to compare against
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Embedding model to use
  * **top_k** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of top results to return
  * **\*\*kwargs** – Additional parameters for embeddings()
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`float`](https://docs.python.org/3/builtins/functions.html#float)]]
* **Returns:**
  List of (text, similarity_score) tuples, sorted by similarity (highest first)

### Examples

```pycon
>>> query = "What is machine learning?"
>>> docs = [
...     "Machine learning is a type of AI",
...     "Python is a programming language",
...     "Neural networks are used in deep learning",
... ]
>>> results = find_most_similar(query, docs, top_k=2)
>>> results[0][0]  # Most similar doc
'Machine learning is a type of AI'
```

### aix.generate_image(prompt, , model=None, size=None, quality=None, style=None, response_format=None, api_key=None, \*\*kwargs)

Generate a single image from a text prompt.

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text description of the image to generate
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use (e.g., ‘openai/gpt-image-1.5’, ‘openai/gpt-image-1-mini’, ‘stable-diffusion’)
  * **size** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image size (e.g., ‘1024x1024’, ‘512x512’, ‘1792x1024’)
  * **quality** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image quality (‘standard’ or ‘hd’ for DALL-E 3)
  * **style** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image style (‘vivid’ or ‘natural’ for DALL-E 3)
  * **response_format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Format of response (‘url’ or ‘b64_json’). Left out of the
    request when None, since some providers and models (OpenAI’s gpt-image
    models, and the images endpoint as of 2026) reject the parameter.
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Explicit API key. If None, resolved from the environment / .env
    / AIX config store for the model’s provider (see aix.credentials).
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage)
* **Returns:**
  GeneratedImage object
* **Raises:**
  [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed

### Examples

```pycon
>>> from aix.image import generate_image
>>> image = generate_image("A serene mountain landscape")
>>> image.save("landscape.png")
```

```pycon
>>> # High quality with DALL-E 3
>>> image = generate_image(
...     "Abstract art with vibrant colors",
...     model="gpt-image-1.5",
...     quality="high",
... )
```

```pycon
>>> # Specific size
>>> image = generate_image(
...     "A futuristic city",
...     size="1792x1024"
... )
```

### aix.generate_images(prompt, , n=None, model=None, size=None, quality=None, style=None, response_format=None, api_key=None, \*\*kwargs)

Generate multiple images from a text prompt.

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text description of images to generate
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of images to generate
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use
  * **size** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image size
  * **quality** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image quality
  * **style** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image style
  * **response_format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Format of response, sent only when given
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage)]
* **Returns:**
  List of GeneratedImage objects

### Examples

```pycon
>>> from aix.image import generate_images
>>> images = generate_images(
...     "A cute robot",
...     n=3,
...     size="512x512"
... )
>>> for i, img in enumerate(images):
...     img.save(f"robot_{i}.png")
```

### aix.generate_video(prompt, , model=None, duration=5.0, resolution='1280x720', fps=24, aspect_ratio=None, style=None, seed=None, api_key=None, \*\*kwargs)

Generate a video from a text prompt.

#### NOTE
This is a high-level interface. Actual implementation depends on
available video generation providers (Runway, Pika, etc.) and may require
provider-specific API keys.

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text description of the video to generate
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video generation model to use
  * **duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Video duration in seconds (typically 2-10 seconds)
  * **resolution** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video resolution (‘1280x720’, ‘1920x1080’, etc.)
  * **fps** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Frames per second
  * **aspect_ratio** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Aspect ratio (‘16:9’, ‘9:16’, ‘1:1’, etc.)
  * **style** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video style hint (provider-specific)
  * **seed** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Random seed for reproducibility
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Explicit API key for the video provider. If None, resolved from
    the environment / .env / AIX config store (see aix.credentials).
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo object
* **Raises:**
  * [**NotImplementedError**](https://docs.python.org/3/builtins/exceptions.html#NotImplementedError) – If no video provider is configured
  * [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If required provider SDK is not installed

### Examples

```pycon
>>> from aix.video import generate_video
>>> video = generate_video(
...     "A serene ocean sunset with gentle waves",
...     duration=5,
...     resolution="1920x1080"
... )
>>> video.save("sunset.mp4")
```

```pycon
>>> # Specific style
>>> video = generate_video(
...     "A futuristic city",
...     style="cyberpunk",
...     duration=4
... )
```

### aix.get_config()

Return the current active [`AixConfig`](_autosummary/aix.html.md#aix.AixConfig).

Inside a [`using()`](_autosummary/aix.html.md#aix.using) block this is the scoped config of the current thread or
asyncio task; otherwise the process-wide config.

* **Return type:**
  [`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig)

### aix.get_model_info(model_id)

Get information about a specific model.

Convenience function that uses the global models instance.

* **Parameters:**
  **model_id** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model identifier
* **Return type:**
  [`Model`](_autosummary/aix.ai_models.base.html.md#aix.ai_models.base.Model)
* **Returns:**
  Model object

### Examples

```pycon
>>> from aix.models import get_model_info
>>> info = get_model_info('openai/gpt-4o')
>>> info.provider
'openai'
```

### aix.get_video_providers()

Get list of available video generation providers.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]
* **Returns:**
  List of provider names that are configured

### Examples

```pycon
>>> from aix.video import get_available_providers
>>> providers = get_available_providers()
>>> print(providers)
['runway', 'pika']
```

### aix.jsonl_logger(path)

A logger that appends one JSON line per call to `path`.

* **Return type:**
  [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[`CallRecord`](_autosummary/aix.calllog.html.md#aix.calllog.CallRecord)], [`None`](https://docs.python.org/3/builtins/constants.html#None)]

### aix.load_config(path=None, , environ=None)

Resolve an [`AixConfig`](_autosummary/aix.html.md#aix.AixConfig) from shipped defaults, TOML file, and env.

Precedence (low to high): shipped defaults < TOML file < environment variables.
Runtime overrides ([`configure()`](_autosummary/aix.html.md#aix.configure)/[`using()`](_autosummary/aix.html.md#aix.using)) and explicit call arguments
sit above this and are applied elsewhere.

* **Parameters:**
  * **path** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Optional explicit TOML path. Defaults to `config_file_path()`.
  * **environ** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Mapping`](https://docs.python.org/3/library/typing.html#typing.Mapping)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]]) – Optional environment mapping (defaults to `os.environ`).
* **Return type:**
  [`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig)
* **Returns:**
  A fully resolved [`AixConfig`](_autosummary/aix.html.md#aix.AixConfig).

### aix.prompt_func(template, , output_schema=None, response_schema=None, egress=None, model=None, temperature=None, name=None, \*\*chat_kwargs)

Create a callable function from a prompt template.

This is the main function for creating prompt-based functions. It automatically
detects parameters from the template and creates a function with those parameters.

Without output_schema: Returns text
With output_schema: Returns structured data (dict, list, etc.)
With egress: Returns whatever the egress post-processor returns.

Templates use the default-aware `{name:default}` dialect (matching
`oa.prompt_function`): `{name}` is a required parameter, `{name:default}`
supplies a default value (the text after the colon), and braces inside
`` fenced `` regions are left literal. Plain `{name}`-only templates behave
exactly as before.

```pycon
>>> greet = prompt_func("Greet {name} in {language:English}")
>>> greet.param_names
['name', 'language']
```

The signature lists every template field, keyword-only, with its default:

```pycon
>>> from inspect import signature
>>> str(signature(prompt_func("{a} {b:x}")))
"(*, a: str, b: str = 'x')"
```

* **Parameters:**
  * **template** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Prompt template with {var} placeholders for parameters
  * **output_schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – Optional schema for structured output. Can be:
    - Dict mapping field names to types: {“name”: str, “age”: int}
    - A single type for simple outputs: str, int, list, etc.
    - None for plain text output (default)
  * **response_schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – Optional JSON Schema dict or Pydantic model class for
    *enforced, validated* structured output (nested objects, arrays,
    enums, required/optional all work): routed to the provider’s
    strict `json_schema` mode where supported, otherwise JSON mode,
    then validated client-side with a bounded repair retry (see
    [`aix.complete()`](_autosummary/aix.html.md#aix.complete)). The function returns the validated value (a
    model instance for a Pydantic schema) or raises
    `aix.SchemaValidationError`. Prefer it over `output_schema`,
    which is flat, prompt-only and unvalidated; pass one or the other.
  * **egress** ([`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any)], [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – Optional post-processor `(result) -> Any` applied to the output
    before returning — on both the text and structured paths. Lets a caller
    keep “prompt → typed Python value” inside the facade (e.g. parse the
    LLM text into a list of lines/ids) instead of wrapping the returned
    function. `None` (default) returns the raw result unchanged.
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use for this function
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Temperature for generation
  * **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional `__name__` for the generated function (for tracing /
    identity). Defaults to `"prompt_based_function"`.
  * **\*\*chat_kwargs** – Additional parameters passed to chat()
* **Return type:**
  [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)
* **Returns:**
  Callable function with parameters derived from template

### Examples

```pycon
>>> # Simple text generation
>>> summarize = prompt_func("Summarize this text: {text}")
>>> summarize(text="Long article...")
'Brief summary...'
```

```pycon
>>> # Structured output
>>> extract = prompt_func(
...     "Extract contact info from: {text}",
...     output_schema={"name": str, "email": str, "phone": str}
... )
>>> result = extract(text="Contact John at john@example.com, 555-1234")
>>> result['name']
'John'
```

```pycon
>>> # Multiple parameters
>>> compare = prompt_func(
...     "Compare {item1} and {item2} in terms of {aspect}. "
...     "Keep it under {word_limit} words."
... )
>>> compare(
...     item1="Python",
...     item2="Java",
...     aspect="learning curve",
...     word_limit=50
... )
'Python has a gentler learning curve...'
```

```pycon
>>> # With specific model
>>> creative_writer = prompt_func(
...     "Write a creative story about {topic}",
...     model="gpt-4o",
...     temperature=1.5
... )
>>> creative_writer(topic="a time-traveling cat")
'Once upon a time, there was a cat named Whiskers...'
```

### aix.prompt_to_json(template, schema, \*\*kwargs)

Create a function that returns structured JSON output.

This is an explicit alias for prompt_func with output_schema.

* **Parameters:**
  * **template** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Prompt template
  * **schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – Output schema
  * **\*\*kwargs** – Additional parameters for prompt_func
* **Return type:**
  [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)
* **Returns:**
  Function that returns structured data

### Examples

```pycon
>>> extract = prompt_to_json(
...     "Extract name and age from: {text}",
...     schema={"name": str, "age": int}
... )
>>> result = extract(text="Alice is 30")
>>> isinstance(result, dict)
True
```

### aix.prompt_to_text(template, \*\*kwargs)

Create a function that returns text output.

This is an explicit alias for prompt_func without output_schema.

* **Parameters:**
  * **template** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Prompt template
  * **\*\*kwargs** – Additional parameters for prompt_func
* **Return type:**
  [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)
* **Returns:**
  Function that returns text

### Examples

```pycon
>>> summarize = prompt_to_text("Summarize: {text}")
>>> result = summarize(text="Long text...")
>>> isinstance(result, str)
True
```

### aix.resolve_api_key(model_or_provider, , api_key=None, prompt_if_missing=False)

Resolve an API key for `model_or_provider` through the documented layers.

Layers, highest precedence first: explicit `api_key` argument, provider
environment variable (with soft `.env` discovery), the AIX config store,
and – only when `prompt_if_missing` is true *and* running interactively –
an interactive prompt that persists the answer.

* **Parameters:**
  * **model_or_provider** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – A model id (provider inferred via LiteLLM) or a
    provider name directly (e.g. `"openai"`).
  * **api_key** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – An explicit key; when given (non-empty) it is returned verbatim.
  * **prompt_if_missing** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If true, fall back to a REPL prompt + persist when no
    key is found elsewhere. Off by default so the common path never
    blocks on input.
* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]
* **Returns:**
  The resolved key, or `None` if genuinely absent.

### Examples

```pycon
>>> resolve_api_key("gpt-4o", api_key="sk-explicit")
'sk-explicit'
```

### aix.resolve_model(model, , config=None)

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

```pycon
>>> 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`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

### aix.sample(prompt, , n, temperature=None, seed=None, concurrency=None, model=None, strategy='auto', parse=None, response_schema=None, on_error='raise', api_key=None, \*\*kwargs)

Draw `n` answers to `prompt`, each with its finish reason and usage.

* **Parameters:**
  * **prompt** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]]) – A string or a list of message dicts, as for [`aix.chat()`](_autosummary/aix.html.md#aix.chat).
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – How many samples to draw.
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Sampling temperature (`None` = configured default). At
    `0` the samples mostly coincide, which is rarely what you want here.
  * **seed** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Base seed. A provider-side `n` request sends it as is; each
    independent request sends a seed derived from `(seed, index)` so
    independent samples are not forced identical and runs with different
    base seeds do not overlap. Support is provider-dependent.
  * **concurrency** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Max simultaneous independent requests (`None` = config
    `chat.sample_concurrency`).
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model id or alias (`None` = configured default).
  * **strategy** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'auto'`, `'provider'`, `'independent'`]) – `"auto"` (provider `n` when supported, else independent;
    also falls back to independent if LiteLLM or the provider refuses
    `n` – for a provider 400 the first independent request is sent
    alone as a probe, and if it fails too the original 400 is raised;
    see [`Samples.fallback_error`](_autosummary/aix.html.md#aix.Samples.fallback_error)),
    `"provider"` (force one `n` request) or `"independent"`.
    `n=1` is always a single plain request, recorded `"independent"`.
  * **response_schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – A JSON Schema dict or Pydantic model class, enforced and
    validated per request as in [`aix.complete()`](_autosummary/aix.html.md#aix.complete); each payload is the
    validated value, and a choice still invalid after repairs records its
    `SchemaValidationError` as `error`. Exclusive with `parse`.
  * **parse** ([`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)], [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – Optional `text -> payload` (e.g. `json.loads`). A failure is
    recorded on that sample (`payload=None`, `error=...`), not raised.
  * **on_error** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'raise'`, `'record'`]) – When a request fails: `"raise"` (default) raises
    [`SamplingError`](_autosummary/aix.html.md#aix.SamplingError) once the launched requests finish, carrying
    the partial batch; `"record"` returns the batch with the failure on
    that sample’s `error`.
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Explicit API key, as for [`aix.chat()`](_autosummary/aix.html.md#aix.chat).
  * **\*\*kwargs** – Passed to every request (e.g. `max_tokens`, `response_format`).
* **Return type:**
  [`Samples`](_autosummary/aix.sampling.html.md#aix.sampling.Samples)
* **Returns:**
  [`Samples`](_autosummary/aix.html.md#aix.Samples) – a list of [`Sample`](_autosummary/aix.html.md#aix.Sample) with batch `.strategy`,
  `.usage`, `.n_requests`.
* **Raises:**
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – For a non-positive `n` / `concurrency`, an unknown
        `strategy` / `on_error`, or a reserved kwarg (`messages`, `stream`).
  * [**SamplingError**](_autosummary/aix.html.md#aix.SamplingError) – A request failed and `on_error="raise"`.

### aix.set_call_logger(logger)

Install `logger` for this context (`None` turns logging off).

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### aix.set_config(config)

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

Inside a [`using()`](_autosummary/aix.html.md#aix.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`](_autosummary/aix.config.html.md#aix.config.AixConfig)

### aix.supported_params(model=None)

The OpenAI-style parameters LiteLLM says `model` accepts.

`None` when that is unknown (LiteLLM cannot place the model, or is not
installed) – which is not the same as “supports nothing”.

* **Parameters:**
  **model** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Model id or alias; `None` means the configured chat default.
* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`frozenset`](https://docs.python.org/3/builtins/stdtypes.html#frozenset)]

### aix.supports(model, param)

Whether `model` is known to accept `param` – i.e. whether LiteLLM
*forwards* it to the provider for this model.

Conservative: `False` when support is unknown (or for a non-string
`param`), so a caller that branches on it takes the path that works
everywhere. `True` is not a guarantee that the parameter has an effect:
a router (OpenRouter…) can forward `seed` / `n` to an upstream model
that drops them, and a provider can deprecate or ignore a parameter
(seeding is best-effort everywhere; reasoning models may ignore it).

* **Parameters:**
  * **model** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Model id or alias; `None` means the configured chat default.
  * **param** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – An OpenAI-style request parameter name (`"n"`, `"seed"`,
    `"response_format"`…) or a capability in `CAPABILITIES`
    (`"response_schema"`).
* **Return type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

```pycon
>>> supports("gpt-4o-mini", "seed")
True
>>> supports("gpt-4o-mini", "response_schema")
True
```

### aix.text_to_speech(text, , model=None, voice=None, speed=None, response_format='mp3', api_key=None, \*\*kwargs)

Convert text to speech audio.

* **Parameters:**
  * **text** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text to convert to speech
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – TTS model to use (e.g., ‘tts-1’, ‘tts-1-hd’)
  * **voice** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Voice to use (‘alloy’, ‘echo’, ‘fable’, ‘onyx’, ‘nova’, ‘shimmer’)
  * **speed** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Playback speed (0.25 to 4.0)
  * **response_format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Audio format (‘mp3’, ‘opus’, ‘aac’, ‘flac’)
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedAudio`](_autosummary/aix.audio.html.md#aix.audio.GeneratedAudio)
* **Returns:**
  GeneratedAudio object
* **Raises:**
  [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed

### Examples

```pycon
>>> from aix.audio import text_to_speech
>>> audio = text_to_speech("Hello, how are you?")
>>> audio.save("greeting.mp3")
```

```pycon
>>> # Different voice and speed
>>> audio = text_to_speech(
...     "This is a test.",
...     voice="nova",
...     speed=1.2
... )
```

```pycon
>>> # High quality
>>> audio = text_to_speech(
...     "Important announcement",
...     model="tts-1-hd",
...     voice="onyx"
... )
```

### aix.to_image_content(image, , detail=None)

Build a multimodal `image_url` content block for `image`.

`image` may be:

- an `http(s)://` URL or a `data:` URI — passed through verbatim;
- a local file path (`str` or [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)) — read and inlined
  as a base64 `data:` URI with a guessed MIME type;
- raw `bytes` — base64-inlined (MIME sniffed from magic bytes, else JPEG);
- a PIL `Image` — encoded to PNG and inlined.

`detail` (`"low"` | `"high"` | `"auto"`) is forwarded when set; the
block is the OpenAI/LiteLLM multimodal shape understood across providers.

```pycon
>>> to_image_content("https://x/y.jpg")
{'type': 'image_url', 'image_url': {'url': 'https://x/y.jpg'}}
>>> to_image_content("data:image/png;base64,AAAA")["image_url"]["url"][:10]
'data:image'
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

### aix.transcribe(audio, , engine=None, model=None, language=None, prompt=None, response_format='text', temperature=None, timestamp_granularities=None, api_key=None, \*\*kwargs)

Transcribe audio to text.

By default this routes through LiteLLM (OpenAI-style transcription). Pass
`engine=` to instead delegate to a `scribed` backend — one façade over
many ASR engines (local Whisper / faster-whisper / vosk, or cloud Deepgram /
AssemblyAI / Groq / ElevenLabs / Google …) with speaker diarization and
SRT/VTT output. The return type is unchanged either way, so existing callers
are unaffected.

* **Parameters:**
  * **audio** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`BinaryIO`](https://docs.python.org/3/library/typing.html#typing.BinaryIO), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)]) – Audio file path, file object, or bytes.
  * **engine** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional `scribed` backend id (e.g. `"faster-whisper"`,
    `"deepgram"`). When given, transcription is delegated to scribed
    (which resolves that engine’s own credentials); the LiteLLM path is
    bypassed. Requires `pip install 'aix[scribed]'`. See
    `scribed.list_backends()`.
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Transcription model (e.g. `'whisper-1'`); for a scribed engine,
    the engine-specific model (e.g. a Whisper size).
  * **language** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Source language (ISO-639-1 code, e.g. `'en'`, `'es'`).
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional text to guide the model’s style (LiteLLM path).
  * **response_format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – `'text'` (default) → `str`; `'srt'`/`'vtt'` →
    subtitle `str` (scribed path); else → [`TranscriptionResult`](_autosummary/aix.html.md#aix.TranscriptionResult).
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Sampling temperature (LiteLLM path).
  * **timestamp_granularities** ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – Timestamp types (‘word’, ‘segment’) (LiteLLM path).
  * **\*\*kwargs** – Additional parameters (forwarded to LiteLLM, or to the scribed
    backend — e.g. `diarize=True`).
* **Return type:**
  [`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`TranscriptionResult`](_autosummary/aix.audio.html.md#aix.audio.TranscriptionResult)]
* **Returns:**
  `str` for `response_format` in {text, srt, vtt}, else a
  [`TranscriptionResult`](_autosummary/aix.html.md#aix.TranscriptionResult).

### Examples

```pycon
>>> from aix.audio import transcribe
>>> text = transcribe("recording.mp3")
>>> # delegate to a scribed engine (local, free, diarized SRT):
>>> srt = transcribe(
...     "meeting.wav", engine="faster-whisper", response_format="srt"
... )
>>> dg = transcribe(
...     "call.mp3", engine="deepgram", diarize=True,
...     response_format="verbose_json",
... )
```

### aix.transcribe_with_timestamps(audio, , granularity='segment', model=None, \*\*kwargs)

Transcribe audio with detailed timestamps.

* **Parameters:**
  * **audio** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`BinaryIO`](https://docs.python.org/3/library/typing.html#typing.BinaryIO), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)]) – Audio file path, file object, or bytes
  * **granularity** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Timestamp granularity (‘word’ or ‘segment’)
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Transcription model
  * **\*\*kwargs** – Additional parameters for transcribe()
* **Return type:**
  [`TranscriptionResult`](_autosummary/aix.audio.html.md#aix.audio.TranscriptionResult)
* **Returns:**
  TranscriptionResult with detailed segments

### Examples

```pycon
>>> from aix.audio import transcribe_with_timestamps
>>> result = transcribe_with_timestamps("lecture.mp3")
>>> for segment in result.segments:
...     start = segment['start']
...     end = segment['end']
...     text = segment['text']
...     print(f"[{start:.2f}-{end:.2f}] {text}")
```

### aix.translate_audio(audio, , model=None, prompt=None, api_key=None, \*\*kwargs)

Translate audio from any language to English.

#### NOTE
Currently uses Whisper’s translation capability which translates to English.

* **Parameters:**
  * **audio** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`BinaryIO`](https://docs.python.org/3/library/typing.html#typing.BinaryIO), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)]) – Audio file path, file object, or bytes
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Translation model (typically ‘whisper-1’)
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional text to guide translation
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)
* **Returns:**
  Translated text in English

### Examples

```pycon
>>> from aix.audio import translate_audio
>>> english_text = translate_audio("spanish_audio.mp3")
>>> print(english_text)
'This is the English translation.'
```

### aix.using(\*\*overrides)

Context manager applying scoped overrides, restored on exit.

The override lives in a [`ContextVar`](https://docs.python.org/3/library/contextvars.html#contextvars.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()`](https://docs.python.org/3/library/contextvars.html#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

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

* **Return type:**
  [`Iterator`](https://docs.python.org/3/library/typing.html#typing.Iterator)[[`AixConfig`](_autosummary/aix.config.html.md#aix.config.AixConfig)]

### Modules

| [`config`](_autosummary/aix.config.html.md#module-aix.config)             | Central configuration for AIX (single source of truth for defaults).                          |
|---------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| [`ai_models`](_autosummary/aix.ai_models.html.md#module-aix.ai_models)       | AI Model Management Module.                                                                   |
| [`audio`](_autosummary/aix.audio.html.md#module-aix.audio)               | Audio operations interface for AIX.                                                           |
| [`batches`](_autosummary/aix.batches.html.md#module-aix.batches)           | Batch processing interface for AIX.                                                           |
| [`calllog`](_autosummary/aix.calllog.html.md#module-aix.calllog)           | An opt-in log of aix model calls: the resolved model, the caller, the outcome.                |
| [`capabilities`](_autosummary/aix.capabilities.html.md#module-aix.capabilities) | What a model supports, asked before calling it.                                               |
| [`claude_cli`](_autosummary/aix.claude_cli.html.md#module-aix.claude_cli)     | A chat backend that runs prompts through the Claude Code CLI (`claude -p`).                   |
| [`credentials`](_autosummary/aix.credentials.html.md#module-aix.credentials)   | Unified, discoverable API-key / secret resolution for AIX.                                    |
| [`gen_ai`](_autosummary/aix.gen_ai.html.md#module-aix.gen_ai)             | Generative AI modules.                                                                        |
| [`image`](_autosummary/aix.image.html.md#module-aix.image)               | Image generation interface for AIX.                                                           |
| [`misc`](_autosummary/aix.misc.html.md#module-aix.misc)                 | Misc AIX functions.                                                                           |
| [`models`](_autosummary/aix.models.html.md#aix.models)                    | User-friendly interface for model discovery and selection.                                    |
| [`prompts`](_autosummary/aix.prompts.html.md#module-aix.prompts)           | Prompt-based function creation for AIX.                                                       |
| [`sampling`](_autosummary/aix.sampling.html.md#module-aix.sampling)         | Repeated sampling: `n` answers to one prompt, drawn as fast as the provider allows.           |
| [`stores`](_autosummary/aix.stores.html.md#module-aix.stores)             | Storage layers for AIX.                                                                       |
| [`structured`](_autosummary/aix.structured.html.md#module-aix.structured)     | Structured output: a schema in, validated values out, enforced as far as the provider allows. |
| [`util`](_autosummary/aix.util.html.md#module-aix.util)                 | Utils for AIX.                                                                                |
| [`video`](_autosummary/aix.video.html.md#module-aix.video)               | Video generation interface for AIX.                                                           |
| [`vision`](_autosummary/aix.vision.html.md#module-aix.vision)             | Image-to-text (vision) interface for AIX.                                                     |


# _autosummary/aix.image.html.md

# aix.image

Image generation interface for AIX.

Generate images from text descriptions using various AI models.

### Examples

Simple image generation:

```pycon
>>> from aix.image import generate_image
>>> image = generate_image("A serene mountain landscape at sunset")
>>> image.save("landscape.png")
```

Multiple images:

```pycon
>>> images = generate_images(
...     "A cute cat wearing a hat",
...     n=3,
...     size="1024x1024"
... )
>>> for i, img in enumerate(images):
...     img.save(f"cat_{i}.png")
```

With specific model:

```pycon
>>> image = generate_image(
...     "Abstract art with vibrant colors",
...     model="gpt-image-1.5"
... )
```

### Functions

| [`create_variation`](_autosummary/aix.image.html.md#aix.image.create_variation)(image_path, \*[, model, ...])     | Create variations of an existing image.      |
|-----------------------------------------------------------------------------------------------------|----------------------------------------------|
| [`edit_image`](_autosummary/aix.image.html.md#aix.image.edit_image)(image_path, prompt, \*[, ...])          | Edit an existing image based on a prompt.    |
| [`generate_image`](_autosummary/aix.image.html.md#aix.image.generate_image)(prompt, \*[, model, size, ...])     | Generate a single image from a text prompt.  |
| [`generate_images`](_autosummary/aix.image.html.md#aix.image.generate_images)(prompt, \*[, n, model, size, ...]) | Generate multiple images from a text prompt. |

### Classes

| [`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage)([url, b64_json, model, ...])   | Wrapper for generated images.   |
|------------------------------------------------------------------------------------------------|---------------------------------|

### *class* aix.image.GeneratedImage(url=None, b64_json=None, model=None, prompt=None, revised_prompt=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Wrapper for generated images.

Provides convenient access to image data in various formats.

### Examples

```pycon
>>> img = GeneratedImage(url="https://...", model="gpt-image-1.5")
>>> img.save("output.png")
>>> img.show()
>>> data = img.as_bytes()
```

#### as_bytes()

Get image as bytes.

* **Return type:**
  [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)
* **Returns:**
  Image data as bytes

#### as_pil_image()

Get image as PIL Image object.

* **Returns:**
  PIL.Image object
* **Raises:**
  [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If PIL is not installed

#### save(path, format=None)

Save image to file.

* **Parameters:**
  * **path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Output file path
  * **format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image format (e.g., ‘PNG’, ‘JPEG’). Auto-detected from path if None.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### Examples

```pycon
>>> img.save("output.png")
>>> img.save("output.jpg", format="JPEG")
```

#### show()

Display the image.

Requires PIL (Pillow) to be installed.

### Examples

```pycon
>>> img.show()
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### aix.image.create_variation(image_path, , model=None, size=None, n=1, api_key=None, \*\*kwargs)

Create variations of an existing image.

* **Parameters:**
  * **image_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Path to the source image
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use (`None` = configured `image.variation_model`)
  * **size** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Output image size
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of variations to generate
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage)]]
* **Returns:**
  GeneratedImage or list of GeneratedImage objects

### Examples

```pycon
>>> from aix.image import create_variation
>>> variations = create_variation(
...     "original.png",
...     n=3,
...     size="512x512"
... )
>>> for i, var in enumerate(variations):
...     var.save(f"variation_{i}.png")
```

### aix.image.edit_image(image_path, prompt, , mask_path=None, model=None, size=None, n=1, api_key=None, \*\*kwargs)

Edit an existing image based on a prompt.

* **Parameters:**
  * **image_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Path to the image to edit
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Description of the desired edit
  * **mask_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Optional path to mask image (transparent areas will be edited)
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use (`None` = configured `image.edit_model`)
  * **size** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Output image size
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of variations to generate
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage)]]
* **Returns:**
  GeneratedImage or list of GeneratedImage objects

### Examples

```pycon
>>> from aix.image import edit_image
>>> edited = edit_image(
...     "photo.png",
...     "Add a rainbow in the sky",
...     mask_path="sky_mask.png"
... )
>>> edited.save("edited_photo.png")
```

### aix.image.generate_image(prompt, , model=None, size=None, quality=None, style=None, response_format=None, api_key=None, \*\*kwargs)

Generate a single image from a text prompt.

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text description of the image to generate
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use (e.g., ‘openai/gpt-image-1.5’, ‘openai/gpt-image-1-mini’, ‘stable-diffusion’)
  * **size** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image size (e.g., ‘1024x1024’, ‘512x512’, ‘1792x1024’)
  * **quality** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image quality (‘standard’ or ‘hd’ for DALL-E 3)
  * **style** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image style (‘vivid’ or ‘natural’ for DALL-E 3)
  * **response_format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Format of response (‘url’ or ‘b64_json’). Left out of the
    request when None, since some providers and models (OpenAI’s gpt-image
    models, and the images endpoint as of 2026) reject the parameter.
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Explicit API key. If None, resolved from the environment / .env
    / AIX config store for the model’s provider (see aix.credentials).
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage)
* **Returns:**
  GeneratedImage object
* **Raises:**
  [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed

### Examples

```pycon
>>> from aix.image import generate_image
>>> image = generate_image("A serene mountain landscape")
>>> image.save("landscape.png")
```

```pycon
>>> # High quality with DALL-E 3
>>> image = generate_image(
...     "Abstract art with vibrant colors",
...     model="gpt-image-1.5",
...     quality="high",
... )
```

```pycon
>>> # Specific size
>>> image = generate_image(
...     "A futuristic city",
...     size="1792x1024"
... )
```

### aix.image.generate_images(prompt, , n=None, model=None, size=None, quality=None, style=None, response_format=None, api_key=None, \*\*kwargs)

Generate multiple images from a text prompt.

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text description of images to generate
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of images to generate
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use
  * **size** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image size
  * **quality** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image quality
  * **style** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Image style
  * **response_format** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Format of response, sent only when given
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`GeneratedImage`](_autosummary/aix.image.html.md#aix.image.GeneratedImage)]
* **Returns:**
  List of GeneratedImage objects

### Examples

```pycon
>>> from aix.image import generate_images
>>> images = generate_images(
...     "A cute robot",
...     n=3,
...     size="512x512"
... )
>>> for i, img in enumerate(images):
...     img.save(f"robot_{i}.png")
```


# _autosummary/aix.misc.html.md

# aix.misc

Misc AIX functions.

### Functions

| [`get_llm_leaderboards`](_autosummary/aix.misc.html.md#aix.misc.get_llm_leaderboards)()   | Get the LLM leaderboards.   |
|---------------------------------------------------------------------------|-----------------------------|

### aix.misc.get_llm_leaderboards()

Get the LLM leaderboards.

Requires the optional `tabled` dependency (`pip install aix[tables]`).


# _autosummary/aix.models.html.md

# aix.models

### aix.models *= ModelStore(0 models)*

User-friendly interface for model discovery and selection.

Provides a Mapping interface over the ModelManager with convenient
access patterns and integration with chat/embeddings functions.

### Examples

```pycon
>>> models = ModelStore()
>>> models.discover()  # Fetch available models
```

```pycon
>>> # List all models
>>> list(models)[:5]
['openai/gpt-4o', 'openai/gpt-4o-mini', ...]
```

```pycon
>>> # Get model info
>>> info = models['openai/gpt-4o']
>>> info.provider
'openai'
```

```pycon
>>> # Filter models
>>> openai_models = models.filter(provider='openai')
>>> local_models = models.filter(is_local=True)
```

```pycon
>>> # Use with chat
>>> from aix.chat import chat
>>> model = models['gpt-4o-mini']
>>> chat("Hello", model=model.id)
'Hello! How can I help you?'
```


# _autosummary/aix.prompts.html.md

# aix.prompts

Prompt-based function creation for AIX.

Transform text prompts into callable Python functions with automatic parameter extraction.

This module provides the core functionality for creating reusable AI-powered functions
from natural language prompts. It supports both text generation and structured output.

### Examples

Create a simple text function:

```pycon
>>> from aix.prompts import prompt_func
>>> translate = prompt_func("Translate to French: {text}")
>>> translate(text="Hello world")
'Bonjour le monde'
```

Create a function with structured output:

```pycon
>>> extract_person = prompt_func(
...     "Extract person information from: {text}",
...     output_schema={"name": str, "age": int}
... )
>>> extract_person(text="Alice is 30 years old")
{'name': 'Alice', 'age': 30}
```

Multiple parameters:

```pycon
>>> compare = prompt_func(
...     "Compare {item1} and {item2} in terms of {aspect}"
... )
>>> compare(item1="Python", item2="JavaScript", aspect="performance")
'Python generally has better...'
```

### Functions

| [`constrained_answer`](_autosummary/aix.prompts.html.md#aix.prompts.constrained_answer)(prompt, valid_answers, \*)   | Get an answer from the LLM constrained to a set of valid answers or types.   |
|--------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------|
| [`prompt_func`](_autosummary/aix.prompts.html.md#aix.prompts.prompt_func)(template, \*[, output_schema, ...]) | Create a callable function from a prompt template.                           |
| [`prompt_to_json`](_autosummary/aix.prompts.html.md#aix.prompts.prompt_to_json)(template, schema, \*\*kwargs)    | Create a function that returns structured JSON output.                       |
| [`prompt_to_text`](_autosummary/aix.prompts.html.md#aix.prompts.prompt_to_text)(template, \*\*kwargs)            | Create a function that returns text output.                                  |

### Classes

| [`CommonFuncs`](_autosummary/aix.prompts.html.md#aix.prompts.CommonFuncs)([model])   | Collection of commonly used prompt functions.   |
|-------------------------------------------------------------------------|-------------------------------------------------|
| [`PromptFuncs`](_autosummary/aix.prompts.html.md#aix.prompts.PromptFuncs)([model])   | Collection of prompt-based functions.           |

### Exceptions

| [`ConstraintViolation`](_autosummary/aix.prompts.html.md#aix.prompts.ConstraintViolation)(message, \*[, answer, ...])   | Raised when an LLM answer does not satisfy the requested constraint.   |
|----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|

### *class* aix.prompts.CommonFuncs(model=None)

Bases: [`PromptFuncs`](_autosummary/aix.prompts.html.md#aix.prompts.PromptFuncs)

Collection of commonly used prompt functions.

### Examples

```pycon
>>> from aix.prompts import common_funcs
>>> common_funcs.summarize(text="Long article...")
'Summary...'
>>> common_funcs.extract_keywords(text="Article about AI")
['AI', 'artificial', 'intelligence']
```

### *exception* aix.prompts.ConstraintViolation(message, , answer=None, valid_answers=None)

Bases: [`ValueError`](https://docs.python.org/3/builtins/exceptions.html#ValueError)

Raised when an LLM answer does not satisfy the requested constraint.

A subclass of `ValueError` so that callers who already guard
[`constrained_answer()`](_autosummary/aix.prompts.html.md#aix.prompts.constrained_answer) with `except ValueError` keep working.

#### answer

The offending value, as it came back from the model.

#### valid_answers

The constraint the value failed, verbatim as passed in.

### Examples

```pycon
>>> violation = ConstraintViolation("nope", answer="nope", valid_answers=["a"])
>>> violation.answer, violation.valid_answers
('nope', ['a'])
>>> isinstance(violation, ValueError)
True
```

### *class* aix.prompts.PromptFuncs(model=None, \*\*default_kwargs)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Collection of prompt-based functions.

Provides a namespace for organizing related prompt functions with
attribute-based access.

### Examples

```pycon
>>> funcs = PromptFuncs()
>>> funcs.add('summarize', "Summarize: {text}")
>>> funcs.add('translate', "Translate {text} to {language}")
>>> funcs.summarize(text="Long article...")
'Summary...'
>>> funcs.translate(text="Hello", language="Spanish")
'Hola'
```

#### add(name, template, , output_schema=None, \*\*kwargs)

Add a function to the collection.

* **Parameters:**
  * **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Function name (will be accessible as attribute)
  * **template** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Prompt template
  * **output_schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – Optional schema for structured output
  * **\*\*kwargs** – Additional parameters for prompt_func
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### keys()

Get all function names.

### aix.prompts.constrained_answer(prompt, valid_answers, , model=None, temperature=None, enhance_prompt=False, n=1, on_violation='raise', max_retries=0, concurrency=None)

Get an answer from the LLM constrained to a set of valid answers or types.

Uses JSON mode to ensure the LLM returns a valid response based on constraints.
More flexible than the oa version - works with any model that supports JSON mode
via LiteLLM.

This can be seen as a facade for some common structured output use cases, as well
as a convenient tool to do response statistics and validation (via n>1).

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The question or prompt to ask the LLM
  * **valid_answers** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)], [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`int`](https://docs.python.org/3/builtins/functions.html#int)], [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`float`](https://docs.python.org/3/builtins/functions.html#float)], [`type`](https://docs.python.org/3/builtins/functions.html#type), [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`float`](https://docs.python.org/3/builtins/functions.html#float), [`float`](https://docs.python.org/3/builtins/functions.html#float)]]) – 

    Can be:
    - list[str]: List of valid string options
    - list[int]: List of valid integer options
    - list[float]: List of valid float options
    - bool: Constrains answer to True or False
    - int: Any integer
    - float: Any number
    - tuple[float, float]: Numerical range (min, max) inclusive
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The model to use for the LLM (default: uses DFLT_CHAT_MODEL)
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Temperature for sampling (default: None, uses model’s default).
    Higher values (e.g., 1.0) give more random/varied results.
    Lower values (e.g., 0.0) give more deterministic results.
  * **enhance_prompt** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool)) – If True, adds explicit instructions to the prompt about
    JSON formatting and constraints. If False (default), relies on
    response_format alone. Default is False to match oa behavior.
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Number of times to call the LLM (default: 1). The `n` calls are
    independent and run concurrently (see `concurrency`); each is
    validated (and retried) on its own. On the first failure no new
    call is started, but calls already in flight finish (and are
    billed) before the error propagates. For raw samples with finish
    reasons and usage, use [`aix.sample()`](_autosummary/aix.html.md#aix.sample).
  * **on_violation** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'raise'`, `'return'`]) – What to do when the model’s answer does not satisfy
    `valid_answers`. `'raise'` (default) raises `ConstraintViolation`.
    `'return'` returns the model’s value unchecked – the behaviour of
    this function before enforcement existed, kept as an escape hatch.
  * **max_retries** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – How many times to re-ask the model after a violation
    before giving up (default: 0, i.e. ask exactly once). Ignored when
    `on_violation='return'`, which never detects a violation.
  * **concurrency** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Max simultaneous calls when `n > 1` (default: config
    `chat.sample_concurrency`).
* **Returns:**
  One of the valid answers, respecting the type constraint.
  If n > 1, returns a list of answers.
* **Raises:**
  * [**ConstraintViolation**](_autosummary/aix.prompts.html.md#aix.prompts.ConstraintViolation) – If the answer is not a member of an options list,
        falls outside a `(min, max)` range, or cannot be converted to the
        declared type – unless `on_violation='return'`.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If the response is not JSON, or has no “answer” field.

### Examples

```pycon
>>> # String options
>>> answer = constrained_answer(
...     "Is Python compiled or interpreted?",
...     ["compiled", "interpreted", "both"]
... )
>>> answer in ["compiled", "interpreted", "both"]
True
```

```pycon
>>> # Boolean
>>> answer = constrained_answer(
...     "Is Python dynamically typed?",
...     bool
... )
>>> isinstance(answer, bool)
True
```

```pycon
>>> # Integer options
>>> answer = constrained_answer(
...     "How many wheels does a car have?",
...     [2, 3, 4, 6, 8]
... )
>>> answer in [2, 3, 4, 6, 8]
True
```

```pycon
>>> # Numerical range
>>> answer = constrained_answer(
...     "What is a reasonable hourly rate for a senior Python developer? (USD)",
...     (50.0, 300.0)
... )
>>> 50.0 <= answer <= 300.0
True
```

```pycon
>>> # Multiple samples for statistics
>>> answers = constrained_answer(
...     "Which is better: cats or dogs?",
...     ["cats", "dogs"],
...     n=10
... )
>>> len(answers)
10
```

```pycon
>>> # Tolerate an off-constraint answer instead of raising
>>> answer = constrained_answer(
...     "Is Python compiled or interpreted?",
...     ["compiled", "interpreted"],
...     on_violation="return",
... )
```

### aix.prompts.prompt_func(template, , output_schema=None, response_schema=None, egress=None, model=None, temperature=None, name=None, \*\*chat_kwargs)

Create a callable function from a prompt template.

This is the main function for creating prompt-based functions. It automatically
detects parameters from the template and creates a function with those parameters.

Without output_schema: Returns text
With output_schema: Returns structured data (dict, list, etc.)
With egress: Returns whatever the egress post-processor returns.

Templates use the default-aware `{name:default}` dialect (matching
`oa.prompt_function`): `{name}` is a required parameter, `{name:default}`
supplies a default value (the text after the colon), and braces inside
`` fenced `` regions are left literal. Plain `{name}`-only templates behave
exactly as before.

```pycon
>>> greet = prompt_func("Greet {name} in {language:English}")
>>> greet.param_names
['name', 'language']
```

The signature lists every template field, keyword-only, with its default:

```pycon
>>> from inspect import signature
>>> str(signature(prompt_func("{a} {b:x}")))
"(*, a: str, b: str = 'x')"
```

* **Parameters:**
  * **template** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Prompt template with {var} placeholders for parameters
  * **output_schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – Optional schema for structured output. Can be:
    - Dict mapping field names to types: {“name”: str, “age”: int}
    - A single type for simple outputs: str, int, list, etc.
    - None for plain text output (default)
  * **response_schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – Optional JSON Schema dict or Pydantic model class for
    *enforced, validated* structured output (nested objects, arrays,
    enums, required/optional all work): routed to the provider’s
    strict `json_schema` mode where supported, otherwise JSON mode,
    then validated client-side with a bounded repair retry (see
    [`aix.complete()`](_autosummary/aix.html.md#aix.complete)). The function returns the validated value (a
    model instance for a Pydantic schema) or raises
    `aix.SchemaValidationError`. Prefer it over `output_schema`,
    which is flat, prompt-only and unvalidated; pass one or the other.
  * **egress** ([`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any)], [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – Optional post-processor `(result) -> Any` applied to the output
    before returning — on both the text and structured paths. Lets a caller
    keep “prompt → typed Python value” inside the facade (e.g. parse the
    LLM text into a list of lines/ids) instead of wrapping the returned
    function. `None` (default) returns the raw result unchanged.
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model to use for this function
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Temperature for generation
  * **name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional `__name__` for the generated function (for tracing /
    identity). Defaults to `"prompt_based_function"`.
  * **\*\*chat_kwargs** – Additional parameters passed to chat()
* **Return type:**
  [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)
* **Returns:**
  Callable function with parameters derived from template

### Examples

```pycon
>>> # Simple text generation
>>> summarize = prompt_func("Summarize this text: {text}")
>>> summarize(text="Long article...")
'Brief summary...'
```

```pycon
>>> # Structured output
>>> extract = prompt_func(
...     "Extract contact info from: {text}",
...     output_schema={"name": str, "email": str, "phone": str}
... )
>>> result = extract(text="Contact John at john@example.com, 555-1234")
>>> result['name']
'John'
```

```pycon
>>> # Multiple parameters
>>> compare = prompt_func(
...     "Compare {item1} and {item2} in terms of {aspect}. "
...     "Keep it under {word_limit} words."
... )
>>> compare(
...     item1="Python",
...     item2="Java",
...     aspect="learning curve",
...     word_limit=50
... )
'Python has a gentler learning curve...'
```

```pycon
>>> # With specific model
>>> creative_writer = prompt_func(
...     "Write a creative story about {topic}",
...     model="gpt-4o",
...     temperature=1.5
... )
>>> creative_writer(topic="a time-traveling cat")
'Once upon a time, there was a cat named Whiskers...'
```

### aix.prompts.prompt_to_json(template, schema, \*\*kwargs)

Create a function that returns structured JSON output.

This is an explicit alias for prompt_func with output_schema.

* **Parameters:**
  * **template** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Prompt template
  * **schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – Output schema
  * **\*\*kwargs** – Additional parameters for prompt_func
* **Return type:**
  [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)
* **Returns:**
  Function that returns structured data

### Examples

```pycon
>>> extract = prompt_to_json(
...     "Extract name and age from: {text}",
...     schema={"name": str, "age": int}
... )
>>> result = extract(text="Alice is 30")
>>> isinstance(result, dict)
True
```

### aix.prompts.prompt_to_text(template, \*\*kwargs)

Create a function that returns text output.

This is an explicit alias for prompt_func without output_schema.

* **Parameters:**
  * **template** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Prompt template
  * **\*\*kwargs** – Additional parameters for prompt_func
* **Return type:**
  [`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)
* **Returns:**
  Function that returns text

### Examples

```pycon
>>> summarize = prompt_to_text("Summarize: {text}")
>>> result = summarize(text="Long text...")
>>> isinstance(result, str)
True
```


# _autosummary/aix.sampling.html.md

# aix.sampling

Repeated sampling: `n` answers to one prompt, drawn as fast as the provider allows.

Asking the same question several times is the basic variance-reduction (and
stability-measurement) tool for LLM judgements. [`sample()`](_autosummary/aix.sampling.html.md#aix.sampling.sample) does it in one of
two ways and **records which**, because they are not the same statistical object:

* `"provider_n"` – one request with `n` choices (one prompt evaluation, `n`
  decodes). Cheapest, and used when LiteLLM reports the model supports `n`.
* `"independent"` – `n` separate requests, run concurrently. Works with every
  provider; each sample also gets its own `usage`.

If a provider silently returns fewer choices than asked, the shortfall is drawn
independently and the batch is marked `"mixed"`.

```pycon
>>> answers = sample("Is a tomato a fruit? Answer yes or no.", n=5)
>>> answers.texts
('Yes', 'Yes', 'Yes', 'yes', 'Yes')
>>> answers.strategy, answers.usage.total_tokens
('provider_n', 52)
```

### Functions

| [`sample`](_autosummary/aix.sampling.html.md#aix.sampling.sample)(prompt, \*, n[, temperature, seed, ...])   | Draw `n` answers to `prompt`, each with its finish reason and usage.      |
|----------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| [`concurrent_map`](_autosummary/aix.sampling.html.md#aix.sampling.concurrent_map)(func, items, \*, concurrency)      | `[func(x) for x in items]`, run on up to `concurrency` threads, in order. |
| [`check_positive_int`](_autosummary/aix.sampling.html.md#aix.sampling.check_positive_int)(name, value)                   | `int(value)` if it is a positive integer (not a bool), else `ValueError`. |
| [`forget_n_refusals`](_autosummary/aix.sampling.html.md#aix.sampling.forget_n_refusals)([model])                        | Forget which models were found to refuse a provider-side `n`.             |

### Classes

| [`Sample`](_autosummary/aix.sampling.html.md#aix.sampling.Sample)(text, payload[, finish_reason, ...])   | One drawn answer.                                                                                                                                            |
|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`Samples`](_autosummary/aix.sampling.html.md#aix.sampling.Samples)([samples, usage, n_requests, ...])    | The list of [`Sample`](_autosummary/aix.sampling.html.md#aix.sampling.Sample) returned by [`sample()`](_autosummary/aix.sampling.html.md#aix.sampling.sample), plus batch facts. |

### Exceptions

| [`SamplingError`](_autosummary/aix.sampling.html.md#aix.sampling.SamplingError)(message, \*[, samples])   | A request inside [`sample()`](_autosummary/aix.sampling.html.md#aix.sampling.sample) failed (with `on_error="raise"`).   |
|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|

### *class* aix.sampling.Sample(text, payload, finish_reason=None, usage=None, strategy='independent', seed=None, error=None, system_fingerprint=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

One drawn answer.

#### text

The raw text of this choice (`""` if its request failed).

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### payload

`parse(text)` when a `parse` function was given, else `text`;
`None` if the request or the parsing failed (see `error`).

* **Type:**
  [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)

#### finish_reason

Why this choice stopped. `"length"` = truncated,
`"content_filter"` = refused/filtered; check it before treating the
payload as a judgement.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### usage

Tokens for the request that produced *only this* sample, or
`None` when it shared a provider-side `n` request (whose usage
cannot be split per choice; see [`Samples.usage`](_autosummary/aix.sampling.html.md#aix.sampling.Samples.usage)).

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Usage`](_autosummary/aix.html.md#aix.Usage)]

#### strategy

How this sample was drawn: `"provider_n"` or `"independent"`.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### seed

The seed sent with its request, if any.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`int`](https://docs.python.org/3/builtins/functions.html#int)]

#### error

The exception this sample’s request raised (with
`on_error="record"`) or that `parse` raised on its text.

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`Exception`](https://docs.python.org/3/builtins/exceptions.html#Exception)]

#### system_fingerprint

The serving backend’s fingerprint for its request,
when reported. Seeded samples are only comparable across equal
fingerprints (see [`aix.supports()`](_autosummary/aix.html.md#aix.supports) for whether `seed` is
honoured at all).

* **Type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]

#### *property* ok *: [bool](https://docs.python.org/3/builtins/functions.html#bool)*

`True` when the request succeeded and the text parsed (if asked).

### *class* aix.sampling.Samples(samples=(), , strategy, usage=None, n_requests=0, n_usage_reports=0, fallback_error=None)

Bases: [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)

The list of [`Sample`](_autosummary/aix.sampling.html.md#aix.sampling.Sample) returned by [`sample()`](_autosummary/aix.sampling.html.md#aix.sampling.sample), plus batch facts.

It is a plain `list` otherwise: slicing or concatenating gives a `list`
without the batch attributes, which describe the whole draw only.

#### strategy

`"provider_n"`, `"independent"` or `"mixed"` (provider
`n` topped up with independent calls).

#### usage

Total tokens over every request that reported usage, or `None`
if none did. Compare `n_requests` with `n_usage_reports` to see
whether it is complete.

#### n_requests

How many requests were made (schema repair requests included).

#### n_usage_reports

How many of them reported usage (a completion’s repair
requests are counted with it when it reported usage). A provider
request refused with a 400 (see `fallback_error`) reports none.

#### fallback_error

With `strategy="auto"`: the error that made the
provider-side `n` request fall back to independent requests
(LiteLLM refusing `n`, or the provider rejecting it with a 400),
else `None`.

#### *property* errors *: [tuple](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[Exception](https://docs.python.org/3/builtins/exceptions.html#Exception), ...]*

Every recorded error (request or parse), in sample order.

### *exception* aix.sampling.SamplingError(message, , samples=None)

Bases: [`Exception`](https://docs.python.org/3/builtins/exceptions.html#Exception)

A request inside [`sample()`](_autosummary/aix.sampling.html.md#aix.sampling.sample) failed (with `on_error="raise"`).

No request is launched after the first failure, and the ones already in
flight are awaited, so the work already paid for is not lost: `samples`
holds every request that was made, failed ones included (as samples whose
`error` is set) – possibly fewer than `n`. The first failure is
`__cause__`.

### aix.sampling.check_positive_int(name, value)

`int(value)` if it is a positive integer (not a bool), else `ValueError`.

```pycon
>>> check_positive_int("n", 3)
3
>>> check_positive_int("n", 0)
Traceback (most recent call last):
...
ValueError: n must be a positive integer, got 0
```

* **Return type:**
  [`int`](https://docs.python.org/3/builtins/functions.html#int)

### aix.sampling.concurrent_map(func, items, , concurrency)

`[func(x) for x in items]`, run on up to `concurrency` threads, in order.

Fails fast like the serial loop would: once a call raises, calls not yet
started are cancelled (those already running finish), and the first
exception in item order propagates.

```pycon
>>> concurrent_map(lambda x: x * x, range(5), concurrency=3)
[0, 1, 4, 9, 16]
```

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[`R`]

### aix.sampling.forget_n_refusals(model=None)

Forget which models were found to refuse a provider-side `n`.

`sample(strategy="auto")` remembers, per resolved model id (and endpoint
kwargs) and for the life of the process, that a provider refused `n` with a
400 and a plain request then succeeded. That is a heuristic: a 400 caused by
`n` *combined with* another argument is remembered too. Call this if a
provider has since started accepting `n`. `model=None` forgets every model.

```pycon
>>> forget_n_refusals()
```

* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### aix.sampling.sample(prompt, , n, temperature=None, seed=None, concurrency=None, model=None, strategy='auto', parse=None, response_schema=None, on_error='raise', api_key=None, \*\*kwargs)

Draw `n` answers to `prompt`, each with its finish reason and usage.

* **Parameters:**
  * **prompt** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Iterable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Iterable)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]]) – A string or a list of message dicts, as for [`aix.chat()`](_autosummary/aix.html.md#aix.chat).
  * **n** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – How many samples to draw.
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Sampling temperature (`None` = configured default). At
    `0` the samples mostly coincide, which is rarely what you want here.
  * **seed** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Base seed. A provider-side `n` request sends it as is; each
    independent request sends a seed derived from `(seed, index)` so
    independent samples are not forced identical and runs with different
    base seeds do not overlap. Support is provider-dependent.
  * **concurrency** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Max simultaneous independent requests (`None` = config
    `chat.sample_concurrency`).
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Model id or alias (`None` = configured default).
  * **strategy** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'auto'`, `'provider'`, `'independent'`]) – `"auto"` (provider `n` when supported, else independent;
    also falls back to independent if LiteLLM or the provider refuses
    `n` – for a provider 400 the first independent request is sent
    alone as a probe, and if it fails too the original 400 is raised;
    see [`Samples.fallback_error`](_autosummary/aix.sampling.html.md#aix.sampling.Samples.fallback_error)),
    `"provider"` (force one `n` request) or `"independent"`.
    `n=1` is always a single plain request, recorded `"independent"`.
  * **response_schema** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict), [`type`](https://docs.python.org/3/builtins/functions.html#type)]) – A JSON Schema dict or Pydantic model class, enforced and
    validated per request as in [`aix.complete()`](_autosummary/aix.html.md#aix.complete); each payload is the
    validated value, and a choice still invalid after repairs records its
    `SchemaValidationError` as `error`. Exclusive with `parse`.
  * **parse** ([`Callable`](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable)[[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)], [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – Optional `text -> payload` (e.g. `json.loads`). A failure is
    recorded on that sample (`payload=None`, `error=...`), not raised.
  * **on_error** ([`Literal`](https://docs.python.org/3/library/typing.html#typing.Literal)[`'raise'`, `'record'`]) – When a request fails: `"raise"` (default) raises
    [`SamplingError`](_autosummary/aix.sampling.html.md#aix.sampling.SamplingError) once the launched requests finish, carrying
    the partial batch; `"record"` returns the batch with the failure on
    that sample’s `error`.
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Explicit API key, as for [`aix.chat()`](_autosummary/aix.html.md#aix.chat).
  * **\*\*kwargs** – Passed to every request (e.g. `max_tokens`, `response_format`).
* **Return type:**
  [`Samples`](_autosummary/aix.sampling.html.md#aix.sampling.Samples)
* **Returns:**
  [`Samples`](_autosummary/aix.sampling.html.md#aix.sampling.Samples) – a list of [`Sample`](_autosummary/aix.sampling.html.md#aix.sampling.Sample) with batch `.strategy`,
  `.usage`, `.n_requests`.
* **Raises:**
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – For a non-positive `n` / `concurrency`, an unknown
        `strategy` / `on_error`, or a reserved kwarg (`messages`, `stream`).
  * [**SamplingError**](_autosummary/aix.sampling.html.md#aix.sampling.SamplingError) – A request failed and `on_error="raise"`.


# _autosummary/aix.stores.html.md

# aix.stores

Storage layers for AIX.

### Functions

| [`add_extension_based_decoder`](_autosummary/aix.stores.html.md#aix.stores.add_extension_based_decoder)(ext, decoder)   | Register a decoder function for a given file extension.                                  |
|----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|
| [`extension_based_decode_to_text`](_autosummary/aix.stores.html.md#aix.stores.extension_based_decode_to_text)(k, v)        | Decode the given bytes `v` to a string based on the file extension extracted from `key`. |
| `get_extension`(string)                                                                      |                                                                                          |

### aix.stores.add_extension_based_decoder(ext, decoder)

Register a decoder function for a given file extension.

* **Parameters:**
  * **ext** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str)) – The file extension (without the leading dot), e.g., “pdf”.
  * **decoder** (*Callable* *[* *[*[*bytes*](https://docs.python.org/3/builtins/stdtypes.html#bytes) *]* *,* [*str*](https://docs.python.org/3/builtins/stdtypes.html#str) *]*) – A function that takes bytes and returns a decoded string.
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### aix.stores.extension_based_decode_to_text(k, v)

Decode the given bytes `v` to a string based on the file extension extracted from `key`.

If a decoder is registered for the extension, it is used.
Otherwise, the bytes are decoded using v.decode(‘utf-8’).

* **Parameters:**
  * **key** ([*str*](https://docs.python.org/3/builtins/stdtypes.html#str)) – The key (typically a filename) from which to extract the extension.
  * **v** ([*bytes*](https://docs.python.org/3/builtins/stdtypes.html#bytes)) – The value to decode.
* **Returns:**
  The decoded text.
* **Return type:**
  [*str*](https://docs.python.org/3/builtins/stdtypes.html#str)


# _autosummary/aix.structured.html.md

# aix.structured

Structured output: a schema in, validated values out, enforced as far as the provider allows.

A *response schema* is a JSON Schema `dict` or a Pydantic model class. It is
turned into a [`ResponseSchema`](_autosummary/aix.structured.html.md#aix.structured.ResponseSchema), which knows

* how to ask the provider for it – the strongest mode the model supports:
  - `"strict"`: `response_format={"type": "json_schema", ..., "strict": true}`,
    the provider constrains decoding to the schema. Used when LiteLLM reports
    `supports_response_schema(model)` *and* the schema is strict-compatible
    (every object closes `additionalProperties` and requires all its
    properties – Pydantic models are converted to that form automatically);
  - `"schema"`: the same `json_schema` format, non-strict, for a
    schema-capable model and a schema that is not strict-compatible;
  - `"json_mode"`: `{"type": "json_object"}` plus the schema in the prompt,
    for models without schema support (or whose support is unknown);
  - `"prompt"`: the schema in the prompt only, for models LiteLLM knows do
    not accept a `response_format` at all;
* and how to validate a reply client-side, which happens on every path (it is
  cheap, and “the provider enforced it” is a claim worth checking).

Providers only accept an *object* at the root of a structured reply (strict
`json_schema` and JSON mode alike), so a schema whose root is not an object
(an array, a union, a scalar) is sent wrapped as `{"value": <schema>}` and
unwrapped after validation – transparently to the caller.

```pycon
>>> spec = ResponseSchema.from_schema({"type": "object", "properties": {"x": {"type": "integer"}}, "required": ["x"]})
>>> spec.validate('{"x": 3}')
{'x': 3}
>>> spec.validate('{"x": "three"}')
Traceback (most recent call last):
...
aix.structured.SchemaValidationError: ...
```

### Classes

| [`ResponseSchema`](_autosummary/aix.structured.html.md#aix.structured.ResponseSchema)(name, json_schema, ...[, ...])   | A normalized response schema: its JSON Schema, name, and validator.   |
|--------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|

### Exceptions

| [`SchemaValidationError`](_autosummary/aix.structured.html.md#aix.structured.SchemaValidationError)(message, \*[, text, detail])   | A reply was not JSON, or did not match the response schema.   |
|-------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|

### *class* aix.structured.ResponseSchema(name, json_schema, wire_schema, strict_compatible, source, wrapped=False, \_coerce_json=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

A normalized response schema: its JSON Schema, name, and validator.

Build it with [`from_schema()`](_autosummary/aix.structured.html.md#aix.structured.ResponseSchema.from_schema); [`aix.complete()`](_autosummary/aix.html.md#aix.complete) does that for you
from `response_schema=`.

#### name

The schema name sent to the provider.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### json_schema

The caller’s JSON Schema dict (what a value must match).

* **Type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

#### wire_schema

What is sent: `json_schema` itself, or wrapped as
`{"value": json_schema}` when its root is not an object.

* **Type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)

#### strict_compatible

Whether `wire_schema` satisfies strict-mode rules.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### wrapped

Whether `wire_schema` is the `{"value": ...}` wrapper.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### source

What the caller passed (a dict or a Pydantic model class).

* **Type:**
  [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)

#### *classmethod* from_schema(schema)

Normalize a JSON Schema dict or a Pydantic model class.

* **Raises:**
  * [**TypeError**](https://docs.python.org/3/builtins/exceptions.html#TypeError) – For anything else.
  * **jsonschema.SchemaError** – For a malformed JSON Schema dict.
* **Return type:**
  [`ResponseSchema`](_autosummary/aix.structured.html.md#aix.structured.ResponseSchema)

#### instruction()

The prompt text that asks for this schema (JSON / prompt modes, repairs).

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### mode_for(model)

The strongest enforcement mode available for `model` and this schema.

* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### response_format(mode)

The LiteLLM `response_format` for `mode` (`None` for `"prompt"`).

* **Return type:**
  [`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional)[[`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)]

#### validate(text)

Parse and validate a reply; return the value (a model instance for Pydantic).

* **Raises:**
  [**SchemaValidationError**](_autosummary/aix.structured.html.md#aix.structured.SchemaValidationError) – If `text` is not JSON or does not match.
* **Return type:**
  [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)

### *exception* aix.structured.SchemaValidationError(message, , text='', detail='')

Bases: [`ValueError`](https://docs.python.org/3/builtins/exceptions.html#ValueError)

A reply was not JSON, or did not match the response schema.

#### text

The reply that failed.

#### detail

The parse / validation message (what a repair prompt is told).


# _autosummary/aix.util.html.md

# aix.util

Utils for AIX.


# _autosummary/aix.video.html.md

# aix.video

Video generation interface for AIX.

Generate videos from text descriptions or images.

#### NOTE
Video generation support varies by provider and may require additional
API keys and configuration. This module provides a unified interface but
implementation depends on available providers.

### Examples

Text to video:

```pycon
>>> from aix.video import generate_video
>>> video = generate_video(
...     "A cat walking through a garden",
...     duration=5
... )
>>> video.save("cat_video.mp4")
```

Image to video:

```pycon
>>> video = animate_image(
...     "static_image.jpg",
...     prompt="Make the clouds move gently"
... )
```

### Functions

| [`animate_image`](_autosummary/aix.video.html.md#aix.video.animate_image)(image_path[, prompt, model, ...])    | Animate a static image into a video.                        |
|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------|
| [`estimate_cost`](_autosummary/aix.video.html.md#aix.video.estimate_cost)(duration[, resolution, provider])    | Estimate the cost of video generation.                      |
| [`extend_video`](_autosummary/aix.video.html.md#aix.video.extend_video)(video_path[, prompt, ...])            | Extend an existing video with additional generated content. |
| [`generate_video`](_autosummary/aix.video.html.md#aix.video.generate_video)(prompt, \*[, model, duration, ...]) | Generate a video from a text prompt.                        |
| [`generate_video_pika`](_autosummary/aix.video.html.md#aix.video.generate_video_pika)(prompt, \*[, duration])        | Generate video using Pika Labs.                             |
| [`generate_video_runway`](_autosummary/aix.video.html.md#aix.video.generate_video_runway)(prompt, \*[, duration])      | Generate video using Runway ML.                             |
| [`generate_video_stable_diffusion`](_autosummary/aix.video.html.md#aix.video.generate_video_stable_diffusion)(prompt, \*[, ...]) | Generate video using Stable Diffusion Video.                |
| [`get_available_providers`](_autosummary/aix.video.html.md#aix.video.get_available_providers)()                          | Get list of available video generation providers.           |
| [`interpolate_frames`](_autosummary/aix.video.html.md#aix.video.interpolate_frames)(video_path, \*[, ...])          | Interpolate frames to create smoother video.                |

### Classes

| [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)([url, data, model, prompt, ...])   | Wrapper for generated videos.   |
|----------------------------------------------------------------------------------------------------|---------------------------------|

### *class* aix.video.GeneratedVideo(url=None, data=None, model=None, prompt=None, duration=None, resolution=None, status='completed', task_id=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Wrapper for generated videos.

Provides convenient access to video data and metadata.

### Examples

```pycon
>>> video = GeneratedVideo(url="https://...")
>>> video.save("output.mp4")
>>> print(video.duration)
5.0
```

#### as_bytes()

Get video as bytes.

* **Return type:**
  [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes)
* **Returns:**
  Video data as bytes

#### save(path)

Save video to file.

* **Parameters:**
  **path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Output file path
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### Examples

```pycon
>>> video.save("output.mp4")
```

#### wait_until_complete(max_wait=300, poll_interval=5)

Wait for video generation to complete (for async operations).

* **Parameters:**
  * **max_wait** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Maximum time to wait in seconds
  * **poll_interval** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Time between status checks in seconds
* **Raises:**
  * [**TimeoutError**](https://docs.python.org/3/builtins/exceptions.html#TimeoutError) – If generation doesn’t complete within max_wait
  * [**RuntimeError**](https://docs.python.org/3/builtins/exceptions.html#RuntimeError) – If generation fails
* **Return type:**
  [`None`](https://docs.python.org/3/builtins/constants.html#None)

### aix.video.animate_image(image_path, prompt=None, , model=None, duration=3.0, motion_strength=0.5, \*\*kwargs)

Animate a static image into a video.

* **Parameters:**
  * **image_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Path to the source image
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional text prompt to guide the animation
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video generation model to use
  * **duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Animation duration in seconds
  * **motion_strength** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Strength of motion (0.0 to 1.0)
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo object

### Examples

```pycon
>>> from aix.video import animate_image
>>> video = animate_image(
...     "landscape.jpg",
...     prompt="Gentle camera pan across the scene",
...     duration=4
... )
>>> video.save("animated_landscape.mp4")
```

### aix.video.estimate_cost(duration, resolution='1280x720', provider=None)

Estimate the cost of video generation.

* **Parameters:**
  * **duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Video duration in seconds
  * **resolution** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video resolution
  * **provider** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Provider name (or None for all)
* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)
* **Returns:**
  Dict with cost estimates

### Examples

```pycon
>>> from aix.video import estimate_cost
>>> cost = estimate_cost(duration=5, resolution="1920x1080")
>>> print(cost)
{'runway': 0.05, 'pika': 0.03}
```

### aix.video.extend_video(video_path, prompt=None, , extend_duration=2.0, model=None, \*\*kwargs)

Extend an existing video with additional generated content.

* **Parameters:**
  * **video_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Path to the source video
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Optional text prompt to guide the extension
  * **extend_duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – How many seconds to add
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video generation model
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo object with extended content

### Examples

```pycon
>>> from aix.video import extend_video
>>> extended = extend_video(
...     "original.mp4",
...     prompt="Continue the same scene",
...     extend_duration=3
... )
```

### aix.video.generate_video(prompt, , model=None, duration=5.0, resolution='1280x720', fps=24, aspect_ratio=None, style=None, seed=None, api_key=None, \*\*kwargs)

Generate a video from a text prompt.

#### NOTE
This is a high-level interface. Actual implementation depends on
available video generation providers (Runway, Pika, etc.) and may require
provider-specific API keys.

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text description of the video to generate
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video generation model to use
  * **duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Video duration in seconds (typically 2-10 seconds)
  * **resolution** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video resolution (‘1280x720’, ‘1920x1080’, etc.)
  * **fps** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Frames per second
  * **aspect_ratio** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Aspect ratio (‘16:9’, ‘9:16’, ‘1:1’, etc.)
  * **style** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Video style hint (provider-specific)
  * **seed** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Random seed for reproducibility
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Explicit API key for the video provider. If None, resolved from
    the environment / .env / AIX config store (see aix.credentials).
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo object
* **Raises:**
  * [**NotImplementedError**](https://docs.python.org/3/builtins/exceptions.html#NotImplementedError) – If no video provider is configured
  * [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If required provider SDK is not installed

### Examples

```pycon
>>> from aix.video import generate_video
>>> video = generate_video(
...     "A serene ocean sunset with gentle waves",
...     duration=5,
...     resolution="1920x1080"
... )
>>> video.save("sunset.mp4")
```

```pycon
>>> # Specific style
>>> video = generate_video(
...     "A futuristic city",
...     style="cyberpunk",
...     duration=4
... )
```

### aix.video.generate_video_pika(prompt, , duration=3.0, \*\*kwargs)

Generate video using Pika Labs.

Requires: PIKA_API_KEY environment variable

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text description
  * **duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Video duration
  * **\*\*kwargs** – Pika-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo object

### aix.video.generate_video_runway(prompt, , duration=5.0, \*\*kwargs)

Generate video using Runway ML.

Requires: RUNWAY_API_KEY environment variable

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text description
  * **duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Video duration
  * **\*\*kwargs** – Runway-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo object

### aix.video.generate_video_stable_diffusion(prompt, , duration=2.0, \*\*kwargs)

Generate video using Stable Diffusion Video.

Requires: Stable Diffusion Video model setup

* **Parameters:**
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Text description
  * **duration** ([`float`](https://docs.python.org/3/builtins/functions.html#float)) – Video duration
  * **\*\*kwargs** – SD-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo object

### aix.video.get_available_providers()

Get list of available video generation providers.

* **Return type:**
  [`list`](https://docs.python.org/3/builtins/stdtypes.html#list)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]
* **Returns:**
  List of provider names that are configured

### Examples

```pycon
>>> from aix.video import get_available_providers
>>> providers = get_available_providers()
>>> print(providers)
['runway', 'pika']
```

### aix.video.interpolate_frames(video_path, , target_fps=60, model=None, \*\*kwargs)

Interpolate frames to create smoother video.

* **Parameters:**
  * **video_path** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)]) – Path to the source video
  * **target_fps** ([`int`](https://docs.python.org/3/builtins/functions.html#int)) – Target frames per second
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – Frame interpolation model
  * **\*\*kwargs** – Additional provider-specific parameters
* **Return type:**
  [`GeneratedVideo`](_autosummary/aix.video.html.md#aix.video.GeneratedVideo)
* **Returns:**
  GeneratedVideo with interpolated frames

### Examples

```pycon
>>> from aix.video import interpolate_frames
>>> smooth_video = interpolate_frames(
...     "choppy.mp4",
...     target_fps=60
... )
```


# _autosummary/aix.vision.html.md

# aix.vision

Image-to-text (vision) interface for AIX.

The cross-modal counterpart to [`aix.image`](_autosummary/aix.image.html.md#module-aix.image) (which is text→image): given an
image, produce text — a caption, an answer to a question about it, or a
structured judgement. Like the rest of AIX it is a thin, provider-neutral facade
over LiteLLM’s multimodal `completion` (the same backend `chat` uses), so the
same call routes to any vision-capable provider (OpenAI, Anthropic, Gemini,
OpenRouter, …) by model id alone.

[`describe_image()`](_autosummary/aix.vision.html.md#aix.vision.describe_image) is the primitive: image (URL / local path / bytes / PIL
image / `data:` URI) + a prompt → text. [`to_image_content()`](_autosummary/aix.vision.html.md#aix.vision.to_image_content) exposes the
multimodal content block builder so callers can assemble richer messages (e.g.
multiple images in one turn) and pass them straight to [`aix.chat()`](_autosummary/aix.html.md#aix.chat).

### Examples

Caption an image (any vision-capable model):

```pycon
>>> from aix.vision import describe_image
>>> describe_image("https://example.com/cat.jpg")
'A grey tabby cat sitting on a windowsill in afternoon light.'
```

Ask a specific question:

```pycon
>>> describe_image("photo.png", prompt="What colour is the car?")
'The car is red.'
```

Build a multi-image message yourself and hand it to `chat`:

```pycon
>>> from aix import chat
>>> from aix.vision import to_image_content
>>> msg = [{"role": "user", "content": [
...     {"type": "text", "text": "Which is brighter?"},
...     to_image_content("a.jpg"), to_image_content("b.jpg"),
... ]}]
>>> chat(msg, model="gpt-4o")
'The second image is brighter.'
```

[`compare_images()`](_autosummary/aix.vision.html.md#aix.vision.compare_images) builds on these primitives: it puts a *candidate* image
beside one or more *reference* images and asks a vision model, via a structured
JSON path, for an explainable per-aspect likeness verdict — the “explain the
drift” half of a reference supervisor (face / costume / setting / lighting /
props matched?). The numeric identity-cosine gate lives elsewhere (lookbook);
this layer is the explainable checklist on top of it.

```pycon
>>> from aix.vision import compare_images
>>> verdict = compare_images("gen.png", "locked_ref.png")
>>> verdict.match, verdict["identity"].match
(True, True)
```

### Module Attributes

| [`DFLT_VISION_MODEL`](_autosummary/aix.vision.html.md#aix.vision.DFLT_VISION_MODEL)   | Shipped-default vision model, kept for reference.                                                                    |
|----------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| [`DFLT_VISION_PROMPT`](_autosummary/aix.vision.html.md#aix.vision.DFLT_VISION_PROMPT)  | Default instruction when the caller doesn't supply one.                                                              |
| [`DFLT_COMPARE_RUBRIC`](_autosummary/aix.vision.html.md#aix.vision.DFLT_COMPARE_RUBRIC) | Default rubric for [`compare_images()`](_autosummary/aix.vision.html.md#aix.vision.compare_images) — a generic likeness checklist. |
| [`DFLT_FILM_RUBRIC`](_autosummary/aix.vision.html.md#aix.vision.DFLT_FILM_RUBRIC)    | the locked face, the architecture/set, the lighting, and the props.                                                  |

### Functions

| [`describe_image`](_autosummary/aix.vision.html.md#aix.vision.describe_image)(image, \*[, prompt, model, ...])   | Describe (or answer a question about) `image` and return the text.   |
|----------------------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| [`to_image_content`](_autosummary/aix.vision.html.md#aix.vision.to_image_content)(image, \*[, detail])             | Build a multimodal `image_url` content block for `image`.            |
| [`compare_images`](_autosummary/aix.vision.html.md#aix.vision.compare_images)(candidate, reference, \*[, ...])   | Compare a `candidate` image to `reference` image(s) on a rubric.     |

### Classes

| [`RubricVerdict`](_autosummary/aix.vision.html.md#aix.vision.RubricVerdict)(aspect, match, confidence[, note])   | A vision model's verdict on a single rubric aspect.               |
|-----------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| [`ImageComparison`](_autosummary/aix.vision.html.md#aix.vision.ImageComparison)(match, confidence, explanation)    | Structured result of comparing a candidate image to reference(s). |

### aix.vision.DFLT_COMPARE_RUBRIC *= ('identity', 'costume', 'setting', 'lighting', 'props')*

Default rubric for [`compare_images()`](_autosummary/aix.vision.html.md#aix.vision.compare_images) — a generic likeness checklist.
Each entry is one aspect the vision model judges independently.

### aix.vision.DFLT_FILM_RUBRIC *= ('face_identity', 'costume', 'setting_architecture', 'lighting', 'props', 'skin_realism')*

the
locked face, the architecture/set, the lighting, and the props. Pass it as
`rubric=` when comparing a generated frame against a locked reference.

* **Type:**
  Filmmaking-oriented rubric (Noel’s reference-supervisor checklist)

### aix.vision.DFLT_VISION_MODEL *= 'gpt-4o-mini'*

Shipped-default vision model, kept for reference. The *active* default is
resolved from `aix.config` at call time (see [`aix.config.VisionConfig`](_autosummary/aix.config.html.md#aix.config.VisionConfig)).

### aix.vision.DFLT_VISION_PROMPT *= 'Describe this image in detail.'*

Default instruction when the caller doesn’t supply one.

### *class* aix.vision.ImageComparison(match, confidence, explanation, aspects=tuple(), model=None, usage=None)

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

Structured result of comparing a candidate image to reference(s).

Behaves like an ordered, read-only mapping of `aspect -> RubricVerdict`
(`comparison["identity"]`, `in`, iteration, `len`) so per-aspect
lookups read naturally, while also carrying the overall verdict.

#### match

Overall pass/fail across the whole rubric.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### confidence

Overall confidence in `[0.0, 1.0]`.

* **Type:**
  [`float`](https://docs.python.org/3/builtins/functions.html#float)

#### explanation

A short overall summary of the comparison.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### aspects

The per-aspect verdicts, one [`RubricVerdict`](_autosummary/aix.vision.html.md#aix.vision.RubricVerdict) per
rubric item, in rubric order.

* **Type:**
  [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple)[[`RubricVerdict`](_autosummary/aix.vision.html.md#aix.vision.RubricVerdict), [`...`](https://docs.python.org/3/builtins/constants.html#Ellipsis)]

#### model

The vision model id that produced the verdict.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### usage

Tokens billed for the comparison request (see
[`aix.Usage`](_autosummary/aix.html.md#aix.Usage)), or `None` if the provider did not report it.

* **Type:**
  [`Usage`](_autosummary/aix.html.md#aix.Usage) | [`None`](https://docs.python.org/3/builtins/constants.html#None)

#### get(aspect, default=None)

Return the verdict for `aspect`, or `default` if absent.

* **Return type:**
  [`RubricVerdict`](_autosummary/aix.vision.html.md#aix.vision.RubricVerdict) | [`None`](https://docs.python.org/3/builtins/constants.html#None)

### *class* aix.vision.RubricVerdict(aspect, match, confidence, note='')

Bases: [`object`](https://docs.python.org/3/builtins/functions.html#object)

A vision model’s verdict on a single rubric aspect.

#### aspect

The rubric item this verdict is about (e.g. `"identity"`).

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

#### match

Whether the candidate matches the reference for this aspect.

* **Type:**
  [`bool`](https://docs.python.org/3/builtins/functions.html#bool)

#### confidence

The model’s self-reported confidence in `[0.0, 1.0]`.

* **Type:**
  [`float`](https://docs.python.org/3/builtins/functions.html#float)

#### note

A short free-text explanation of the verdict.

* **Type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)

### aix.vision.compare_images(candidate, reference, , rubric=('identity', 'costume', 'setting', 'lighting', 'props'), model=None, api_key=None, max_tokens=None, temperature=0.0, detail=None, instruction='You are a strict visual continuity supervisor. The FIRST image is the CANDIDATE; the remaining image(s) are the locked REFERENCE the candidate must match. Judge each rubric aspect INDEPENDENTLY (do not let one aspect color another). For each aspect decide whether the candidate matches the reference, give a confidence in [0.0, 1.0], and a short note explaining what matches or drifts. Then give an overall match (true only if every important aspect matches), an overall confidence, and a one-sentence explanation.', \*\*kwargs)

Compare a `candidate` image to `reference` image(s) on a rubric.

The explainable half of a reference supervisor: a vision model returns a
per-aspect pass/fail checklist (does the face match? the costume? the set?
the lighting? the props?) plus an overall verdict — the explainable layer
over a cheap numeric identity-cosine gate (which lives elsewhere, e.g.
lookbook). Built on [`to_image_content()`](_autosummary/aix.vision.html.md#aix.vision.to_image_content) (multi-image content block)
and the same multimodal `completion` path as [`describe_image()`](_autosummary/aix.vision.html.md#aix.vision.describe_image),
asked via a JSON contract for a structured answer.

The comparison is *pointwise* (each aspect judged on its own), not a ranked
pairwise comparison, to avoid position bias.

* **Parameters:**
  * **candidate** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – The image under review (URL / path / bytes / PIL image /
    `data:` URI — anything [`to_image_content()`](_autosummary/aix.vision.html.md#aix.vision.to_image_content) accepts).
  * **reference** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any), [`Sequence`](https://docs.python.org/3/library/typing.html#typing.Sequence)[[`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]]) – The locked reference — a single image *or* a sequence of
    images (a locked set) in the same flexible formats. An empty
    sequence is an error.
  * **rubric** ([`Sequence`](https://docs.python.org/3/library/typing.html#typing.Sequence)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str)]) – The aspects to evaluate, one verdict per item. Defaults to
    [`DFLT_COMPARE_RUBRIC`](_autosummary/aix.vision.html.md#aix.vision.DFLT_COMPARE_RUBRIC); pass [`DFLT_FILM_RUBRIC`](_autosummary/aix.vision.html.md#aix.vision.DFLT_FILM_RUBRIC) (or any
    custom sequence) to override — e.g. `("face", "architecture",
    "props", "lighting")`. Must be non-empty.
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Vision-capable model id or alias. `None` → the configured
    default ([`aix.config.VisionConfig`](_autosummary/aix.config.html.md#aix.config.VisionConfig)).
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Explicit API key; `None` resolves it for the model’s
    provider from the environment / `.env` / config store.
  * **max_tokens** ([`int`](https://docs.python.org/3/builtins/functions.html#int) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Cap on generated tokens (`None` → provider default).
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Sampling temperature (default `0.0` for a stable,
    reproducible verdict; `None` → provider default).
  * **detail** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Image detail hint (`"low"` | `"high"` | `"auto"`),
    applied to every image block.
  * **instruction** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The system-style framing prepended to the rubric. Has a
    sensible default; override to retune the supervisor’s strictness.
  * **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any)) – Extra provider-specific params forwarded to LiteLLM.
* **Return type:**
  [`ImageComparison`](_autosummary/aix.vision.html.md#aix.vision.ImageComparison)
* **Returns:**
  An [`ImageComparison`](_autosummary/aix.vision.html.md#aix.vision.ImageComparison) — overall `match` / `confidence` /
  `explanation` plus an ordered, mapping-like collection of
  [`RubricVerdict`](_autosummary/aix.vision.html.md#aix.vision.RubricVerdict) (one per rubric aspect, keyed by aspect).
* **Raises:**
  * [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed.
  * [**ValueError**](https://docs.python.org/3/builtins/exceptions.html#ValueError) – If `rubric` is empty or `reference` is an empty
        sequence, or if the model’s reply can’t be parsed as the expected
        JSON verdict.

### Examples

Default rubric, single reference:

```pycon
>>> compare_images("gen.png", "ref.png")
ImageComparison(match=True, confidence=0.9, ...)
```

Filmmaking rubric, a locked reference *set*:

```pycon
>>> from aix.vision import DFLT_FILM_RUBRIC
>>> compare_images(
...     candidate="frame_042.png",
...     reference=["ref_front.png", "ref_side.png"],
...     rubric=DFLT_FILM_RUBRIC,
... )["face_identity"].match
True
```

### aix.vision.describe_image(image, , prompt='Describe this image in detail.', model=None, api_key=None, max_tokens=None, temperature=None, detail=None, \*\*kwargs)

Describe (or answer a question about) `image` and return the text.

The image→text primitive. `image` accepts a URL, a local path, raw bytes,
a PIL image, or a `data:` URI (see [`to_image_content()`](_autosummary/aix.vision.html.md#aix.vision.to_image_content)). `prompt` is
the instruction (default: a generic “describe this image”); pass a question
for VQA or a rubric for a judgement. Everything past `image` is keyword.

* **Parameters:**
  * **image** ([`Union`](https://docs.python.org/3/library/typing.html#typing.Union)[[`str`](https://docs.python.org/3/builtins/stdtypes.html#str), [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path), [`bytes`](https://docs.python.org/3/builtins/stdtypes.html#bytes), [`Any`](https://docs.python.org/3/library/typing.html#typing.Any)]) – The image (URL / path / bytes / PIL image / `data:` URI).
  * **prompt** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – The text instruction accompanying the image.
  * **model** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Vision-capable model id (e.g. `gpt-4o`, `claude-sonnet-4-6`,
    `gemini/gemini-1.5-pro`) or an alias. `None` → the configured
    default ([`aix.config.VisionConfig`](_autosummary/aix.config.html.md#aix.config.VisionConfig)).
  * **api_key** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Explicit API key; `None` resolves it from the environment /
    `.env` / config store for the model’s provider.
  * **max_tokens** ([`int`](https://docs.python.org/3/builtins/functions.html#int) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Cap on generated tokens (`None` → provider default).
  * **temperature** ([`float`](https://docs.python.org/3/builtins/functions.html#float) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Sampling temperature (`None` → provider default).
  * **detail** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) | [`None`](https://docs.python.org/3/builtins/constants.html#None)) – Image detail hint (`"low"` | `"high"` | `"auto"`).
  * **\*\*kwargs** ([`Any`](https://docs.python.org/3/library/typing.html#typing.Any)) – Extra provider-specific params forwarded to LiteLLM.
* **Return type:**
  [`str`](https://docs.python.org/3/builtins/stdtypes.html#str)
* **Returns:**
  The model’s text response.
* **Raises:**
  [**ImportError**](https://docs.python.org/3/builtins/exceptions.html#ImportError) – If LiteLLM is not installed.

```pycon
>>> describe_image("cat.jpg", prompt="Caption it.")
'A cat on a sofa.'
```

For usage, several samples (`n`) or validated structured output, send the
same image content through [`aix.complete()`](_autosummary/aix.html.md#aix.complete) (or [`aix.sample()`](_autosummary/aix.html.md#aix.sample)):

```pycon
>>> from aix import complete
>>> c = complete([{"role": "user", "content": [
...     {"type": "text", "text": "Caption it."}, to_image_content("cat.jpg")]}],
...     model="gpt-4o-mini", n=3)
>>> c.texts, c.usage
```

### aix.vision.to_image_content(image, , detail=None)

Build a multimodal `image_url` content block for `image`.

`image` may be:

- an `http(s)://` URL or a `data:` URI — passed through verbatim;
- a local file path (`str` or [`Path`](https://docs.python.org/3/library/pathlib.html#pathlib.Path)) — read and inlined
  as a base64 `data:` URI with a guessed MIME type;
- raw `bytes` — base64-inlined (MIME sniffed from magic bytes, else JPEG);
- a PIL `Image` — encoded to PNG and inlined.

`detail` (`"low"` | `"high"` | `"auto"`) is forwarded when set; the
block is the OpenAI/LiteLLM multimodal shape understood across providers.

```pycon
>>> to_image_content("https://x/y.jpg")
{'type': 'image_url', 'image_url': {'url': 'https://x/y.jpg'}}
>>> to_image_content("data:image/png;base64,AAAA")["image_url"]["url"][:10]
'data:image'
```

* **Return type:**
  [`dict`](https://docs.python.org/3/builtins/stdtypes.html#dict)


# about-this-build.html.md

<!-- generated by epythet -->

# About this build

This documentation was built on **2026-11-23 07:25 UTC** from commit <a href="https://github.com/addaix/aix/commit/2859d9c4b5401df3f3e90e6bd2121a4359cd32a8"><code>2859d9c</code></a> on branch <code>master</code>, for **aix 0.0.62** (from <code>pyproject.toml</code>).

#### WARNING
The documentation and the package may be misaligned:

- The documented version (0.0.62) is behind the latest release on PyPI (0.0.63): `pip install aix` gives newer code than these docs describe.

## Source

|                     |                                                                                                                                                   |
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| Commit              | <a href="https://github.com/addaix/aix/commit/2859d9c4b5401df3f3e90e6bd2121a4359cd32a8"><code>2859d9c4b5401df3f3e90e6bd2121a4359cd32a8</code></a> |
| Branch              | <code>master</code>                                                                                                                               |
| Tags at this commit | none                                                                                                                                              |
| Working tree        | clean                                                                                                                                             |
| Remote              | <code>https://github.com/addaix/aix</code>                                                                                                        |

## Continuous integration

|              |                                                                                            |
|--------------|--------------------------------------------------------------------------------------------|
| Repository   | <code>addaix/aix</code>                                                                    |
| Run          | <a href="https://github.com/addaix/aix/actions/runs/45130720190">45130720190</a>           |
| Ref          | <code>refs/heads/master</code>                                                             |
| Event commit | <code>2859d9c4b5401df3f3e90e6bd2121a4359cd32a8</code> (in the history of the built commit) |

## Tools

|          |         |
|----------|---------|
| epythet  | 0.2.24  |
| Sphinx   | 9.1.1   |
| docutils | 0.22.4  |
| Python   | 3.12.16 |

## Configuration as resolved

|               |                                                                  |
|---------------|------------------------------------------------------------------|
| theme         | <code>auto</code> (Sphinx theme <code>furo</code>)               |
| accent        | <code>#2b559f</code>                                             |
| api_generator | <code>autosummary</code>                                         |
| ignore        | <code>tests/</code>, <code>scrap/</code>, <code>examples/</code> |
| agent_outputs | <code>true</code>                                                |
| aggregates    | <code>md</code>                                                  |
| ai_artifacts  | <code>true</code>                                                |

## Package on PyPI

Latest release: <a href="https://pypi.org/project/aix/0.0.63/">0.0.63</a>, newer than the documented version (0.0.62).

## Reproduce

```bash
git clone https://github.com/addaix/aix && cd aix
git checkout 2859d9c4b5401df3f3e90e6bd2121a4359cd32a8
pip install "epythet==0.2.24"
epythet quickstart . --ignore tests/ scrap/ examples/
```

The same data, for machines: <a href="build_info.json"><code>build_info.json</code></a> (schema version 1).


# ai-agents.html.md

<!-- generated by epythet -->

# For AI agents

`aix` ships artifacts for coding agents alongside its code. This page lists
them, says where each lives in the repository, and points at the
machine-readable copies of this documentation.

## Instruction files

Files agents read before working in this repository.

- [`.claude/CLAUDE.md`](https://github.com/thorwhalen/aix/tree/HEAD/.claude/CLAUDE.md): read by Claude Code

## Machine-readable documentation

This site publishes the same documentation in forms that fit an agent’s context window:

- [`llms.txt`](https://thorwhalen.github.io/aix/llms.txt): an index of every page with a one-line description ([llms.txt](https://llmstxt.org) format)
- [`aix.md`](https://thorwhalen.github.io/aix/aix.md): the whole documentation as one Markdown file
- `<page>.html.md`: a rendered Markdown twin of every page, advertised from each page’s `<head>` with `<link rel="alternate" type="text/markdown">`
- [`objects.inv`](https://thorwhalen.github.io/aix/objects.inv): the Sphinx inventory: a symbol-to-URL index (`sphobjinv convert plain objects.inv -`)


# api.html.md

# API reference

| [`aix`](_autosummary/aix.html.md#module-aix)   | AIX: Artificial Intelligence eXtensions   |
|-------------------------------------------------------------------|-------------------------------------------|


