LangServe ️
[!WARNING] DEPRECATED This project has been deprecated since Nov 18, 2024 (https://github.com/langchain-ai/langserve/issues/791).
We recommend using LangGraph Platform rather than LangServe for new projects.
Please see the LangGraph Platform Migration Guide for more information.
We will continue to accept bug fixes for LangServe from the community; however, we will not be accepting new feature contributions.
LangServe helps developers
deploy LangChain runnables and chains
as a REST API.
This library is integrated with FastAPI and uses pydantic for data validation.
In addition, it provides a client that can be used to call into runnables deployed on a server. A JavaScript client is available in LangChain.js.
/invoke, /batch and /stream endpoints with support for many
concurrent requests on a single server/stream_log endpoint for streaming all (or some) intermediate steps from your
chain/agent/stream_events to make it easier to stream without needing to parse the output of /stream_log./playground/ with streaming output and intermediate stepsLangServe is designed to primarily deploy simple Runnables and work with well-known primitives in langchain-core.
If you need a deployment option for LangGraph, you should instead be looking at LangGraph Cloud (beta) which will be better suited for deploying LangGraph applications.
For both client and server:
pip install "langserve[all]"or pip install "langserve[client]" for client code,
and pip install "langserve[server]" for server code.
Use the LangChain CLI to bootstrap a LangServe project quickly.
To use the langchain CLI make sure that you have a recent version of langchain-cli
installed. You can install it with pip install -U langchain-cli.
Note: We use poetry for dependency management. Please follow poetry doc to learn more about it.
langchain app new my-appadd_routes(app. NotImplemented)poetry to add 3rd party packages (e.g., langchain-openai, langchain-anthropic, langchain-mistral, etc).poetry add [package-name] // e.g `poetry add langchain-openai`export OPENAI_API_KEY="sk-..."poetry run langchain serve --port=8100Get your LangServe instances started quickly with the examples directory.
| Description | Links |
|---|---|
| LLMs Minimal example that reserves OpenAI and Anthropic chat models. Uses async, supports batching and streaming. | server, client |
| Retriever Simple server that exposes a retriever as a runnable. | server, client |
| Conversational Retriever A Conversational Retriever exposed via LangServe | server, client |
| Agent without conversation history based on OpenAI tools | server, client |
| Agent with conversation history based on OpenAI tools | server, client |
RunnableWithMessageHistory to implement chat persisted on backend, keyed off a session_id supplied by client. |
server, client |
RunnableWithMessageHistory to implement chat persisted on backend, keyed off a conversation_id supplied by client, and user_id (see Auth for implementing user_id properly). |
server, client |
| Configurable Runnable to create a retriever that supports run time configuration of the index name. | server, client |
| Configurable Runnable that shows configurable fields and configurable alternatives. | server, client |
APIHandler Shows how to use APIHandler instead of add_routes. This provides more flexibility for developers to define endpoints. Works well with all FastAPI patterns, but takes a bit more effort. |
server |
| LCEL Example Example that uses LCEL to manipulate a dictionary input. | server, client |
Auth with add_routes: Simple authentication that can be applied across all endpoints associated with app. (Not useful on its own for implementing per user logic.) |
server |
Auth with add_routes: Simple authentication mechanism based on path dependencies. (No useful on its own for implementing per user logic.) |
server |
Auth with add_routes: Implement per user logic and auth for endpoints that use per request config modifier. (Note: At the moment, does not integrate wi |
No open issues yet, or sync has not completed.