Skip to main content

createLLMNode

workflow.createLLMNode() Creates a one-time LLM invocation node. When the node executes, it will first parse the provider, then call provider.chat(llmInput), and finally convert the LLM output into business payload through mapOutput.

Signature​

workflow.createLLMNode<Input>(
options: LLMNodeOptions<Input, LLMChatOutput>,
): BaseNode<Input, LLMChatOutput>

workflow.createLLMNode<Input, Output>(
options: LLMNodeOptions<Input, Output> & {
mapOutput: LLMOutputMapper<Input, Output>;
},
): BaseNode<Input, Output>

Parameter​

ParameterTypeDescription
optionsLLMNodeOptions<Input, Output>Define provider, input mappings, output mappings, and node meta information.

LLMNodeOptions​

FieldTypeDescription
namestringNode name, default "llm". provider binding to override the provider by that name.
providerLLMProviderSourceprovider instance, provider id, provider ref, or resolver. Required.
mapInput(input, context) => LLMChatInputTranslate the business input into an LLM request. Required.
mapOutput(output, input, context) => OutputConverts the LLM output to business output; returns the original LLMChatOutput when not passed.
historyLimitnumberThe number of nodes retained in the execution history. The default value is 50.
metadataNodeMetadataInputThe node displays meta information.

LLMProviderSource​

FormTypeDescription
provider examplesLLMProviderUse the callable provider directly.
provider idstringLookup from context.providers.llmProviders.
provider refLLMProviderRefDelay parsing by id and configure the fallback.
resolver(context, nodeName) => LLMProvider | undefinedDynamically selects provider by node or context.

LLMChatInput​

FieldTypeDescription
promptstringSingle prompt; and messages two-choice 1.
messagesModelMessage[]Multi-round message; 1 with prompt binary.
systemstringSystem prompt.
temperaturenumberSampling temperature.
maxOutputTokensnumberThe maximum number of output tokens.
topP / topKnumberSampling parameters.
presencePenalty / frequencyPenaltynumberRepeat the penalty parameter.
stopSequencesstring[]Stop the sequence.
seednumberRandom seed.
maxRetriesnumberNumber of retries.
timeoutnumberThe call timed out.
headersobjectExtra request header.
providerOptionsLLMProviderOptionsprovider private extension parameters.
abortSignalAbortSignalNodes are automatically injected from context.abortSignal.

Output​

SituationNode Output TypeDescription
Not passed mapOutputLLMChatOutputReturns the provider chat result as it is.
Imported mapOutputOutputReturns the result of mapOutput(output, input, context).

LLMChatOutput​

FieldTypeDescription
textstringModel text output.
finishReasonFinishReason | undefinedStop the cause.
usageLanguageModelUsage | undefinedtoken usage.
providerMetadataProviderMetadata | undefinedprovider meta information.

When an executor configures tokenUsage: { enabled: true }, the provider resolved by getLLMProvider() reports LLMChatOutput.usage to context.tokenUsage after chat returns, so accounting still works when mapOutput omits usage. The run aggregate appears in report.tokenUsage.run; cumulative totals are written to the current project's KV and, when present, its conversation KV. Server derives the system total by aggregating project totals. Input, output, reasoning, cached-input, and cache-creation token details are supported.

Call process​

PhaseInputResult
Upstream nodeInputBusiness input
mapInputInput, NodeContextLLMChatInput
provider chatLLMChatInputLLMChatOutput
mapOutputLLMChatOutput, Input, NodeContextOutput

Example​

const llmNode = workflow.createLLMNode<ParsedInput, AnswerPayload>({
name: "answer",
provider: workflow.createLLMProviderRef("default"),
mapInput(input) {
return {
system: "You answer briefly.",
prompt: input.message,
temperature: 0.2,
};
},
mapOutput(output) {
return {
errCode: 0,
errMessage: "",
content: output.text,
};
},
});