Based Mdels

Agent Loop docs

Configuration

Use Settings to validate a mapping before constructing a client. This example creates an OpenAI client with a placeholder credential; constructing and closing it makes no model request:

from agentloop import Settings, build_client

settings = Settings.from_env({
    "LLM_PROVIDER": "openai",
    "OPENAI_API_KEY": "example-key",
    "OPENAI_MODEL": "example-model",
    "LLM_MAX_ATTEMPTS": "2",
})
client = build_client(settings)
try:
    print(client.name, client.model)
    print(f"max attempts: {settings.max_attempts}")
finally:
    client.close()

Output:

openai example-model
max attempts: 2

The application supplies the mapping. Pass os.environ when you want process environment variables; Settings.from_env() does not read them on its own. build_client() applies the configured retry policy, and the caller closes the client it created.

Environment variables

VariableDefaultMeaning
LLM_PROVIDERopenrouteranthropic, openai, openrouter, or modal
LLM_MAX_ATTEMPTS3Total attempts, including the first request
LLM_TIMEOUT_SECONDSprovider defaultRead timeout for one model call (Anthropic: the SDK's overall timeout)
ANTHROPIC_API_KEYunsetAnthropic credential
ANTHROPIC_MODELclaude-opus-5Anthropic model
OPENAI_API_KEYunsetOpenAI credential
OPENAI_MODELgpt-5.1OpenAI model
OPENAI_APIresponsesresponses or completions
OPENROUTER_API_KEYunsetOpenRouter credential
OPENROUTER_MODELopenrouter/freeOpenRouter model or router
MODAL_ENDPOINT_URLunsetBase URL of the deployed endpoint
MODAL_ENDPOINT_MODELQwen/Qwen3.6-35B-A3B-FP8Model exposed by Modal/vLLM
MODAL_PROXY_TOKEN_IDunsetOptional Modal proxy token ID
MODAL_PROXY_TOKEN_SECRETunsetOptional Modal proxy token secret

You can also construct Settings directly when values come from application configuration or a secrets service:

from pydantic import SecretStr

from agentloop import Settings

settings = Settings(
    provider="openai",
    openai_api_key=SecretStr("example-key"),
    openai_model="example-model",
    max_attempts=2,
)
print(settings.provider, settings.model, settings.max_attempts)

Output:

openai example-model 2

The keys above are placeholders; no request is sent by either example. Replace them with application-supplied credentials before calling a provider. Settings rejects unknown fields, invalid provider names, and nonpositive attempt or timeout values.

See the config API for every field.