langserve  by langchain-ai

REST API deployment for LangChain runnables and chains

Created 2 years ago
2,159 stars

Top 20.9% 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

1 day ago

Responsiveness

1 day

Pull Requests (30d)
6
Issues (30d)
1
Star History
13 stars in the last 30 days

Explore Similar Projects

Feedback? Help us improve.