Configuration
Configuration model hierarchy and environment overrides.
#Configuration
The mAIvn SDK uses a layered configuration system that supports environment variables and programmatic configuration.
For HTTP credentials and endpoints, use ClientConfig.from_sources(...) or the corresponding Client constructor options. Agent and Swarm also accept api_key, env_file, and api_key_file. Terminal MAIVN_API_KEY values take precedence over selected files. MAIVN_API_KEY_FILE supports a mounted single-line secret. See Authentication for exact precedence, shared-client behavior, and file handling.
This page covers SDK environment and process-level settings. Invocation-time runtime controls such as memory, system tools and model selection are documented in Session Config Models.
#Import
from maivn import (
ConfigurationBuilder,
MaivnConfiguration,
get_configuration,
)#MaivnConfiguration
A compatibility view of SDK settings. Use ClientConfig for the current HTTP client configuration, or ClientBuilder.from_configuration(config) to convert this nested representation explicitly.
class MaivnConfiguration:
server: ServerConfiguration
execution: ExecutionConfiguration
security: SecurityConfiguration#ServerConfiguration
Server connection settings.
#ExecutionConfiguration
Execution settings.
server.timeout_seconds controls the HTTP request timeout. MaivnConfiguration and its sections refuse fields they do not know, so a removed setting raises a validation error instead of being ignored. See Upgrading to SDK 3.
#Tool timeout
tool_execution_timeout is sent as the timeout of each SDK tool. A tool that runs longer ends with a timeout, and the value also bounds how long a human-approval tool can wait. The default is 600 seconds, and values above 600 are sent as 600. Set it on Client, ClientConfig, the builders, MaivnConfiguration.execution.tool_execution_timeout_seconds or per call with RunOptions(tool_execution_timeout=...), which wins over the client value.
#SecurityConfiguration
Authentication settings.
API keys are hidden in representations and human-readable validation errors. Explicit model_dump() and to_dict() output contains the key. Do not log it.
MaivnConfiguration also offers from_dict(mapping), to_dict() and to_client_config().
#ClientConfig
ClientConfig is the frozen configuration a Client actually uses. Build one with ClientConfig.from_sources(...) and pass it as Client(config=...).
from maivn import ClientConfig
config = ClientConfig.from_sources(api_key='your-api-key', timeout_seconds=60)
print(config.base_url_text, config.timeout_seconds)from_sources resolves explicit arguments first, then the process environment, then a selected dotenv file, then a selected key file. A missing credential raises ConfigurationError, and so does an env_file that does not exist.
#Concurrent-job wait
When your team already has as many runs in progress as its plan allows, the platform refuses a new run start, or an answer that would resume a paused run, with HTTP 429 and the code concurrent_jobs_limit_reached. The SDK waits as long as the platform asks and sends the same request again, until the total wait would pass concurrent_jobs_wait_seconds; then it raises ConcurrentJobsLimitError. This applies to invoke, stream, thread starts and messages, time travel and hosted job starts, and to approvals, interrupt responses and follow-up answers. Set it on Client(concurrent_jobs_wait_seconds=...), ClientConfig or ClientConfig.from_sources(...). See Concurrent jobs.
#ConfigurationBuilder
Factory for creating configuration from various sources. ConfigurationBuilder.from_dict(mapping) builds a MaivnConfiguration from a raw mapping.
#from_environment()
Create configuration from environment variables.
config = ConfigurationBuilder.from_environment()
# Optional explicitly selected file; process environment still wins.
config = ConfigurationBuilder.from_environment(env_file="/path/to/project/.env")Both ConfigurationBuilder.from_environment() and ClientBuilder.from_environment() accept the source options of ClientConfig.from_sources() except default_user_id. These include env_file, api_key_file, base_url, project_id, thread_id and the timeout settings. They share the credential precedence rules. Converting a builder-produced configuration to a client preserves the resolved endpoints and settings. No implicit dotenv or shell PATH search occurs.
#Environment Variables
The local-store variables are read when automatic private storage is needed. They are separate from ClientConfig and the compatibility configuration tables above. They read the process environment. Selecting Client(env_file=...) does not load these vault settings from that file. Explicit Client(local_vault=LocalVaultConfig(...)) replaces environment-based vault configuration. See local storage setup.
#Configuration Functions
#get_configuration()
Get the current active configuration.
from maivn import get_configuration
config = get_configuration()
print(config.server.timeout_seconds)If no configuration is set, returns a default configuration.
This is a compatibility context. To use its values, pass the configuration to ClientBuilder.from_configuration(). Client() and Agent() resolve their own explicit arguments and environment. They do not automatically consult this context.
#Examples
#Environment-Based Configuration
# .env file
MAIVN_API_KEY=your-api-key
# The SDK defaults to https://api.maivn.io; availability depends on your environment.
# Local development opts into a local address explicitly:
MAIVN_BASE_URL=http://127.0.0.1:8000from maivn import Agent, ClientBuilder, ConfigurationBuilder
# Select a dotenv file, with exported values taking precedence.
config = ConfigurationBuilder.from_environment(env_file=".env")
# Agent uses this configuration
agent = Agent(name='my_agent', client=ClientBuilder.from_configuration(config))#Checking Configuration
from maivn import get_configuration
config = get_configuration()
print(f'API Key set: {bool(config.security.api_key)}')
print(f'API address: {config.server.base_url}')#Client with Custom Timeouts
from maivn import Client
# Override the HTTP request timeout and the per-tool timeout.
client = Client(
api_key='...',
timeout_seconds=60,
tool_execution_timeout=120,
)Invocation RunOptions(timeout=...) can select an HTTP timeout for one request.
#Configuration Hierarchy
Use ClientConfig.from_sources() to resolve explicit values, environment, selected dotenv, and built-in defaults. Supply the resulting config= or share the client with scopes. ClientBuilder.from_configuration() converts the specific nested configuration you pass. It does not consult the active configuration context.
#See Also
- Client - Client timeout configuration
- Session Config Models - Typed invocation runtime controls
- Logging - Logging configuration