Skip to main content

[ ![🦜️🔗 Langchain](/img/brand/wordmark.png) ![🦜️🔗
Langchain](/img/brand/wordmark-dark.png) ](/) [ Docs
](/docs/get_started/introduction) [ Use cases ](/docs/use_cases) [
Integrations ](/docs/integrations/platforms/) [ Guides
](/docs/guides/debugging) [ API  ](https://api.python.langchain.com)

More

  * [ People ](/docs/people/)
  * [ Versioning ](/docs/packages)
  * [ Changelog ](/docs/changelog)
  * [ Contributing ](/docs/contributing)
  * [ Templates ](/docs/templates/)
  * [ Cookbooks  ](https://github.com/langchain-ai/langchain/blob/master/cookbook/README.md)
  * [ Tutorials ](/docs/additional_resources/tutorials)
  * [ YouTube ](/docs/additional_resources/youtube)

🦜️🔗

  * [ LangSmith  ](https://smith.langchain.com)
  * [ LangSmith Docs  ](https://docs.smith.langchain.com/)
  * [ LangServe GitHub  ](https://github.com/langchain-ai/langserve)
  * [ Templates GitHub  ](https://github.com/langchain-ai/langchain/tree/master/templates)
  * [ Templates Hub  ](https://templates.langchain.com)
  * [ LangChain Hub  ](https://smith.langchain.com/hub)
  * [ JS/TS Docs  ](https://js.langchain.com)

[ 💬  ](https://chat.langchain.com) [ ](https://github.com/langchain-
ai/langchain)

Search

  * [ Get started ](/docs/get_started)

    * [ Introduction ](/docs/get_started/introduction)
    * [ Installation ](/docs/get_started/installation)
    * [ Quickstart ](/docs/get_started/quickstart)
    * [ Security ](/docs/security)
  * [ LangChain Expression Language ](/docs/expression_language/)

    * [ Get started ](/docs/expression_language/get_started)
    * [ Why use LCEL ](/docs/expression_language/why)
    * [ Interface ](/docs/expression_language/interface)
    * [ Streaming ](/docs/expression_language/streaming)
    * [ How to ](/docs/expression_language/how_to/)

    * [ Cookbook ](/docs/expression_language/cookbook/)

    * [ LangChain Expression Language (LCEL) ](/docs/expression_language/)
  * [ Modules ](/docs/modules/)

    * [ Model I/O ](/docs/modules/model_io/)

    * [ Retrieval ](/docs/modules/data_connection/)

    * [ Agents ](/docs/modules/agents/)

    * [ Chains ](/docs/modules/chains)
    * [ More ](/docs/modules/memory/)

  * [ LangServe ](/docs/langserve)
  * [ LangSmith ](/docs/langsmith/)

  * [ LangGraph ](/docs/langgraph)

  * [ ](/)
  * [ LangChain Expression Language  ](/docs/expression_language/)
  * Interface 

On this page

#  Interface

To make it as easy as possible to create custom chains, we’ve implemented a [
“Runnable”
](https://api.python.langchain.com/en/stable/runnables/langchain_core.runnables.base.Runnable.html#langchain_core.runnables.base.Runnable)
protocol. The ` Runnable ` protocol is implemented for most components. This
is a standard interface, which makes it easy to define custom chains as well
as invoke them in a standard way. The standard interface includes:

  * ` stream ` : stream back chunks of the response 
  * ` invoke ` : call the chain on an input 
  * ` batch ` : call the chain on a list of inputs 

These also have corresponding async methods:

  * ` astream ` : stream back chunks of the response async 
  * ` ainvoke ` : call the chain on an input async 
  * ` abatch ` : call the chain on a list of inputs async 
  * ` astream_log ` : stream back intermediate steps as they happen, in addition to the final response 
  * ` astream_events ` : **beta** stream events as they happen in the chain (introduced in ` langchain-core ` 0.1.14) 

The **input type** and **output type** varies by component:

Component  |  Input Type  |  Output Type   
---|---|---  
Prompt  |  Dictionary  |  PromptValue   
ChatModel  |  Single string, list of chat messages or a PromptValue  |  ChatMessage   
LLM  |  Single string, list of chat messages or a PromptValue  |  String   
OutputParser  |  The output of an LLM or ChatModel  |  Depends on the parser   
Retriever  |  Single string  |  List of Documents   
Tool  |  Single string or dictionary, depending on the tool  |  Depends on the