Skip to content

AiModule

Provides access to the WebbiOS AI Kernel API.

This module is the primary interface for all AI operations within WebbiOS. It supports provider management (CRUD), model configuration, chat completions, text embeddings, and health checks.

// Provider management
const providers = await sdk.ai.getProviders();
await sdk.ai.addProvider({
provider: 'gemini',
displayName: 'Google Gemini',
credentials: { apiKey: 'AIza...' }
});
// Chat with AI
const response = await sdk.ai.chat('model-config-id', [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is WebbiOS?' }
]);
console.log(response.content);

new AiModule(client): AiModule

ApiClient

AiModule

addModel(input): Promise<AiModelConfig>

Add a new model configuration to a provider.

CreateModelConfigInput

Model type, ID, display name, and generation settings.

Promise<AiModelConfig>

The created model configuration.


addProvider(input): Promise<AiProvider>

Add a new AI provider with credentials. Credentials are encrypted server-side before storage.

CreateProviderInput

Provider type, display name, and credentials.

Promise<AiProvider>

The created provider record.


chat(modelConfigId, messages, options?): Promise<ChatResponse>

Send a chat request to the AI Kernel. Uses the specified model configuration to route to the appropriate provider.

string

The model config ULID to use for generation.

ChatMessage[]

Chat conversation history.

ChatRequestOptions

Optional generation parameters (temperature, maxTokens).

Promise<ChatResponse>

The AI-generated response with token usage and latency metrics.

const response = await sdk.ai.chat('01H...', [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Explain quantum computing.' }
], { temperature: 0.5 });
console.log(response.content);
console.log(`Tokens: ${response.tokensUsed.input + response.tokensUsed.output}`);

deleteModel(id): Promise<void>

Delete a model configuration.

string

The model config ULID to delete.

Promise<void>


deleteProvider(id): Promise<void>

Delete an AI provider and all its associated model configurations. This action is irreversible.

string

The provider ULID to delete.

Promise<void>


embed(texts): Promise<EmbeddingResponse>

Generate text embeddings using the tenant’s default embedding model. Embeddings are per-tenant (single model) to ensure vector consistency.

string[]

Array of text strings to embed (max 100 per request).

Promise<EmbeddingResponse>

Embedding vectors, model info, and dimensions.

const result = await sdk.ai.embed(['Hello world', 'How are you?']);
console.log(`Dimensions: ${result.dimensions}`);
console.log(`Vectors: ${result.embeddings.length}`);

getCatalog(): Promise<ModelCatalog>

Retrieve the full catalog of available AI models across all providers. This is informational only and does not require any provider credentials.

Promise<ModelCatalog>

The complete model catalog grouped by provider.


getModels(type?): Promise<AiModelConfig[]>

List all model configurations, optionally filtered by type.

"chat" | "embedding"

Optional filter: ‘chat’ for LLMs, ‘embedding’ for vector models.

Promise<AiModelConfig[]>

A list of model configurations.


getProviders(): Promise<AiProvider[]>

Retrieve all configured AI providers for this tenant.

Promise<AiProvider[]>

A list of AI providers (credentials are NOT included for security).


setDefaultModel(id, modelType): Promise<AiModelConfig>

Set a model as the tenant-wide default for its type. Only one default is allowed per type (chat or embedding).

string

The model config ULID to set as default.

"chat" | "embedding"

Which type to set as default (‘chat’ or ‘embedding’).

Promise<AiModelConfig>

The updated model configuration.

await sdk.ai.setDefaultModel('01H...', 'embedding');

testProvider(id): Promise<HealthCheckResult>

Test connectivity to an AI provider. Sends a small test request to verify credentials are valid.

string

The provider ULID to test.

Promise<HealthCheckResult>

Health check result with latency and any error details.


updateModel(id, input): Promise<AiModelConfig>

Update an existing model configuration.

string

The model config ULID.

UpdateModelConfigInput

Fields to update (display name, max tokens, temperature).

Promise<AiModelConfig>

The updated model configuration.


updateProvider(id, input): Promise<AiProvider>

Update an existing AI provider.

string

The provider ULID.

UpdateProviderInput

Fields to update (display name, credentials, active status).

Promise<AiProvider>

The updated provider record.