Aex Brain
Runtime reference

Models & providers

Select models, configure provider API keys, set reasoning effort, route through custom endpoints, and preserve prompt caches.

Brain delegates model inference to the harness runner while keeping provider credentials and transport configuration under host control. When you create a session, you set its model and optional reasoning effort in config.

Model ID format and validation

Pass config.model in provider/model format (1–256 characters) when calling POST /sessions:

{
  "harness": "pi",
  "config": {
    "model": "openai/gpt-4.1-mini",
    "reasoning_effort": "low",
    "tools": []
  }
}

Model validation happens in two steps:

  1. Session creation (POST /sessions): Brain splits config.model on the first /, verifies that the provider prefix is installed, and selects an authorized private session credential or the startup default. Missing slashes, unknown providers, or missing credentials fail immediately with 400 invalid_request. Application policy denials return 403 forbidden.
  2. Turn execution (Pi runner startup): When the first user.message starts the Pi runner, the runner looks up provider and model in its pinned offline Model catalog (allowModelNetwork: false, refreshOnCreate: false). If the model ID is not in the catalog or the harness falls back to a different model, the turn fails with a session.error (brain_error) event.

Explicit credentials only

Brain authenticates providers with explicit API keys. It passes the resolved key privately to the selected runner and strips ambient authentication environment variables when spawning harness processes. Credential scope follows the selected adapter.

Configure providers

Declare each provider prefix in the providers map of your host configuration file (brain.json):

{
  "providers": {
    "openai": { "api_key_env": "OPENAI_API_KEY" },
    "anthropic": { "api_key_env": "ANTHROPIC_API_KEY" }
  }
}

When api_key_env is present, that environment variable must be set and non-empty when brain starts (or when running brain -check). Omit it to require a private session credential. If a provider's API key changes in the host environment while Brain is running, Brain recycles any idle runner using the old credential before the next turn.

Private model credentials

POST /sessions accepts model_credential separately from config and tool credentials. Creation requires session-management authority and an independent credential key. Application provider authorization runs at admission and before each turn. The JSON-encoded credential object is limited to 65,536 bytes; the total HTTP request body limit also applies.

FieldTypeRequiredDefaultDescription
model_credential.api_keystringExactly one source—Non-empty provider API key, up to 65,536 bytes; the total HTTP request body limit also applies.
model_credential.referencestringExactly one source—Non-empty reference, up to 1,024 bytes. The installed application's resolver authorizes and resolves it in the session tenant's scope.

An override takes precedence over the startup key. Rejected, revoked, unavailable, or missing override records fail explicitly without selecting the default. Direct keys and reference selections are encrypted before admission succeeds and included as encrypted recovery records in checkpoints. Public configuration, events, and model arguments contain neither the key nor the reference. Clients cannot supply provider endpoints through this field.

Use Model(name, ApiKey(key)) or Model(name, CredentialReference(reference)) in the TypeScript and Python clients. The Go application SDK installs defaults and authorization through Options.Models and administers overrides with Server.RotateCredentials and Server.RevokeModelCredential.

Reasoning effort

Set config.reasoning_effort when creating a session to control extended thinking or reasoning tokens:

ValueDescription
"off"Default when reasoning_effort is omitted or "". Disables extended reasoning.
"minimal", "low", "medium", "high", "xhigh", "max"Requests the corresponding thinking level from the Pi harness.

Codex accepts off, minimal, low, medium, high and xhigh; max returns 422 unsupported at admission. OpenCode accepts off and rejects other effort selections at admission. Empty values normalize to off.

  • Any value outside this set is rejected at session creation with 400 invalid_request.
  • When the Pi runner opens the session, it checks session.thinkingLevel === options.config.reasoning_effort. If the selected model does not support the requested reasoning effort, the runner fails the turn explicitly with session.error ("requested reasoning effort is unsupported by the model") rather than silently downgrading it.

Custom endpoints and proxies

Each entry in providers accepts optional base_url and api fields to route a catalog provider through an HTTP(S) proxy or OpenAI-compatible gateway:

{
  "providers": {
    "openai": {
      "api_key_env": "OPENAI_API_KEY",
      "base_url": "https://my-proxy.example.com/v1",
      "api": "openai-completions"
    }
  }
}
  • base_url: Must be a valid http or https URL with a host and no embedded user credentials.
  • api: Overrides the transport protocol used by the Pi runtime for that provider (for example, "openai-completions" or "openai-responses").
  • Catalog scope: base_url and api override transport settings for models that already exist under that provider in the Model catalog; they do not register arbitrary new model IDs.

The catalog lookup and transport override above describe Pi. Codex and OpenCode require openai-responses (or an omitted api, selecting Responses); another transport returns 422 unsupported before admission. Their native provider uses the selected model suffix at the installed endpoint. The application authorizes provider/model selections. OpenCode's installed model definition uses a 200,000-token context and 32,000-token output limit.

Prompt caching

Brain and the Pi runner are structured to keep provider prompt prefixes stable across turns, evictions, and checkpoint restores:

  • Stable prompt prefixes: The system prompt (config.instructions) and tool definitions (config.tools) stay constant while a turn runs so provider prompt prefixes remain cacheable across model calls.
  • Clean system prompts: The Pi runner overrides before_agent_start so Pi uses your exact config.instructions (defaulting to "You are a helpful assistant. Use the available tools when needed.") without appending the runner's private local working directory path, which would invalidate prompt caches when a session moves to another server.
  • Native state restoration: Reloading an evicted session or restoring an external checkpoint opens Pi's native .jsonl session file (SessionManager.open) instead of rebuilding prompts from flattened event text.
  • No background cache warming: Upstream background cache-warming timers are disabled (cacheWarming: "off") so idle sessions never make background LLM calls or incur unexpected token charges.

On this page