Skip to content

Configuration API

anyinfer.CONFIG_FORMAT_VERSION module-attribute

CONFIG_FORMAT_VERSION = 1

The configuration format version written and understood by this release.

anyinfer.MAX_CONFIG_BYTES module-attribute

MAX_CONFIG_BYTES = 1024 * 1024

Maximum accepted configuration size.

anyinfer.AnyInferConfig dataclass

AnyInferConfig(
    providers: tuple[ProviderSettings, ...] = (),
    route: Route | None = None,
    format_version: int = CONFIG_FORMAT_VERSION,
)

Validated configuration shared by every AnyInfer integration surface.

Pass providers and route directly to Client or AsyncClient. The same object is used by the command-line runner and OpenAI-compatible sidecar.

Attributes:

Name Type Description
providers tuple[ProviderSettings, ...]

Configured provider instances, in declaration order.

route Route | None

Default fallback route, when one was configured.

format_version int

Parsed file-format version.

anyinfer.load_config

load_config(
    path: str | Path,
    *,
    registry: ProviderRegistry | None = None,
) -> AnyInferConfig

Read and validate an AnyInfer JSON configuration file.

Parameters:

Name Type Description Default
path str | Path

File to read.

required
registry ProviderRegistry | None

Provider registry used to validate setup-field names. Defaults to the process-wide registry, including installed third-party providers.

None

Raises:

Type Description
ConfigError

If the file cannot be read or does not match the shared format.

anyinfer.loads_config

loads_config(
    text: str,
    *,
    source: str = "<string>",
    registry: ProviderRegistry | None = None,
) -> AnyInferConfig

Parse and validate AnyInfer configuration from a JSON string.

Parameters:

Name Type Description Default
text str

UTF-8 JSON text.

required
source str

Human-readable source name included in validation errors.

'<string>'
registry ProviderRegistry | None

Provider registry used to validate setup-field names.

None

Raises:

Type Description
ConfigError

If the text is too large, invalid JSON, or has invalid fields.