Early Production: This site is in early production. Things may take a while to load. Report issues

Code Examples

Ready-to-use code snippets for common tasks

Python

Get Predictions

Python
import requests

API_KEY = "sk_live_your_api_key_here"
BASE_URL = "https://api.senraio.com/api/v1"

# Get predictions for a bill
bill_id = 12345
response = requests.get(
    f"{BASE_URL}/predict/{bill_id}",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    }
)

if response.status_code == 200:
    prediction = response.json()
    print(f"Royal Assent: {prediction['royal_assent_probability']:.1%}")
    print(f"Next Stage (30d): {prediction['next_stage_30d_probability']:.1%}")
    print(f"Next Stage ETA: {prediction['timeline_eta_days']:.1f} days (until next stage, not Royal Assent)")
else:
    print(f"Error: {response.status_code} - {response.text}")

Batch Predictions

Python
import requests

API_KEY = "sk_live_your_api_key_here"
BASE_URL = "https://api.senraio.com/api/v1"

# Get predictions for multiple bills
bill_ids = [12345, 12346, 12347]
response = requests.post(
    f"{BASE_URL}/predictions/batch",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    },
    json={
        "bill_ids": bill_ids,
        "reference_date": "2025-12-18"
    }
)

if response.status_code == 200:
    data = response.json()
    for result in data['results']:
        print(f"Bill {result['bill_id']}: {result['royal_assent_probability']:.1%}")
else:
    print(f"Error: {response.status_code} - {response.text}")

Create Predictive Alert

Python
import requests

API_KEY = "sk_live_your_api_key_here"
BASE_URL = "https://api.senraio.com/api/v1"

# Create alert threshold
response = requests.post(
    f"{BASE_URL}/predictions/alerts/thresholds",
    headers={
        "Authorization": f"Bearer {API_KEY}",
        "Content-Type": "application/json"
    },
    json={
        "watchlist_id": 1,
        "alert_type": "timeline_eta",
        "threshold_value": 7.0,
        "comparison": "less_than"
    }
)

if response.status_code == 200:
    alert = response.json()
    print(f"Alert created: {alert['id']}")
else:
    print(f"Error: {response.status_code} - {response.text}")

JavaScript / Node.js

Get Predictions

Node.js
const fetch = require('node-fetch');

const API_KEY = 'sk_live_your_api_key_here';
const BASE_URL = 'https://api.senraio.com/api/v1';

async function getPrediction(billId) {
  const response = await fetch(
    `${BASE_URL}/predict/${billId}`,
    {
      headers: {
        'Authorization': `Bearer ${API_KEY}`,
        'Content-Type': 'application/json'
      }
    }
  );

  if (response.ok) {
    const prediction = await response.json();
    console.log(`Royal Assent: ${(prediction.royal_assent_probability * 100).toFixed(1)}%`);
    console.log(`Next Stage (30d): ${(prediction.next_stage_30d_probability * 100).toFixed(1)}%`);
    console.log(`Next Stage ETA: ${prediction.timeline_eta_days.toFixed(1)} days (until next stage, not Royal Assent)`);
    return prediction;
  } else {
    throw new Error(`Error: ${response.status} - ${await response.text()}`);
  }
}

// Usage
getPrediction(12345).catch(console.error);

cURL Examples

Get Predictions

cURL
curl -X GET "https://api.senraio.com/api/v1/predict/12345" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json"

Batch Predictions

cURL
curl -X POST "https://api.senraio.com/api/v1/predictions/batch" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "bill_ids": [12345, 12346, 12347],
    "reference_date": "2025-12-18"
  }'

Create Alert

cURL
curl -X POST "https://api.senraio.com/api/v1/predictions/alerts/thresholds" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "watchlist_id": 1,
    "alert_type": "timeline_eta",
    "threshold_value": 7.0,
    "comparison": "less_than"
  }'