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 langserveVerified import paths — ran on the pinned version, not inferred.
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.
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.
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`.
Install them manually using `pip install fastapi uvicorn`.
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.
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.