Back to agents docs
Quickstart · Python

Wire a Python agent into Orrery

Use orrery-client for typed endpoint methods, or raw httpx when you want to handle the x402 challenge yourself. Agents can spend monthly Orrery API credits or settle per request via x402.

Official client package

publish gate
pip install orrery-client

Package scaffold is ready in-repo and documented at /docs/agents/sdk. Public PyPI install becomes live after the explicit package publish step.

Raw httpx example install

pip install httpx anthropic

Minimal agent (~30 lines)

briefing.py
import httpx
import os
from anthropic import Anthropic

ORRERY = "https://orrery.me/api/x402/v1"
ORRERY_API_KEY = os.getenv("ORRERY_API_KEY")
PAYMENT = os.getenv("ORRERY_X_PAYMENT")  # produced by your x402 payer
client = Anthropic()  # reads ANTHROPIC_API_KEY

def paid_get(path: str):
    headers = {}
    if ORRERY_API_KEY:
        headers["X-Orrery-API-Key"] = ORRERY_API_KEY
    elif PAYMENT:
        headers["X-PAYMENT"] = PAYMENT
    r = httpx.get(f"{ORRERY}{path}", headers=headers, timeout=10)
    if r.status_code == 402:
        raise RuntimeError("x402 payment required: settle the challenge and replay with X-PAYMENT")
    r.raise_for_status()
    return r.json()["data"]

# 1. Today's brief — biggest moves, signals, resolution watch.
brief = paid_get("/brief/today")

# 2. For the top mover, ask Orrery for the interpreted "why".
top = brief["biggest_moves"][0]
why = paid_get(f"/markets/{top['slug']}/why")

# 3. Verify resolution-risk before treating any move as news.
risk = paid_get(f"/markets/{top['slug']}/resolution-risk")

# Hand the structured brief to Claude. The prompt is grounded;
# Orrery already separated facts from interpretation.
msg = client.messages.create(
    model="claude-opus-4-7",
    max_tokens=600,
    thinking={"type": "adaptive"},
    system=(
        "You summarise prediction-market intelligence for a daily "
        "briefing. Stay grounded in the supplied JSON; never predict "
        "outcomes; flag resolution risk when present."
    ),
    messages=[{
        "role": "user",
        "content": (
            f"Today's brief headline: {brief['headline']}\n\n"
            f"Top mover: {top}\n\n"
            f"Why it moved (Orrery factors): {why['factors']}\n\n"
            f"Resolution-risk verdict: {risk}\n\n"
            "Write a 4-sentence briefing for a busy reader."
        ),
    }],
)
print(msg.content[0].text)

Adding the X-PAYMENT header

Every paid endpoint returns HTTP 402 with a JSON challenge until the agent settles on Base via the x402 protocol and replays the same request with X-PAYMENT attached:

def fetch_with_payment(url: str, payer) -> dict:
    """Fetch url; if 402, settle on Base and replay."""
    r = httpx.get(url, timeout=10)
    if r.status_code != 402:
        return r.json()
    challenge = r.json()["accepts"][0]
    proof = payer.settle(
        amount=challenge["amount"],
        asset=challenge["asset"],     # USDC
        network=challenge["network"], # base
    )
    r2 = httpx.get(url, headers={"X-PAYMENT": proof}, timeout=10)
    r2.raise_for_status()
    return r2.json()

The Coinbase x402 docs detail the wallet payer interface. Orrery doesn't mandate a specific wallet — any x402-compliant payer works.

Next steps

  • • Use /api/x402/v1/health (free) to discover endpoints + check upstream Polymarket health before paying.
  • • Schedule the briefing as a cron / Lambda; the brief endpoint caches for 5 minutes so an hourly schedule pays roughly $0.024/day at current catalog prices.
  • • Subscribe to /signals/{kind} (e.g. resolution_risk) to monitor a single signal class.
  • SDK packages · TypeScript quickstart · Raw HTTP / cURL
Orrery for AI agents — Python quickstart | Orrery