Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

FastAPI + LangChain Streaming Example

This is a very small LangChain v1 example that streams Anthropic Claude Haiku 4.5 output through FastAPI.

Files

.
├── client.py
├── main.py
└── src
    ├── server.py
    └── settings.py

What It Does

  • src/settings.py reads ANTHROPIC_API_KEY with Pydantic settings.
  • src/server.py exposes POST /chat/stream.
  • The endpoint builds a LangChain v1 agent with create_agent(...).
  • It streams agent output with astream(..., stream_mode="messages", version="v2").
  • Each streamed text chunk is forwarded with FastAPI StreamingResponse.
  • client.py is an optional local client if you want something simpler than curl.

Install

uv sync

Configure

Set your Anthropic key before starting the app:

export ANTHROPIC_API_KEY="your-api-key"

Optional: override the FastAPI port.

export PORT=8001

Optional: override the default model alias.

export ANTHROPIC_MODEL="claude-haiku-4-5"

Run The Server

uv run main.py

Open the docs at http://127.0.0.1:${PORT:-8000}/docs.

Stream With client.py

uv run client.py "Explain streaming in 3 short sentences."

If you omit the prompt, client.py uses a default one:

uv run client.py

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages