← All @molecule/* packages · App templates
@molecule/api-ai-localProvider bond · ai · API (Node) · v1.0.2 · Apache-2.0
Local ai-local provider for molecule.dev.
npm install @molecule/api-ai-localnpm · Source on GitHub · Implements @molecule/api-ai
@molecule/api-ai-local is a provider bond on the API (Node) side: it implements the ai core interface (@molecule/api-ai) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
Works with: @molecule/api-bond, @molecule/api-i18n, @molecule/api-secrets
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Local (OpenAI-compatible) ai-local provider for molecule.dev.
Streams chat completions from any local inference server that speaks the
OpenAI chat/completions protocol (Ollama, LM Studio, llama.cpp, vLLM),
keyless by default.
provider
npm install @molecule/api-ai-local @molecule/api-ai @molecule/api-bond @molecule/api-i18n @molecule/api-secrets
LocalConfigLocal (OpenAI-compatible) provider configuration.
interface LocalConfig {
/** Called on each rate-limited/busy upstream response, before any retry sleep. */
onRateLimit?: AiRateLimitCallback
/**
* Base URL of the OpenAI-compatible endpoint, INCLUDING the version segment
* (e.g. `http://localhost:11434/v1`). Overrides `LOCAL_AI_BASE_URL` /
* `OLLAMA_BASE_URL`. Defaults to Ollama's `http://localhost:11434/v1`.
*/
baseUrl?: string
/**
* Optional API key. Most local servers ignore auth; when omitted (and no
* `LOCAL_AI_API_KEY` env var is set) no `Authorization` header is sent.
*/
apiKey?: string
/**
* Default model when a call doesn't specify one. Overrides `LOCAL_AI_MODEL`.
* Defaults to `llama3.1`.
*/
model?: string
}
LocalAIProviderLocal (OpenAI-compatible) chat provider implementing the AIProvider
interface. Mirrors @molecule/api-ai-openai so the same handler code can
dispatch to a local endpoint.
createProvider(config)Create a local (OpenAI-compatible) AI provider instance.
Constructs WITHOUT requiring any secret — local endpoints run keyless.
function createProvider(config?: LocalConfig): AIProvider
config — Local provider configuration.Returns: An AIProvider backed by an OpenAI-compatible local endpoint.
aiLocalSecretDefinitionsOptional secret/config overrides recognised by the local AI bond.
const aiLocalSecretDefinitions: SecretDefinition[]
providerThe provider implementation. Constructs keyless — no secret required.
const provider: AIProvider
Implements @molecule/api-ai interface.
Setup function to register this provider with the bond system:
import { bond } from '@molecule/api-bond'
import { provider } from '@molecule/api-ai-local'
export function setupAiLocal(): void {
bond('ai', 'local', provider)
}
Peer dependencies:
@molecule/api-ai ^1.0.1@molecule/api-bond ^1.0.1@molecule/api-i18n ^1.0.1@molecule/api-secrets ^1.0.1@molecule/api-ai@molecule/api-bond@molecule/api-i18n@molecule/api-secretsError message disambiguation: a plain 400 that ISN'T a context-length error (bad param, malformed tool schema) gets its own non-retryable message distinct from the generic "AI service error. Please try again." used for retryable failures.
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual chat/AI screens, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip. The sandbox HAS an AI provider bonded, so the flow runs live end-to-end; AI output is NON-DETERMINISTIC, so assert on STRUCTURE/behavior, not exact text:
chat() yields text chunks then a final done; a single late
blob means the reply was awaited whole and streaming is broken.)messages history is sent, not just the last
line.