LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corerunnablesbaseRunnableSerializableconfigurable_alternatives
    Method●Since v0.1

    configurable_alternatives

    Configure alternatives for Runnable objects that can be set at runtime.

    Copy
    configurable_alternatives(
      self,
      which: ConfigurableField,
      *,
      default_key: str = 'default',
      prefix_keys: bool = False,
      **kwargs: Runnable[Input, Output] | Callable[[], Runnable[Input, Output]] = {}
    ) -> RunnableSerializable[Input, Output]
    from langchain_anthropic import ChatAnthropic
    from langchain_core.runnables.utils import ConfigurableField
    from langchain_openai import ChatOpenAI
    
    model = ChatAnthropic(
        model_name="claude-sonnet-4-5-20250929"
    ).configurable_alternatives(
        ConfigurableField(id="llm"),
        default_key="anthropic",
        openai=ChatOpenAI(),
    )
    
    # uses the default model ChatAnthropic
    print(model.invoke("which organization created you?").content)
    
    # uses ChatOpenAI
    print(
        model.with_config(configurable={"llm": "openai"})
        .invoke("which organization created you?")
        .content
    )

    Parameters

    NameTypeDescription
    which*ConfigurableField

    The ConfigurableField instance that will be used to select the alternative.

    default_keystr
    Default:'default'

    The default key to use if no alternative is selected.

    prefix_keysbool
    Default:False

    Whether to prefix the keys with the ConfigurableField id.

    **kwargsRunnable[Input, Output] | Callable[[], Runnable[Input, Output]]
    Default:{}

    A dictionary of keys to Runnable instances or callables that return Runnable instances.

    View source on GitHub