Skip to main content

alphai-sdk

Typed Python client for the AlphaAI financial-news REST API — relevance-scored, ticker-linked news and SEC Form 4 insider data, built for AI agents and trading bots.

  • Sync and async clients (Client / AsyncClient) over httpx
  • Pydantic v2 response models — autocomplete, validation, Decimal money
  • Cursor auto-pagination, automatic retry on 429/5xx, rate-limit inspection
  • Typed errors and full coverage of the 9 public endpoints

API reference: https://api.alphai.io/api/schema/ · Developer guide: https://alphai.io/developers

Install

pip install alphai-sdk

Requires Python 3.10+. The import name is alphai.

Authentication

Create an API key at https://alphai.io/account/api-keys, then pass it explicitly or via the ALPHAI_API_KEY environment variable.

from alphai import Client

# reads $ALPHAI_API_KEY when api_key is omitted
with Client(api_key="ak_live_…") as client:
    page = client.news.list(symbol="NVDA")
    for article in page.results:
        print(article.title, "→", article.relevance_score)

Rate limits are per account and two-layer — a per-minute burst plus a per-day volume cap: Free 20/min · 100/day · Basic 60/min · 10,000/day · Pro 150/min · 100,000/day. News-archive depth is tiered too: Free keys page the feeds back 30 days, Basic 90, Pro the full archive (paging past your horizon returns a 403 with an upgrade hint).

Quickstart

List & filter the feed

from alphai import Client, NewsCategory

with Client() as client:
    page = client.news.list(
        symbol="NVDA",
        category=[NewsCategory.EARNINGS, "insider"],  # enum or str; OR-matched
        min_relevance=7,
        collapse_stories=True,  # dedupe syndicated reprints
        page_size=50,  # 10 default; 50 needs a Pro key
    )
    print(page.next_cursor)  # opaque cursor for the next (older) page
    print(page.has_more)

Poll for what is new (sort="ingested")

Articles reach the feed after their publish time, so a poller that tracks time_published silently skips late arrivals. sort="ingested" orders the feed by arrival instead, and its cursor is a polling position rather than an end-of-feed marker:

cursor = load_cursor()  # None on the first run

with Client() as client:
    page = client.news.list(sort="ingested", cursor=cursor, symbol="NVDA")
    for article in page.results:
        handle(article)  # article.original.created_at = when we received it
    save_cursor(page.next_cursor)  # always set; empty results = caught up

Pass the same sort on every call of a run. Each mode mints its own cursor family, so replaying an ingested cursor into the default mode is a 400, not a silent restart. Cursors are opaque: hand one back unchanged, never build one.

On Free and Basic the archive horizon applies to where a poll resumes, so a cursor left unused for longer than your window comes back 403 (extra.reason = "archive_horizon"). Poll on your plan's cadence and you will not see it; Pro has no window.

Auto-paginate

iter() follows the cursor for you and flattens articles across pages:

with Client() as client:
    for article in client.news.iter(category="earnings", max_items=100):
        print(article.uid, article.title)

Single article, trending, related, insider

with Client() as client:
    client.news.trending()  # top ≤10 from the last 48h
    art = client.news.get("788e477c66f3849b")
    client.news.related(art.uid)  # up to 6 related articles
    client.news.insider(symbol="NVDA")  # SEC Form 4 feed (or .insider_iter())

Symbols & rollups

from decimal import Decimal

with Client() as client:
    client.symbols.list(limit=100)  # active tickers (bare list)
    nvda = client.symbols.get("NVDA")  # detail (404 if unknown)
    btc = client.symbols.get("BTC-USD")  # crypto + foreign listings too
    # Multi-market: .asset_type ("Stock"/"ETF"/"Crypto"), .country, .currency,
    # .supports_insider (US SEC names only). Crypto is "<SYM>-USD"; foreign uses
    # the Yahoo suffix (e.g. "VOD.L").
    sent = client.symbols.sentiment_summary("NVDA")  # 7-day AI sentiment
    ins = client.symbols.insider_summary("NVDA")  # 30-day Form 4 rollup
    assert isinstance(ins.buy_value_usd, Decimal | None)  # money is Decimal

