Back to agents docs
Quickstart · Python

Wire a Python agent into Orrery

Three calls and you have a daily prediction-market briefing. Uses httpx for the HTTP layer + the official Anthropic SDK to feed the brief into Claude. No API keys to Orrery; agents pay USDC per request via x402 (preview mode is free).

Install

pip install httpx anthropic

Minimal agent (~30 lines)

briefing.py
import httpx
from anthropic import Anthropic

ORRERY = "https://orrery.me/api/x402/v1"
client = Anthropic()  # reads ANTHROPIC_API_KEY

# 1. Today's brief — biggest moves, signals, resolution watch.
brief = httpx.get(f"{ORRERY}/brief/today", timeout=10).json()["data"]

# 2. For the top mover, ask Orrery for the interpreted "why".
top = brief["biggest_moves"][0]
why = httpx.get(f"{ORRERY}/markets/{top['slug']}/why", timeout=10).json()["data"]

# 3. Verify resolution-risk before treating any move as news.
risk = httpx.get(
    f"{ORRERY}/markets/{top['slug']}/resolution-risk", timeout=10
).json()["data"]

# 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

During v1 preview the calls above succeed without payment. When Orrery flips enforcement on, every paid endpoint returns HTTP 402 with a JSON challenge. The agent should settle on Base via the x402 protocol and replay 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 ~$0.024/day at preview prices.
  • • Subscribe to /signals/{kind} (e.g. resolution_risk) to monitor a single signal class.
  • TypeScript quickstart · Raw HTTP / cURL
Orrery for AI agents — Python quickstart | Orrery