Cloudflare Docs
Edit this page on GitHub
Set theme to dark (⇧+D)


LangChain is the most popular framework for building AI applications powered by large language models (LLMs).

LangChain publishes multiple Python packages. The following are provided by the Workers runtime:

​​ Get Started

Clone the cloudflare/python-workers-examples repository and run the LangChain example:

git clone
cd 04-langchain
npx wrangler@latest dev

​​ Example code
from js import Response
from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAI
async def on_fetch(request, env):
prompt = PromptTemplate.from_template("Complete the following sentence: I am a {profession} and ")
llm = OpenAI(api_key=env.API_KEY)
chain = prompt | llm
res = await chain.ainvoke({"profession": "electrician"})