Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

langserve

> 后端框架
Open source

LangServe ️

2.3K stars0 likes2 views
WebsiteGitHub

About

LangServe ️

️ 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.

Overview

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.

Features

  • Input and Output schemas automatically inferred from your LangChain object, and enforced on every API call, with rich error messages
  • API docs page with JSONSchema and Swagger (insert example link)
  • Efficient /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
  • new as of 0.0.40, supports /stream_events to make it easier to stream without needing to parse the output of /stream_log.
  • Playground page at /playground/ with streaming output and intermediate steps
  • Built-in (optional) tracing to LangSmith, just add your API key (see Instructions)
  • All built with battle-tested open-source Python libraries like FastAPI, Pydantic, uvloop and asyncio.
  • Use the client SDK to call a LangServe server as if it was a Runnable running locally (or call the HTTP API directly)
  • LangServe Hub

⚠️ LangGraph Compatibility

LangServe 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.

Limitations

  • Client callbacks are not yet supported for events that originate on the server
  • Versions of LangServe <= 0.2.0, will not generate OpenAPI docs properly when using Pydantic V2 as Fast API does not support mixing pydantic v1 and v2 namespaces. See section below for more details. Either upgrade to LangServe>=0.3.0 or downgrade Pydantic to pydantic 1.

Security

  • Vulnerability in Versions 0.0.13 - 0.0.15 -- playground endpoint allows accessing arbitrary files on server. Resolved in 0.0.16.

Installation

For both client and server:

bash
pip install "langserve[all]"

or pip install "langserve[client]" for client code, and pip install "langserve[server]" for server code.

LangChain CLI ️

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.

Setup

Note: We use poetry for dependency management. Please follow poetry doc to learn more about it.

1. Create new app using langchain cli command

bash
langchain app new my-app

2. Define the runnable in add_routes. Go to server.py and edit

bash
add_routes(app. NotImplemented)

3. Use poetry to add 3rd party packages (e.g., langchain-openai, langchain-anthropic, langchain-mistral, etc).

bash
poetry add [package-name] // e.g `poetry add langchain-openai`

4. Set up relevant env variables. For example,

bash
export OPENAI_API_KEY="sk-..."

5. Serve your app

bash
poetry run langchain serve --port=8100

Examples

Get 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

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptdeploymentfastapilangchainlangchain-python

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架