Skip to content

Configure Providers & Models ​

Configure a server-side model connection once, then use it from AI Scenes or private Chat. Provider credentials stay on the backend.

Configure a deployment ​

The module registers openai, anthropic and openaiCompatible factories but intentionally ships no production model ID or credential. For a single default connection, supply these backend environment variables through your deployment configuration:

VariableModule configuration targetDefault when unset or empty
AI_PROVIDER_DEFAULT_FACTORYaiProviders.default.factoryUnset; choose openai, anthropic or openaiCompatible, or another registered factory
AI_PROVIDER_DEFAULT_BASEURLaiProviders.default.options.baseURLUnset; SDK default for openai/anthropic; required for openaiCompatible
AI_PROVIDER_DEFAULT_APIKEYaiProviders.default.options.apiKeyUnset; openai and anthropic require an effective configured key; compatible endpoints may allow no key
AI_MODEL_DEFAULT_PROVIDERaiModels.default.providerdefault
AI_MODEL_DEFAULT_MODELIDaiModels.default.modelIdUnset; choose a model supported by the selected provider

The factory name selects an entry in providerFactories; the model's provider name references a connection in aiProviders. They are different identities. For example, set AI_PROVIDER_DEFAULT_FACTORY to anthropic and AI_MODEL_DEFAULT_MODELID to claude-opus-5, and supply the key through AI_PROVIDER_DEFAULT_APIKEY. Leave AI_MODEL_DEFAULT_PROVIDER unset to use the default connection. Changing it does not create a connection: the referenced connection must already be defined in application/instance configuration or the instance's provider table.

Environment values become module defaults during startup configuration assembly. Application module configuration, instance configuration and then AI-specific database overrides take precedence. Changing the deployment environment requires restarting the affected backend process; a new scene invocation alone does not reload environment configuration. Database changes, in contrast, are resolved by a newly created invocation. In managed test mode, the module substitutes its mock factory, test key and test model before later application/instance overrides.

Installing the suite without a configured model is allowed. An attempted invocation rejects incomplete model/provider configuration or a missing required credential rather than silently choosing a production provider or its API-key environment fallback. The openaiCompatible factory permits an omitted key for endpoints that intentionally require no authentication.

For multiple connections or additional generation settings, supply aiModels.default and its provider in the application's cabloy-ai module configuration. For example, this configuration fragment obtains the key from deployment-owned code:

ts
config.modules = {
  'cabloy-ai': {
    aiProviders: {
      primary: {
        factory: 'anthropic',
        options: { apiKey: deploymentCredentials.aiApiKey },
      },
    },
    aiModels: {
      default: {
        provider: 'primary',
        modelId: 'claude-opus-5',
        generation: { temperature: 0.2 },
        request: { maxRetries: 0 },
      },
    },
  },
};

deploymentCredentials represents your existing server-side deployment configuration, not a Cabloy AI service to install. Do not commit real keys to source control. Choose a model ID supported by your account and installed provider. Configuration alone enables scene calls; no administration page or configuration-row bootstrap is needed. No provider request occurs merely by registering configuration.

For another provider, import its SDK factory in trusted backend code, declare its package dependency in the owning module, and add it to providerFactories. The factory receives connection options and returns a provider with languageModel(modelId). Custom server-side fetch and provider-specific connection options belong here, never in a database document.

AI SDK configuration ownership ​

text
providerFactories (code)
  → aiProviders (configuration + instance DB overrides)
  → aiModels (configuration + instance DB overrides)
  → AiScene (code registration + instance configuration/DB overrides)
  → this.bean.ai.create(...)
LayerMeaningDatabase behavior
providerFactoriesTrusted SDK provider creation functionsCannot be registered or replaced by database rows
aiProvidersNamed provider connections and connection optionsOverride a configured connection or add a connection using a registered factory
aiModelsNamed language models and generation defaultsOverride a configured model or add a model referencing an effective provider
AiSceneCode-owned business scene and default model selectionOverride a registered scene; cannot create a new scene

A deployment can run entirely from code configuration. Reading configuration does not create corresponding database rows. Ordinary persisted conversation/run records are separate from configuration records.

Shared base configuration ​

base.aiProviders supplies common provider defaults and base.aiModels supplies common model defaults. The module ships this base:

