Skip to content
15 min read · 3,001 words

Interface: WebLLMChatCompletionsAdapterOptions

Defined in: src/batteries/llm/webllm_chat_completions/types.ts:75

Configuration options for the in-browser WebLLM Chat Completions adapter — the OpenAI options minus the network-transport fields (no HTTP is involved), plus WebLLM-specific engine controls.

Extends

Properties

PropertyTypeDefault valueDescriptionInherited fromDefined in
audio?{ format: "wav" | "mp3" | "flac" | "opus" | "pcm16"; voice: string; }undefinedParameters for audio output if requested.OpenAIChatCompletionsAdapterOptions.audiosrc/batteries/llm/openai_chat_completions/types.ts:611
audio.format"wav" | "mp3" | "flac" | "opus" | "pcm16"undefined--src/batteries/llm/openai_chat_completions/types.ts:611
audio.voicestringundefined--src/batteries/llm/openai_chat_completions/types.ts:611
autoAck?booleanfalseWhether the executor should call ctx.ack() itself when a generation completes with no tool calls (a terminal text answer). Remarks ack() is terminal and one-shot: once called, the dispatch loop exits after the current iteration. When the executor acks automatically, it seizes turn-completion control from the implementor — a dispatchOutputPipeline quality gate can never run, because the signal is already set before the output pipeline executes. This option therefore defaults to false (opt-in). With autoAck: false, a tool-call-free response leaves the context unsignalled and the executor returns; the implementor's output pipeline (or a later iteration) is responsible for calling ctx.ack() / ctx.nack(). This is the seam that makes output-side quality gates (citation enforcement, schema validation, regenerate-on-reject) possible. Set autoAck: true to restore single-shot behavior: the executor acks the moment a tool-call-free answer finishes, terminating the turn without giving the output pipeline a vote. The tool-call path is unaffected by this flag — it always withholds ack so the runner can iterate and execute the calls. Error paths always nack regardless of this flag.OpenAIChatCompletionsAdapterOptions.autoAcksrc/batteries/llm/openai_chat_completions/types.ts:605
bucketOrder?ChatCompletionsBucketOrderundefinedDetermines order of memory and retrievable buckets in history assembly.OpenAIChatCompletionsAdapterOptions.bucketOrdersrc/batteries/llm/openai_chat_completions/types.ts:502
chatOptions?ChatOptions | ChatOptions[]undefinedMLC chat option(s) applied to the loaded model.-src/batteries/llm/webllm_chat_completions/types.ts:93
contextWindow?numberundefinedSize of the model's token context window.OpenAIChatCompletionsAdapterOptions.contextWindowsrc/batteries/llm/openai_chat_completions/types.ts:504
createEngine?(input: { chatOptions?: ChatOptions | ChatOptions[]; engineConfig?: MLCEngineConfig; model: string; onInitProgress?: (report: InitProgressReport) => void; }) => Promise<MLCEngineInterface>undefinedCustom engine factory; overrides the default WebLLM engine loader.-src/batteries/llm/webllm_chat_completions/types.ts:95
enableThinking?booleanundefinedWhether to enable the model's "thinking"/reasoning mode, threaded EXPLICITLY into the request as extra_body.enable_thinking. Defaults to false — many reasoning chat templates (Qwen3, DeepSeek-R1) default thinking ON, which silently burns the token budget inside <think>. Pinned off unless you opt in. (Independent of reasoningFieldPrecedence/parsing, which only handle thinking that IS emitted.)-src/batteries/llm/webllm_chat_completions/types.ts:112
engine?MLCEngineInterfaceundefinedA pre-constructed engine to drive; mutually exclusive with WebLLMChatCompletionsAdapterOptions.createEngine.-src/batteries/llm/webllm_chat_completions/types.ts:89
engineConfig?MLCEngineConfigundefinedMLC engine configuration used when the adapter creates the engine itself.-src/batteries/llm/webllm_chat_completions/types.ts:91
extra_body?Record<string, unknown>undefinedAdditional WebLLM/MLC request fields passed through verbatim.-src/batteries/llm/webllm_chat_completions/types.ts:87
forgeToolsFilter?(forged: ToolRegistry, ctx: DispatchContext) => ToolRegistryundefinedOPTIONAL hook to SHAPE the artifact-query tools forged from prior-turn SpooledArtifact results, before they merge into the visible tool set. Receives the merged forged registry + dispatch context; returns a (possibly narrowed) registry, applied BEFORE the merge with ctx.tools. Lets the assembler keep only the core readers on a tight window (the rest reachable via tool_catalog/call_a_tool). Default absent = identity (all forged tools) = backward-compatible. The battery stays budget-agnostic (per the CONTRIBUTING size-threshold rule) — it applies the supplied filter without measuring context; budget logic lives in the caller's filter.OpenAIChatCompletionsAdapterOptions.forgeToolsFiltersrc/batteries/llm/openai_chat_completions/types.ts:758
frequency_penalty?numberundefinedFrequency penalty wire field to discourage repeating words.OpenAIChatCompletionsAdapterOptions.frequency_penaltysrc/batteries/llm/openai_chat_completions/types.ts:613
function_call?| "auto" | "none" | { name: string; }undefinedDeprecated wire field to control which function is called.OpenAIChatCompletionsAdapterOptions.function_callsrc/batteries/llm/openai_chat_completions/types.ts:615
functions?{ description?: string; name: string; parameters?: JsonSchema; }[]undefinedDeprecated list of functions available to the model.OpenAIChatCompletionsAdapterOptions.functionssrc/batteries/llm/openai_chat_completions/types.ts:617
helpers?Partial<ChatCompletionsHelpers>undefinedOptional overrides for OpenAI chat completions helpers.OpenAIChatCompletionsAdapterOptions.helperssrc/batteries/llm/openai_chat_completions/types.ts:533
ignore_eos?booleanundefinedWhen true, the model ignores end-of-sequence tokens and keeps generating.-src/batteries/llm/webllm_chat_completions/types.ts:85
isWebGPUAvailable?() => booleanundefinedOverride for the WebGPU-availability probe (defaults to a real navigator.gpu check).-src/batteries/llm/webllm_chat_completions/types.ts:104
localToolCallParser?| ToolCallParserName | ToolCallParserFnundefinedOPTIONAL fallback parser for tool calls the provider did NOT return structurally. Remarks The Chat Completions message.tool_calls array is authoritative: when the provider returns tool calls, those are used and this option is never consulted. But some models — especially small local ones served through an OpenAI-compatible endpoint — emit a tool call in a surface form the endpoint does not lift into tool_calls: <call:name{…}, a fenced ```json ```` block, <tool_code…>, or bare name\nkey: value. Those land as plain assistant contentwithtool_callsempty, silently dropping the call. This is a cross-model, cross-weight reality, not a single-endpoint quirk. Set this to a parser family name (e.g.'gemma'), 'auto'(try every bundled parser in priority order), or a custom ToolCallParserFn to recover such calls fromcontentONLY when the provider returned none. Recovered calls execute exactly like native ones. Default absent = disabled = today's native-only behaviour (fully backward-compatible). Mirrors the on-device batteries'toolCallParser, which parse from text unconditionally because those runtimes never return structured calls.OpenAIChatCompletionsAdapterOptions.localToolCallParsersrc/batteries/llm/openai_chat_completions/types.ts:748
logit_bias?Record<string, number>undefinedBias logits to control token generation likelihood.OpenAIChatCompletionsAdapterOptions.logit_biassrc/batteries/llm/openai_chat_completions/types.ts:619
logprobs?booleanundefinedRequest log probabilities for generated tokens.OpenAIChatCompletionsAdapterOptions.logprobssrc/batteries/llm/openai_chat_completions/types.ts:621
max_completion_tokens?numberundefinedHard limit on token count for model reasoning/completion.OpenAIChatCompletionsAdapterOptions.max_completion_tokenssrc/batteries/llm/openai_chat_completions/types.ts:623
max_tokens?numberundefinedMaximum number of generated tokens.OpenAIChatCompletionsAdapterOptions.max_tokenssrc/batteries/llm/openai_chat_completions/types.ts:625
metadata?Record<string, string>undefinedMetadata key-value pairs forwarded to the provider.OpenAIChatCompletionsAdapterOptions.metadatasrc/batteries/llm/openai_chat_completions/types.ts:627
modalities?("text" | "audio")[]undefinedDesired modalities for model output, such as text and audio.OpenAIChatCompletionsAdapterOptions.modalitiessrc/batteries/llm/openai_chat_completions/types.ts:629
modelstringundefinedName of the model to use for completion.OpenAIChatCompletionsAdapterOptions.modelsrc/batteries/llm/openai_chat_completions/types.ts:609
n?numberundefinedNumber of completions to generate for each request.OpenAIChatCompletionsAdapterOptions.nsrc/batteries/llm/openai_chat_completions/types.ts:631
onCompiling?BatteryLifecycleCallbackundefinedEngine/graph/shader compilation after download, before the first token. A COARSE marker: the on-device runtimes (LiteRT Engine.create, transformers.js from_pretrained) expose the boundary — download done, opaque WebGPU/WASM graph build about to run — but NOT a progress stream, so progress is usually absent. Often the slowest part of a cold start; without this it was invisible.BatteryLifecycleHooks.onCompilingsrc/batteries/llm/chat_common/lifecycle.ts:89
onComplete?BatteryLifecycleCallbackundefinedAfter the turn's output is parsed + persisted, before ack (fires per turn).BatteryLifecycleHooks.onCompletesrc/batteries/llm/chat_common/lifecycle.ts:95
onError?BatteryLifecycleCallbackundefinedA load or generation failure (paired with nack).BatteryLifecycleHooks.onErrorsrc/batteries/llm/chat_common/lifecycle.ts:97
onGenerating?BatteryLifecycleCallbackundefinedImmediately before the provider generate call (fires per turn).BatteryLifecycleHooks.onGeneratingsrc/batteries/llm/chat_common/lifecycle.ts:93
onInitProgress?(report: InitProgressReport) => voidundefinedCallback invoked with model-load progress reports.-src/batteries/llm/webllm_chat_completions/types.ts:102
onLifecycle?BatteryLifecycleCallbackundefinedFires on EVERY phase transition (the firehose).BatteryLifecycleHooks.onLifecyclesrc/batteries/llm/chat_common/lifecycle.ts:80
onLoading?BatteryLifecycleCallbackundefinedWeights/runtime loading — may fire repeatedly with progress as the provider reports it.BatteryLifecycleHooks.onLoadingsrc/batteries/llm/chat_common/lifecycle.ts:82
onPromptAssembled?PromptAssembledObserverFnundefinedObserve the fully-assembled request this battery is about to POST TO the provider — fired once per terminal generation, the instant the body is built and BEFORE the fetch, with the wire messages, tools, and the complete requestBody. The mirror of onRawGeneration. Purely observational (return value ignored, errors swallowed). Default absent. An ADK-control key — stripped from the wire request body, never sent to the provider. The request is handed back AS-IS — no redaction — so treat it as potentially sensitive (it may contain auth material that rode the body) if you persist it. See PromptAssembledObserverFn.OpenAIChatCompletionsAdapterOptions.onPromptAssembledsrc/batteries/llm/openai_chat_completions/types.ts:729
onRawGeneration?RawGenerationObserverFnundefinedObserve the model's RAW response for each completed generation — fired once per terminal generation, after the provider's reply is parsed but before the result is persisted, with the returned assistant content (rawText), the residual cleanedText, and the extracted reasoning / toolCalls. Purely observational (return value ignored, errors swallowed). Default absent. An ADK-control key — stripped from the wire request body, never sent to the provider. See RawGenerationObserverFn.OpenAIChatCompletionsAdapterOptions.onRawGenerationsrc/batteries/llm/openai_chat_completions/types.ts:719
onReady?BatteryLifecycleCallbackundefinedEngine/pipeline resolved and cached, before the first generation.BatteryLifecycleHooks.onReadysrc/batteries/llm/chat_common/lifecycle.ts:91
parallel_tool_calls?booleanundefinedAllow the model to emit multiple tool calls in one turn.OpenAIChatCompletionsAdapterOptions.parallel_tool_callssrc/batteries/llm/openai_chat_completions/types.ts:633
prediction?{ content: | string | { text: string; type: "text"; }[]; type: "content"; }undefinedPrediction helper to accelerate latency of known content.OpenAIChatCompletionsAdapterOptions.predictionsrc/batteries/llm/openai_chat_completions/types.ts:635
prediction.content| string | { text: string; type: "text"; }[]undefined--src/batteries/llm/openai_chat_completions/types.ts:637
prediction.type"content"undefined--src/batteries/llm/openai_chat_completions/types.ts:636
presence_penalty?numberundefinedPresence penalty wire field to encourage new topics.OpenAIChatCompletionsAdapterOptions.presence_penaltysrc/batteries/llm/openai_chat_completions/types.ts:640
prompt_cache_key?stringundefinedVendor cache key for caching system prompts.OpenAIChatCompletionsAdapterOptions.prompt_cache_keysrc/batteries/llm/openai_chat_completions/types.ts:642
prompt_cache_retention?"in_memory" | "24h"undefinedCache retention strategy for cached system prompts.OpenAIChatCompletionsAdapterOptions.prompt_cache_retentionsrc/batteries/llm/openai_chat_completions/types.ts:644
reasoning_effort?"none" | "low" | "high" | "minimal" | "medium"undefinedTarget reasoning depth/effort for reasoning models.OpenAIChatCompletionsAdapterOptions.reasoning_effortsrc/batteries/llm/openai_chat_completions/types.ts:646
reasoningFieldPrecedence?ReasoningFieldPrecedence['reasoning', 'reasoning_content']Ordered precedence of the wire fields the adapter reads for model reasoning/thinking output. Remarks Reasoning is not part of OpenAI's official Chat Completions spec, so OpenAI-compatible providers disagree on the field name: Ollama's /v1 and current vLLM emit reasoning, while legacy vLLM (≤0.8) and the DeepSeek API emit reasoning_content. The adapter reads every field in this list that is present on the response. Precedence governs two things. When more than one listed field is present with identical content (or only one is present), the adapter emits a single thought attributed to the highest-precedence field. When listed fields are present with divergent content, each surfaces as its own thought (ordered by precedence) rather than silently dropping one — a thought stream is the wrong place to lose data.OpenAIChatCompletionsAdapterOptions.reasoningFieldPrecedencesrc/batteries/llm/openai_chat_completions/types.ts:531
repetition_penalty?numberundefinedPenalty applied to repeated tokens (WebLLM/MLC sampling parameter).-src/batteries/llm/webllm_chat_completions/types.ts:83
replayCompatibility?readonly string[]undefinedList of replay labels supported by the assistant.OpenAIChatCompletionsAdapterOptions.replayCompatibilitysrc/batteries/llm/openai_chat_completions/types.ts:512
response_format?| { type: "text"; } | { type: "json_object"; } | { json_schema: { description?: string; name: string; schema: JsonSchema; strict?: boolean; }; type: "json_schema"; }undefinedEnforces a specific output format, e.g. JSON schema.OpenAIChatCompletionsAdapterOptions.response_formatsrc/batteries/llm/openai_chat_completions/types.ts:648
safety_identifier?stringundefinedUnique safety system identifier or configuration ID.OpenAIChatCompletionsAdapterOptions.safety_identifiersrc/batteries/llm/openai_chat_completions/types.ts:661
seed?numberundefinedDeterministic random seed for generation.OpenAIChatCompletionsAdapterOptions.seedsrc/batteries/llm/openai_chat_completions/types.ts:663
selfIdentity?stringundefinedUnique identity label for the assistant instance.OpenAIChatCompletionsAdapterOptions.selfIdentitysrc/batteries/llm/openai_chat_completions/types.ts:506
service_tier?"default" | "auto" | "flex" | "priority" | "scale"undefinedService reliability tier for processing the request.OpenAIChatCompletionsAdapterOptions.service_tiersrc/batteries/llm/openai_chat_completions/types.ts:665
spoolStore?SpoolStorea new InMemorySpoolStore per dispatchBacking store for string / Uint8Array tool returns. Tool output bytes are written under the tool call's id; the resulting @nhtio/adk!SpooledArtifact (or the tool's configured subclass) is the model-visible handle for the rest of the turn. Remarks Defaults to a fresh, ephemeral per-dispatch @nhtio/adk/batteries/storage/in_memory!InMemorySpoolStore. Inject an @nhtio/adk/batteries/storage/opfs!OpfsSpoolStore or a Flydrive-backed store to persist artifacts to durable storage (and to stream large/binary tool output to disk rather than buffering it in memory). Lifetime / namespacing: the default store is per-dispatch, so tool-call ids only need to be unique within a dispatch. An injected durable store persists across turns and dispatches, so the tool-call ids used as keys must be globally unique for that store (or the store must apply its own keyPrefix); the adapter does not namespace keys for you, and it does not delete entries — lifetime and cleanup of an injected store are the consumer's responsibility.OpenAIChatCompletionsAdapterOptions.spoolStoresrc/batteries/llm/openai_chat_completions/types.ts:554
stop?string | string[]undefinedCustom stop sequence strings.OpenAIChatCompletionsAdapterOptions.stopsrc/batteries/llm/openai_chat_completions/types.ts:667
store?booleanundefinedRequest the provider to store the completed trace.OpenAIChatCompletionsAdapterOptions.storesrc/batteries/llm/openai_chat_completions/types.ts:669
stream?booleanundefinedWhether to stream the completion response chunk by chunk.OpenAIChatCompletionsAdapterOptions.streamsrc/batteries/llm/openai_chat_completions/types.ts:492
stream_options?{ include_obfuscation?: boolean; include_usage?: boolean; }undefinedConfiguration options for response streaming.OpenAIChatCompletionsAdapterOptions.stream_optionssrc/batteries/llm/openai_chat_completions/types.ts:671
stream_options.include_obfuscation?booleanundefined--src/batteries/llm/openai_chat_completions/types.ts:671
stream_options.include_usage?booleanundefined--src/batteries/llm/openai_chat_completions/types.ts:671
streamIdleTimeoutMs?numberundefinedIdle timeout in milliseconds for the stream before aborting.OpenAIChatCompletionsAdapterOptions.streamIdleTimeoutMssrc/batteries/llm/openai_chat_completions/types.ts:494
strictToolChoice?booleanfalseWhen tool_choice (or the allowed_tools variant) forces the model onto a specific tool name, and that name resolves to an ephemeral, forged artifact-query tool (one produced by <Subclass>.forgeTools(ctx) — i.e. tool.ephemeral === true), this flag controls how the adapter reacts: - false (default): emit a single helpers.log.warn({ kind: 'tool-choice-forged-artifact', ... }) record and continue. Forging an artifact-query tool by name is almost always a misconfiguration — the tool may not exist in the next iteration once the artifact ages out — but the call still goes through. - true: hard-fail with E_INVALID_OPENAI_CHAT_COMPLETIONS_OPTIONS. Use this in production deployments where forcing a forged tool indicates a real bug.OpenAIChatCompletionsAdapterOptions.strictToolChoicesrc/batteries/llm/openai_chat_completions/types.ts:570
temperature?numberundefinedSampling temperature control.OpenAIChatCompletionsAdapterOptions.temperaturesrc/batteries/llm/openai_chat_completions/types.ts:673
thoughtSurfacing?"all-self" | "latest-self" | "all"undefinedDetermines which thoughts are surfaced back to the model.OpenAIChatCompletionsAdapterOptions.thoughtSurfacingsrc/batteries/llm/openai_chat_completions/types.ts:508
tokenEncoding?| "gpt2" | "r50k_base" | "p50k_base" | "p50k_edit" | "cl100k_base" | "o200k_base" | "gemini" | "gemma" | "llama2" | "claude" | nullundefinedTokenizer encoding configuration for token counting.OpenAIChatCompletionsAdapterOptions.tokenEncodingsrc/batteries/llm/openai_chat_completions/types.ts:510
tool_choice?| "required" | "auto" | "none" | { function: { name: string; }; type: "function"; } | { custom: { name: string; }; type: "custom"; } | { allowed_tools: { mode: "required" | "auto"; tools: ( | { function: { name: string; }; type: "function"; } | { custom: { name: string; }; type: "custom"; })[]; }; type: "allowed_tools"; }undefinedEnforce or disable tool execution selection.OpenAIChatCompletionsAdapterOptions.tool_choicesrc/batteries/llm/openai_chat_completions/types.ts:675
top_logprobs?numberundefinedTop log probability tokens limit.OpenAIChatCompletionsAdapterOptions.top_logprobssrc/batteries/llm/openai_chat_completions/types.ts:692
top_p?numberundefinedNucleus sampling probability threshold.OpenAIChatCompletionsAdapterOptions.top_psrc/batteries/llm/openai_chat_completions/types.ts:694
unsupportedMediaPolicy?UnsupportedMediaPolicy'throw'Policy for how the adapter handles a @nhtio/adk!Media instance whose modality the OpenAI Chat Completions wire format does not natively support (today: video). See UnsupportedMediaPolicy.OpenAIChatCompletionsAdapterOptions.unsupportedMediaPolicysrc/batteries/llm/openai_chat_completions/types.ts:579
user?stringundefinedEnd-user identifier for abuse monitoring.OpenAIChatCompletionsAdapterOptions.usersrc/batteries/llm/openai_chat_completions/types.ts:696
verbosity?"low" | "high" | "medium"undefinedDiagnostics verbosity level.OpenAIChatCompletionsAdapterOptions.verbositysrc/batteries/llm/openai_chat_completions/types.ts:698
web_search_options?{ search_context_size?: "low" | "high" | "medium"; user_location?: { approximate: { city?: string; country?: string; region?: string; timezone?: string; }; type: "approximate"; }; }undefinedConfiguration for built-in web search.OpenAIChatCompletionsAdapterOptions.web_search_optionssrc/batteries/llm/openai_chat_completions/types.ts:700
web_search_options.search_context_size?"low" | "high" | "medium"undefined--src/batteries/llm/openai_chat_completions/types.ts:701
web_search_options.user_location?{ approximate: { city?: string; country?: string; region?: string; timezone?: string; }; type: "approximate"; }undefined--src/batteries/llm/openai_chat_completions/types.ts:702
web_search_options.user_location.approximate{ city?: string; country?: string; region?: string; timezone?: string; }undefined--src/batteries/llm/openai_chat_completions/types.ts:704
web_search_options.user_location.approximate.city?stringundefined--src/batteries/llm/openai_chat_completions/types.ts:705
web_search_options.user_location.approximate.country?stringundefined--src/batteries/llm/openai_chat_completions/types.ts:706
web_search_options.user_location.approximate.region?stringundefined--src/batteries/llm/openai_chat_completions/types.ts:707
web_search_options.user_location.approximate.timezone?stringundefined--src/batteries/llm/openai_chat_completions/types.ts:708
web_search_options.user_location.type"approximate"undefined--src/batteries/llm/openai_chat_completions/types.ts:703