Skip to main content

createLLMProviderRef

workflow.createLLMProviderRef() Creates a provider reference object. When the LLM node is executed, the actual provider is resolved by the getLLMProvider node name, provider id, binding table, and fallback.

Signature

workflow.createLLMProviderRef(
id: string,
fallback?: LLMProviderSource,
): LLMProviderRef

Parameter

ParameterTypeDescription
idstringprovider id, used to find provider from context.providers.llmProviders.
fallbackLLMProviderSourceOptional fallback; continue parsing when id is not found.

Return value

FieldTypeDescription
kind"llm-provider-ref"Identifies that this is a provider ref.
idstringProvider ID.
fallbackLLMProviderSource | undefinedFallback provider source.

Provider Parse Order

OrderSourceDescription
1context.providers.llmProviderBindings[nodeName]Node-level binding takes precedence.
2source itselfIf source is a provider, string, ref, or resolver, it is parsed first.
3defaultLLMProviderBinding / defaultLLMProviderIdUse the default binding or default provider id.
4context.providers.llmThe default provider of compatible orders.
5ref fallbackThe last attempt to fallback when ref cannot find id.

Analysis process

PhaseInputResult
Workflow definitionid, fallbackLLMProviderRef
LLM node executionLLMProviderRef, NodeContext, nodeNameLLMProvider
Provider callLLMProvider, LLMChatInputLLM output

Example

const defaultProvider = workflow.createLLMProviderRef("default", () => {
return workflow.createLLMProviderFromEnv();
});

const llmNode = workflow.createLLMNode({
provider: defaultProvider,
mapInput(input) {
return { prompt: input.message };
},
});

Common Scenarios

SceneMethod
Local Default providercreateLLMProviderRef("default", () => workflow.createLLMProviderFromEnv())
server per-node binding modelUse the node name to configure in llmProviderBindings.
Multi-provider switchingPass a different provider id, or use resolver.