ts
base: {
  aiProviders: {
    enabled: true,
    options: { headers: { 'accept-encoding': 'identity' } },
  },
  aiModels: {
    enabled: true,
    request: { maxRetries: 0 },
  },
},

Both use the same definition types as their named entries. They may contain factory/provider/model selectors and trusted connection options, but the shipped base contains no key, URL or model ID. Deliberately putting an API key or endpoint in the base shares it with every inheriting connection, potentially across different factories; prefer named entries when connections have different credentials or endpoints.

For each provider/model, effective resolution merges base → named configuration → stored override into a fresh object. Named configuration is already assembled from module, application and instance layers. This applies to configured entries and database-only entries; saving persists only the supplied override document, not inherited defaults or credentials. Base does not register resources: a name must exist in configuration or the active instance's table. An explicitly declared {} entry can inherit a complete base, but an unknown name still fails.

Set common policy or override a specific connection in application module configuration, for example:

ts
config.modules['cabloy-ai'] = {
  base: {
    aiModels: { generation: { temperature: 0.2 } },
  },
  aiProviders: {
    compressed: {
      factory: 'openai',
      options: {
        apiKey: deploymentCredentials.aiApiKey,
        headers: { 'accept-encoding': 'gzip' },
      },
    },
  },
};

Here other connections inherit identity, while compressed requests gzip. Use the same lowercase header spelling when overriding it. The reference application has no additional default-connection encoding override. Registered factories called directly receive only supplied options; base is applied by Cabloy configuration resolution, not global Fetch or factory decoration.

The identity default requests uncompressed delivery, which may increase bandwidth. It was selected after a real-path comparison, but is not proof of a particular compression defect or a guarantee that every upstream complies or flushes immediately. Reassess policy for each endpoint; see streaming diagnostics for the evidence boundaries. Trusted per-call request headers take precedence for the installed OpenAI SDK. The database header allowlist is unchanged: configure this encoding policy in backend code, not through saveProvider.

Apply code configuration through normal backend reload/restart; no frontend rebuild or database reset is needed. Unset/empty environment defaults omit optional factory, URL, key and model-ID fields so they do not erase base inheritance. An explicitly configured undefined still follows the normal merge semantics; it is not automatically skipped.

OpenAI endpoint compatibility ​

Choose the factory explicitly; changing AI_PROVIDER_DEFAULT_BASEURL or options.baseURL changes the endpoint location, not the protocol:

FactoryProtocolConnection requirements
openaiResponses API (/responses) with the installed @ai-sdk/openai versionEffective apiKey; optional baseURL
openaiCompatibleChat Completions (/chat/completions) through @ai-sdk/openai-compatibleExplicit baseURL; apiKey optional if the endpoint permits unauthenticated access

For a third-party compatible service, configure the default connection with AI_PROVIDER_DEFAULT_FACTORY=openaiCompatible, its API prefix through AI_PROVIDER_DEFAULT_BASEURL, and its model ID through AI_MODEL_DEFAULT_MODELID. Supply AI_PROVIDER_DEFAULT_APIKEY when that service requires authentication. Leave AI_MODEL_DEFAULT_PROVIDER unset to use the default connection.

The same connection can be configured under any alias, for example in application module configuration:

ts
aiProviders: {
  local: {
    factory: 'openaiCompatible',
    options: { baseURL: 'http://127.0.0.1:8000/v1' },
  },
},
aiModels: {
  default: { provider: 'local', modelId: 'your-model-id' },
},

Use the API prefix, such as https://provider.example/v1, not the full /chat/completions URL. The compatible factory requires an explicit URL and does not fall back to OPENAI_BASE_URL or OPENAI_API_KEY. A missing URL fails during invocation creation through the safe factory-error boundary. Never omit a required key for a remote authenticated service.

The compatible adapter fixes the SDK provider name to openaiCompatible, independent of the application's connection alias. Use providerOptions.openaiCompatible for its provider-specific generation options. It forwards provider connection options to the SDK; enable options such as includeUsage: true only when the endpoint supports them. Streaming usage is not requested by default, so token usage can remain unknown. Tools, reasoning and structured outputs depend on the endpoint/model; this factory does not provide Responses-only features or expand the text-chat MVP.

