Profiles
Name a provider, model, params and key once, then select it by name.
A profile is a named combination of provider, model, params, options and API key. Define fast and planner once, then pick one per call, per agent, or per run. Without profiles, nothing changes.
π οΈ Define
In boxlang.json:
{
"modules": { "bxai": { "settings": {
"provider": "openai",
"profiles": {
"fast": {
"description": "Cheap and quick, for small tasks",
"provider": "openai",
"model": "gpt-4.1-mini",
"params": { "temperature": 0 },
"apiKeyEnv": "OPENAI_API_KEY"
},
"planner": {
"description": "Slower and smarter, for planning",
"provider": "claude",
"model": "claude-opus-5-5",
"params": { "temperature": 0.7, "max_tokens": 8192 },
"apiKeyEnv": "CLAUDE_API_KEY"
}
},
"defaultProfile": ""
} } }
}description
Free text for people and UIs. Returned by aiProfile() and aiProfiles()
provider
Provider key. Empty uses the top level provider
model
Shorthand for params.model
params
Request params for this profile
options
Request options for this profile, such as timeout
apiKeyEnv
The name of the environment variable that holds the key. Preferred
apiKey
A literal key. Avoid it
The profile default always exists. It is your top level provider, apiKey and defaultParams. Set defaultProfile to make another profile the one used when a call names no provider.
Rules, checked when the module starts: a profile cannot be named like a provider (openai, claude, ...) or default, names use letters, numbers, _ and -, and defaultProfile must exist. A broken setting throws InvalidConfiguration.
π― Use
An explicit provider, key, param or option in the call always wins. Params layer from lowest to highest: defaultParams, providers.<name>.params, the profile, the call. An unknown profile throws ProfileNotFound.
π Switch an agent
The middleware, skills and MCP servers of the agent's model also stay. agent.setModel( model ) sets the profile to the one the new model was built from, or empty when it has none.
stream() takes the same profile option. To give a sub-agent its own profile, create it with one: aiAgent( name: "researcher", profile: "planner" ), then pass it in subAgents.
π List
Built for chat UIs and remote control, such as /profile and /provider commands:
See aiProfiles, aiProfile and aiProviders.
π Keys stay secret
Use
apiKeyEnv. The key is read from the environment when the profile is used.Listings return
hasApiKeyand the variable name, never the key. Params and options that look like secrets (key,token,secret,password) show as****.A profile key is only sent to the profile's own provider. The same goes for its params (including its model) and options:
aiChat( "Hi", {}, { profile: "fast", provider: "claude" } )sends none of them to Claude.Profiles are never copied into request options, so they do not reach logs or events.
π‘ Event
onAIProfileSwitch fires when an agent changes profile. See events.
Last updated