raise ValueError(  
                f"Received invalid model '{model}'."  
                " Expected one of chat_openai, openai, anthropic"  
            )  
      
    def batch_configurable_chain(  
        topics: List[str],   
        *,   
        model: str = "chat_openai"  
    ) -> List[str]:  
        ...  
      
    async def abatch_configurable_chain(  
        topics: List[str],   
        *,   
        model: str = "chat_openai"  
    ) -> List[str]:  
        ...  
      
    def invoke_chain_with_fallback(topic: str) -> str:  
        try:  
            return invoke_chain(topic)  
        except Exception:  
            return invoke_anthropic_chain(topic)  
      
    async def ainvoke_chain_with_fallback(topic: str) -> str:  
        try:  
            return await ainvoke_chain(topic)  
        except Exception:  
            return await ainvoke_anthropic_chain(topic)  
      
    async def batch_chain_with_fallback(topics: List[str]) -> str:  
        try:  
            return batch_chain(topics)  
        except Exception:  
            return batch_anthropic_chain(topics)  
    

####  LCEL  ​

    
    
    import os  
      
    from langchain_anthropic import ChatAnthropic  
    from langchain_openai import ChatOpenAI  
    from langchain_openai import OpenAI  
    from langchain_core.output_parsers import StrOutputParser  
    from langchain_core.prompts import ChatPromptTemplate  
    from langchain_core.runnables import RunnablePassthrough, ConfigurableField  
      
    os.environ["LANGCHAIN_API_KEY"] = "..."  
    os.environ["LANGCHAIN_TRACING_V2"] = "true"  
      
    prompt = ChatPromptTemplate.from_template(  
        "Tell me a short joke about {topic}"  
    )  
    chat_openai = ChatOpenAI(model="gpt-3.5-turbo")  
    openai = OpenAI(model="gpt-3.5-turbo-instruct")  
    anthropic = ChatAnthropic(model="claude-2")  
    model = (  
        chat_openai  
        .with_fallbacks([anthropic])  
        .configurable_alternatives(  
            ConfigurableField(id="model"),  
            default_key="chat_openai",  
            openai=openai,  
            anthropic=anthropic,  
        )  
    )  
      
    chain = (  
        {"topic": RunnablePassthrough()}   
        | prompt   
        | model   
        | StrOutputParser()  
    )  
    

##  Next steps  ​

To continue learning about LCEL, we recommend: - Reading up on the full LCEL [
Interface ](/docs/expression_language/interface) , which we’ve only partially
covered here. - Exploring the [ How-to ](/docs/expression_language/how_to)
section to learn about additional composition primitives that LCEL provides. -
Looking through the [ Cookbook ](/docs/expression_language/cookbook) section
to see LCEL in action for common use cases. A good next use case to look at
would be [ Retrieval-augmented generation
](/docs/expression_language/cookbook/retrieval) .

* * *

####  Help us out by providing feedback on this documentation page:

[ Previous  Get started  ](/docs/expression_language/get_started) [ Next
Interface  ](/docs/expression_language/interface)

  * Invoke 
  * Stream 
  * Batch 
  * Async 
  * Async Batch 
  * LLM instead of chat model 
  * Different model provider 
  * Runtime configurability 
  * Logging 
  * Fallbacks 
  * Full code comparison 
  * Next steps 

Community

  * [ Discord  ](https://discord.gg/cU2adEyC7w)
  * [ Twitter  ](https://twitter.com/LangChainAI)

GitHub

  * [ Python  ](https://github.com/langchain-ai/langchain)
  * [ JS/TS  ](https://github.com/langchain-ai/langchainjs)

More

  * [ Homepage  ](https://langchain.com)
  * [ Blog  ](https://blog.langchain.dev)
  * [ YouTube  ](https://www.youtube.com/@LangChain)

Copyright © 2024 LangChain, Inc.