For the openai factory, when options.baseURL is unset, the OpenAI SDK may also use its standard OPENAI_BASE_URL environment variable. Set an explicit effective baseURL when endpoint selection must not depend on that fallback. This is separate from API-key resolution: openai and anthropic require a configured key.

Sparse overrides ​

Effective provider/model entries merge the assembled base.aiProviders / base.aiModels, their named module/application/active-instance configuration and the instance's stored override document, in that order. Scene resolution applies decorator/application onion configuration, active-instance onion configuration, the stored scene override and trusted caller overrides, in that order. Base model settings enter through the selected model, not a second scene-level merge.

  • Plain objects merge recursively into fresh objects.
  • Arrays replace the previous array.
  • Missing properties inherit; false and 0 are explicit values.
  • Only nullable fields accept null. It is not a generic delete operator.
  • To restore inheritance, remove the property from the stored override document.
  • Saving an override replaces that override document; it is not an implicit JSON Patch.
  • Deleting an override for a configured entry reveals the configured entry again. Disable the effective entry explicitly to stop its use.

Changing a scene's selected model first selects that model's defaults. Defaults from the previously selected model do not leak into the new selection. Creating another bound invocation resolves the latest effective configuration; an already-created invocation retains its snapshot.

Database values are data only: no factory functions, executable imports, custom fetch, tools, lifecycle callbacks, bean classes or executor options.

Trusted backend code can save overrides through the owning scope service:

ts
const configuration = this.$scope.cabloyAi.service.configuration;

// Store a direct key override for the configured provider.
await configuration.saveProvider('primary', {
  options: { apiKey: newApiKey },
});
await configuration.saveModel('default', {
  generation: { temperature: 0 },
});
await configuration.saveScene('cabloy-ai:default', {
  generation: { temperature: 0.2 },
  limits: { maxOutputTokens: 512 },
});

// Replace the stored model override with an empty document to inherit code defaults.
await configuration.saveModel('default', {});

These calls operate inside the current instance and validate the effective references. Database-only provider/model additions must supply a complete effective definition. They are not browser management APIs. Run backend orchestration inside an established Vona request/executor context; do not select instance or owner authority from posted data.

Keep SDK option layers separate ​

Connection/factory settings such as apiKey, baseURL and shared headers belong to the provider. Model and Scene generation settings supply defaults such as temperature. Configure the single-step output budget and timeout on the Scene under limits; use request for retry and header defaults. Provider-specific generation settings use the SDK's providerOptions namespaces, not the application's provider alias.

For example, an application alias named primary does not change the SDK namespace used by that provider. Do not assume every provider accepts a second options argument when selecting a model; use the installed provider's actual API.

Credentials ​

Set options.apiKey in backend deployment configuration, or save it directly in the provider's overrides JSON through saveProvider. A database-only provider must resolve to a registered factory and valid connection options, inherited from base or supplied in its document. No separate credential column or resolver is required.

Database keys are stored in plaintext, without encryption. Anyone with access to the provider records, database exports or backups can read them. Restrict that access and protect backups accordingly. Instance scoping controls ordinary application access; it does not encrypt data at rest.

Provider saves replace the entire stored override document. To rotate a key, save the replacement key together with any other database overrides you want to retain. To restore the deployment key, remove options.apiKey from the replacement document; saving {} removes all stored provider overrides and inherits the configured provider. It does not disable that provider. A future management form must preserve an unchanged stored key on the server, not submit a display mask as a new key. This MVP does not implement that form or its endpoints.

Only the exact provider-document path options.apiKey is permitted for persisted API keys. Secret-like fields elsewhere, credential-bearing URLs and non-allowlisted headers remain rejected. Executable connection options such as custom fetch remain code-only.

Configuration services are trusted backend operations: their mutation results, provider-model reads and resolveProvider() results may contain the actual key. Never return these objects directly from a controller or transfer them to a browser. There are no public provider/model/scene management endpoints in this MVP.

Do not include keys in run snapshots, errors, diagnostics, chat API responses, frontend state or SSR transfer. The invocation exposes only safe identity/limit data; its model and options remain private. This delivery does not introduce a secret vault, encryption-key lifecycle or secret-management UI.

Released under the MIT License.