Async

Every method mirrors the sync client with await; iter() is an async generator:

import asyncio
from alphai import AsyncClient


async def main() -> None:
    async with AsyncClient() as client:
        async for article in client.news.iter(symbol="NVDA", max_items=20):
            print(article.title)


asyncio.run(main())

Example projects

  • alphai-news-to-email — a small, deployable app that emails you a deduplicated digest of high-relevance news for your watchlist. Built entirely on this SDK.

Errors

All errors derive from AlphaAIError:

from alphai import Client, RateLimitError, NotFoundError, AuthenticationError

with Client() as client:
    try:
        client.symbols.get("ZZZZ")
    except NotFoundError:
        ...
    except RateLimitError as e:
        print("retry after", e.retry_after, "seconds; limit", e.limit)
    except AuthenticationError:
        ...
Status Exception
400 BadRequestError (.fields for validation errors)
401 AuthenticationError
403 PermissionDeniedError
404 NotFoundError
429 RateLimitError (.retry_after, .limit, .remaining, .reset)
5xx ServerError
network/timeout APIConnectionError
2xx, unparseable body InvalidResponseError

GET requests are automatically retried on 429 / 5xx / connection errors (max_retries, default 2) with jittered backoff that honors Retry-After (capped at max_retry_after, default 60s, so a bad value can't freeze your process). A 2xx with a non-JSON / empty body raises InvalidResponseError.

Rate-limit budget

Every keyed response carries the X-RateLimit-* trio. The last one seen is on the client:

with Client() as client:
    client.news.list()
    rl = client.last_rate_limit
    if rl:
        print(f"{rl.remaining}/{rl.limit} left, resets at {rl.reset}")

Configuration

Client(
    api_key=None,  # else $ALPHAI_API_KEY
    base_url="https://api.alphai.io",  # API host
    timeout=30.0,
    max_retries=2,  # clamped to >= 0
    backoff_factor=0.5,
    max_retry_after=60.0,  # cap on honored Retry-After (seconds)
    user_agent="alphai-sdk-python/<version>",
    http_client=None,  # bring your own httpx.Client (advanced)
)

The same keyword arguments apply to AsyncClient. When you pass a custom http_client, the SDK still applies its Authorization header and base URL on every request — your client just supplies the transport (proxies, custom timeout, mounts). You own its lifecycle (the SDK won't close a client you passed in).

Development

uv venv && uv pip install -e ".[dev]"
ruff check . && ruff format --check .
mypy src/alphai
pytest                       # offline suite
pytest -m integration        # live tests (needs ALPHAI_API_KEY)

License

MIT — see LICENSE. API access still requires a valid key.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alphai_sdk-0.4.0.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alphai_sdk-0.4.0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file alphai_sdk-0.4.0.tar.gz.

File metadata

  • Download URL: alphai_sdk-0.4.0.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for alphai_sdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 0761c542c25b26418c9aef91993cbd837fc450a627d744884cc98aca09b3363a
MD5 fe682bea1d77f93c429adde7cca9da3f
BLAKE2b-256 8f1ef47d7508e13326438b709efd95d2aa1d9e95e4692ff0beb0f62021ace228

See more details on using hashes here.

Provenance

The following attestation bundles were made for alphai_sdk-0.4.0.tar.gz:

Publisher: release.yml on makeev/alphai-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file alphai_sdk-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: alphai_sdk-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for alphai_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5db65742ca6febf1a76be541bb9b3832e4d547ebe1204af86a96dda8bc24ec52
MD5 121b47bf5ff6b1fd23e1eb8aeb30e141
BLAKE2b-256 589c1126e4d02f785365833a18ddff2f1dc671c15cbd0982e77f41e993edb267

See more details on using hashes here.

Provenance

The following attestation bundles were made for alphai_sdk-0.4.0-py3-none-any.whl:

Publisher: release.yml on makeev/alphai-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.6.0

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page