Registry / llm-agents / langserve

langserve

JSON →
library0.3.3pypypiunverified

LangServe is a Python library that simplifies the deployment of LangChain runnables and agents as REST APIs. It builds on FastAPI to provide a robust server with a built-in playground UI for testing. The library is under active development, with version 0.3.3 being the latest, and maintains rapid compatibility updates with its core dependencies like `langchain-core`.

pip install langserve
INSTALL
IMPORT
SIG · LANGSERVE
L
langserve
llm-agentspythonv0.3.3
Install
8.5s avg
Import
2984ms
Disk
84MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 3.078s · 98.5MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 8.5s · import 2.891s · 78MB
84MB installed
● package 84MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

add_routes
from langserve import add_routes
from langserve import add_routes

This quickstart sets up a basic LangServe API server with two endpoints: one for a raw OpenAI Chat model and another for a simple 'joke' chain (prompt + OpenAI Chat model). It uses FastAPI and uvicorn. Ensure `OPENAI_API_KEY` is set in your environment or replace the dummy key. You'll need `fastapi`, `uvicorn`, and `langchain-openai` installed.

import os from fastapi import FastAPI from langchain_core.prompts import ChatPromptTemplate from langchain_openai import ChatOpenAI from langserve import add_routes import uvicorn # Set your OpenAI API key from environment variable for local testing. # In a production environment, use proper secrets management. openai_api_key = os.environ.get('OPENAI_API_KEY', 'sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') app = FastAPI( title="LangChain Server", version="1.0", description="A simple API server using LangChain's Runnable interfaces", ) # A simple runnable (e.g., just an LLM) add_routes( app, ChatOpenAI(api_key=openai_api_key), path="/openai", ) # A more complex runnable (e.g., prompt + LLM) prompt = ChatPromptTemplate.from_template("Tell me a joke about {topic}") model = ChatOpenAI(api_key=openai_api_key) chain = prompt | model add_routes( app, chain, path="/joke", ) if __name__ == "__main__": # To run this, save it as a Python file (e.g., server.py) and execute: # uvicorn server:app --reload uvicorn.run(app, host="0.0.0.0", port=8000)
langserve --version
Debug
Known issues
breakingLangServe v0.3.0 and later upgraded to Pydantic V2. This can cause `TypeError`, `AttributeError`, or `ValidationError` issues if other installed packages (or your own code) are still using Pydantic V1, or if you try to use V1 syntax.
fix
Ensure all dependencies requiring Pydantic are compatible with V2. Upgrade your `pydantic` package to `pydantic>=2` and verify other `langchain` ecosystem packages are also updated to their latest versions. Use Pydantic's migration guide if updating your own models.
affects: >=0.3.0
breakingLangServe v0.3.3 is explicitly compatible with `langchain-core` V1. Older `langserve` versions might not work correctly, leading to `AttributeError` or unexpected behavior when interacting with modern LangChain components.
fix
Upgrade both `langserve` and `langchain-core` to their latest compatible versions (`pip install --upgrade langserve langchain-core`). For `langserve==0.3.3`, ensure `langchain-core>=1.0.0`.
affects: <0.3.3
gotchaWhile LangServe integrates with FastAPI, `fastapi` and `uvicorn` are not strict dependencies of the `langserve` package itself. Running a LangServe API server requires these to be installed separately.
fix
Install them manually using `pip install fastapi uvicorn`.
affects: All versions
deprecatedPrior to v0.2.0, some internal module structures or import paths might have differed due to rapid LangChain ecosystem evolution. Directly importing internal components from older LangChain or LangServe versions might lead to `ModuleNotFoundError` or `ImportError` after upgrading.
fix
Always use documented public APIs, typically imported from `langserve`, `langchain_core`, or `langchain_openai`. Consult migration guides for major version bumps in the LangChain ecosystem.
affects: <0.2.0
gotchaLangServe (especially in versions <= 0.2) might not fully support OpenAPI docs generation when Pydantic V2 is used, though API endpoints and the playground typically function as expected.
fix
Upgrade to LangServe >=0.3.0 for better Pydantic V2 support, or downgrade Pydantic to V1 (`pip install pydantic==1.*`) if OpenAPI docs are critical for older LangServe versions.
affects: <0.3.0
Upgrade
Version history
0.3.3latest on PyPI · released Oct 17, 2025
Audit
Dependencies
langchain-corerequiredEssential for defining and composing runnables. LangServe 0.3.3 requires langchain-core >=1.0.0.
pydanticrequiredUsed for data validation and schema generation. LangServe 0.3.0+ requires pydantic >=2.0.0.
fastapioptionalRequired to run the API server. LangServe integrates with FastAPI to expose runnables as endpoints.
uvicornoptionalASGI server required to run the FastAPI application.
langchain-openairequiredCommonly used LLM provider for examples and applications; often installed alongside LangServe.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources
langserve — pip install langserve · libregistry