langserve  by langchain-ai

REST API deployment for LangChain runnables and chains

created 1 year ago
2,137 stars

Top 21.5% on sourcepulse

GitHubView on GitHub
Project Summary

LangServe provides a framework for deploying LangChain runnables and chains as REST APIs, targeting developers building LLM applications. It simplifies the process of exposing complex LLM logic as scalable web services, offering features like automatic schema generation, interactive playgrounds, and built-in tracing.

How It Works

LangServe leverages FastAPI and Pydantic to create robust APIs. It automatically infers input and output schemas from LangChain objects, enforcing data validation and providing clear error messages. The library exposes standard endpoints (/invoke, /batch, /stream, /stream_log) for interacting with deployed runnables, along with a /playground for interactive testing and debugging. It's built on efficient asynchronous Python libraries like uvloop and asyncio.

Quick Start & Requirements

  • Install with pip install "langserve[all]".
  • Requires Python 3.7+.
  • LangChain CLI (pip install -U langchain-cli) is recommended for project bootstrapping.
  • Environment variables (e.g., API keys for LLM providers) are often necessary.
  • Official documentation and examples are available.

Highlighted Details

  • Automatic generation of OpenAPI docs (Swagger/JSONSchema) for API endpoints.
  • Interactive playground with streaming output and intermediate step visualization.
  • Optional integration with LangSmith for tracing and monitoring LLM application runs.
  • Support for custom authentication mechanisms via FastAPI dependencies or middleware.
  • Ability to define custom widgets for the playground, including file uploads and chat interfaces.

Maintenance & Community

LangChain AI maintains the project. The README notes a recommendation to use LangGraph Platform for new projects and that LangServe will only accept bug fixes, not new features.

Licensing & Compatibility

LangServe is typically distributed under a permissive license (e.g., MIT), allowing for commercial use and integration with closed-source applications.

Limitations & Caveats

The project strongly recommends migrating to LangGraph Platform for new projects. Older versions (<= 0.2.0) have compatibility issues with Pydantic v2 regarding OpenAPI documentation generation. Client callbacks for server-originated events are not yet supported. File uploads via multipart/form-data are not yet supported; base64 encoding is the current workaround.

Health Check
Last commit

3 weeks ago

Responsiveness

1 day

Pull Requests (30d)
4
Issues (30d)
1
Star History
76 stars in the last 90 days

Explore Similar Projects

Starred by Nat Friedman Nat Friedman(Former CEO of GitHub), Chip Huyen Chip Huyen(Author of AI Engineering, Designing Machine Learning Systems), and
7 more.

langflow by langflow-ai

2.9%
93k
Visual tool for AI agent and workflow creation/deployment
created 2 years ago
updated 1 day ago
Starred by Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), Carol Willing Carol Willing(Core Contributor to CPython, Jupyter), and
38 more.

langchain by langchain-ai

0.4%
113k
Framework for building LLM-powered applications
created 2 years ago
updated 1 day ago
Feedback? Help us improve.