From 3cc6209859376a923d9d0c2d9b1b4b72ac0704b0 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Tue, 28 Apr 2026 15:40:32 +0200 Subject: [PATCH] chore: [JS] document lc orchestration fallback Co-authored-by: Copilot --- docs-js/langchain/orchestration.mdx | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/docs-js/langchain/orchestration.mdx b/docs-js/langchain/orchestration.mdx index 8a048ea04..d2ed704f7 100644 --- a/docs-js/langchain/orchestration.mdx +++ b/docs-js/langchain/orchestration.mdx @@ -68,6 +68,60 @@ const response = await client.invoke(history, { }); ``` +### Module Fallback + +The [`OrchestrationClient`](pathname:///api/v2/classes/langchain_src.OrchestrationClient.html) supports module fallback, which allows you to provide multiple orchestration configurations that are tried in sequence until one succeeds. +Pass a non-empty array of [`LangChainOrchestrationModuleConfig`](pathname:///api/v2/types/langchain_src.LangChainOrchestrationModuleConfig.html) objects when initializing the client, using the [`LangChainOrchestrationModuleConfigList`](pathname:///api/v2/types/langchain_src.LangChainOrchestrationModuleConfigList.html) type. + +For a full explanation of when fallback is triggered and how it works with the orchestration service, refer to [Module Fallback](../orchestration/chat-completion#module-fallback) in the orchestration documentation. + +```ts +import { OrchestrationClient } from '@sap-ai-sdk/langchain'; +import type { LangChainOrchestrationModuleConfigList } from '@sap-ai-sdk/langchain'; + +const orchestrationConfigs: LangChainOrchestrationModuleConfigList = [ + { + // Primary configuration — fails if the model is unavailable + promptTemplating: { + model: { + name: 'gpt-5', + timeout: 10 // seconds; triggers fallback on timeout (non-streaming only) + } + } + }, + { + // Fallback configuration + promptTemplating: { + model: { + name: 'anthropic--claude-4.5-haiku' + } + } + } +]; + +const response = await new OrchestrationClient(orchestrationConfigs).invoke([ + { role: 'user', content: 'Tell me about SAP Cloud SDK.' } +]); +``` + +Module fallback also works with the `stream()` method. +Note that in streaming scenarios, only model unavailability triggers fallback. +Unlike non-streaming requests, timeouts will not trigger fallback during streaming. + +```ts +import type { AIMessageChunk } from '@langchain/core/messages'; + +const client = new OrchestrationClient(orchestrationConfigs); +const stream = await client.stream([ + { role: 'user', content: 'Tell me about SAP Cloud SDK.' } +]); + +let finalOutput: AIMessageChunk | undefined; +for await (const chunk of stream) { + finalOutput = finalOutput ? finalOutput.concat(chunk) : chunk; +} +``` + ### Streaming The client supports streaming responses for chat completion requests.