Skip to content

Documentation navigation

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

Python
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.

Python
class MaivnConfiguration:
    server: ServerConfiguration
    execution: ExecutionConfiguration
    security: SecurityConfiguration

#ServerConfiguration

Server connection settings.

FieldDefaultDescription
base_urlhttps://api.maivn.ioThe one public API address
project_idNoneServing project identity
timeout_seconds30.0HTTP request timeout

#ExecutionConfiguration

Execution settings.

FieldDefaultDescription
tool_execution_timeout_seconds600.0How long a tool may run before it ends with a timeout. Carried into ClientConfig.tool_execution_timeout. See Tool timeout
thread_idNoneDefault conversation identity

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.

FieldTypeDefaultDescription
api_keystr | NoneNoneAPI key for authentication

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=...).

Python
from maivn import ClientConfig

config = ClientConfig.from_sources(api_key='your-api-key', timeout_seconds=60)
print(config.base_url_text, config.timeout_seconds)
FieldDefaultDescription
api_keyrequiredAPI key. Hidden in repr and validation errors.
base_urlhttps://api.maivn.ioThe one public API address. base_url_text returns it as a string.
timeout_seconds30.0HTTP request timeout. Must be greater than 0.
project_idNoneProject a serving process announces into. Never inferred from the key.
thread_idNoneDefault thread for calls that omit one.
default_user_idNoneCustomer ID for runs that do not set RunOptions.user_id. For trusted backends.
tool_execution_timeout600.0Seconds a tool may run before it ends with a timeout. Sent as each tool's timeout; values above 600 are sent as 600. Greater than 0. See Tool timeout.
concurrent_jobs_wait_seconds60.0Total seconds a run start may wait when your team is at its concurrent-job limit, before the SDK raises ConcurrentJobsLimitError. 0 raises at once. From 0 to 600. See Concurrent-job wait.

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.

Python
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

VariableConfig PathDescription
MAIVN_API_KEYsecurity.api_keyAPI key for authentication
MAIVN_API_KEY_FILECredential sourceExplicit path to a single-line key file, used when no key value exists
MAIVN_PROJECT_IDserver.project_idServing project identity
MAIVN_BASE_URLserver.base_urlThe one public API address (defaults to https://api.maivn.io)
MAIVN_DEFAULT_USER_IDdefault_user_idCustomer ID for runs that do not set RunOptions.user_id.
MAIVN_DEPLOYMENT_TIMEZONEPer-call optionSets RunOptions.sdk_deployment_timezone when a call leaves it unset
MAIVN_VAULT_DIRECTORYLocal private-data storeAbsolute durable parent directory for encrypted caller values
MAIVN_VAULT_KEYLocal private-data storeBase64-encoded 32-byte key injected by your secret manager

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.

Python
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

Shell
# .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:8000
Python
from 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

Python
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

Python
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