Skip to content

About

Async FastAPI backend for agents: live cited web search, page extraction as Markdown and ready datasets from 73 official sources, with typed routes, a shared httpx client and offline mock tests.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

FastAPI backend for agents: live web search, page extraction and ready datasets

An async FastAPI template that gives your agents, apps and tools three things from SpecStream, the live web data engine: cited answers from the web as it is today, the main text of any page as Markdown, and rows from 326,355 ready lists (194.4M rows from 73 official sources, on December 2, 2026), each row with its source. The SpecStream key stays on the server, one httpx.AsyncClient is shared for the app's life, and every route has typed input and output.

SpecStream is first on WideSearch and 99 on SimpleQA Verified (benchmarks). Its fast tier answers at a 937 ms median over 6,548 live calls in the 7 days to December 1, 2026.

Run

Python 3.10 or later.

git clone https://github.com/specstream/fastapi-specstream-agent-backend
cd fastapi-specstream-agent-backend
python -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt
export SPECSTREAM_API_KEY=your_key            # see .env.example
export BACKEND_TOKEN=a_long_random_token      # your own callers send it as a Bearer token
uvicorn app.main:app --reload                 # docs at http://127.0.0.1:8000/docs
curl -s localhost:8000/v1/web-search -H "Authorization: Bearer $BACKEND_TOKEN" \
  -H "Content-Type: application/json" -d '{"q": "When do the EU AI Act rules for general purpose models apply?"}'
{"answer": "...", "answer_page": "https://...", "sources": [{"url": "...", "title": "...", "site": "...", "snippet": "...", "published": "...", "cited": true}], "request_id": "...", "price_usd": 0.001, "took_ms": 912}

Routes

Route What it does SpecStream price
POST /v1/web-search {"q", "fast": true, "num", "news"} The answer with its page when the pages print one, and the ranked sources $1 per 1,000 fast, $5 per 1,000 default
POST /v1/extract {"urls": [...], "query"} The main text of 1 to 20 pages or PDFs as Markdown; query keeps only the passages that answer it $0.80 per 1,000 pages
GET /v1/datasets/search?q=&family= Ready lists whose title matches, with rows and price free
GET /v1/datasets/describe?page=/data/grants A list's title, rows, columns, period and price free
GET /v1/datasets/sample?page=/data/grants The 10 newest rows, each with its source free
GET /v1/datasets/rows?page=&max_cents=&since=&new_only= Rows of a dated list, never more than max_cents; 0, the default, only prices them 5¢ a row the first time, free after
GET /healthz Liveness, open without the token

SpecStream's own status and code come through: 402 when the balance is low, 429 with the seconds to wait. A dataset page must be a /data/... path, so the backend never forwards a caller to another SpecStream route.

Code

from app.specstream import SpecStream

specstream = SpecStream()                              # reads SPECSTREAM_API_KEY
data = await specstream.web_search("Which EU startups raised a Series B in November 2026?")
pages = await specstream.extract(["https://example.com/annual-report.pdf"], query="revenue")
rows = await specstream.rows("/data/osha-violations", max_cents=500, new_only=True)

Use it from a LangGraph or Pydantic AI tool, a Celery task, or another route. SpecStream(transport=...) takes any httpx transport, which is how the tests run offline.

Test

pip install -r requirements-dev.txt
pytest -q                     # against httpx.MockTransport: no key, nothing spent
python check_live.py          # the free dataset routes live through the app; the paid routes answer 402 with no key
Open federal grant opportunities: 1,097 rows, 26 columns, updated 2026-12-01
  sample: 10 free rows, first: OJP FY 2026 Invited to Apply Kayla Hamilton Grant Program
     714  /data/grants/department/department-of-health-and-human-services
     675  /data/grants/category/health
     503  /data/grants/department/department-of-health-and-human-services/national-institutes-of-health
/v1/web-search  answers 402 without a key: set SPECSTREAM_API_KEY to search and read pages
/v1/extract     answers 402 without a key: set SPECSTREAM_API_KEY to search and read pages

Tested on Python 3.10 and 3.14. The tests cover null titles, snippets and texts, an empty search, a page that is gone, non http addresses, a dataset path outside /data/, pricing before spending, 402 and 429 replies, a missing server key and the backend token.

Prices

Price
Free credit on sign up $2, which is 2,000 fast searches, no card
Monthly Pro Pass $49 a month: 5,000 ready list rows a month and $49 of API credit

Links

License

MIT

About

Async FastAPI backend for agents: live cited web search, page extraction as Markdown and ready datasets from 73 official sources, with typed routes, a shared httpx client and offline mock tests.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages