#!/usr/bin/env python3
import json, requests
from datetime import datetime
from rich import print as rprint
from rich.console import Console
from rich.table import Table
BASE_URL = "https://api.futureagi.com"
FI_API_KEY = "<YOUR_API_KEY>"
FI_SECRET_KEY = "<YOUR_SECRET_KEY>"
console = Console()
def headers():
return (
{
"X-Api-Key": FI_API_KEY,
"X-Secret-Key": FI_SECRET_KEY,
"Content-Type": "application/json",
}
)
def get_first_label_id():
resp = requests.get(f"{BASE_URL}/tracer/get-annotation-labels/", headers=headers(), timeout=20)
resp.raise_for_status()
label = resp.json()["result"][0]
console.log(f"Using label: {label['name']} ({label['type']})")
return label["id"]
def build_payload(span_id, label_id):
ts = datetime.utcnow().isoformat(timespec="seconds")
return {
"records": [
{
"observation_span_id": span_id,
"annotations": [
{"annotation_label_id": label_id, "annotator_id": "human_a", "value": "good"},
{"annotation_label_id": label_id, "annotator_id": "human_a", "value_float": 4.2},
],
"notes": [{"text": "First note " + ts, "annotator_id": "human_a"}],
}
]
}
def pretty(resp_json):
table = Table(title="Bulk-Annotation Result", show_header=True, header_style="bold cyan")
table.add_column("Key"); table.add_column("Value", overflow="fold")
for k, v in resp_json.items():
table.add_row(k, json.dumps(v, indent=2) if isinstance(v, (dict, list)) else str(v))
console.print(table)
if __name__ == "__main__":
SPAN_ID = "<SPAN_ID>"
payload = build_payload(SPAN_ID, get_first_label_id())
rprint({"payload": payload})
resp = requests.post(f"{BASE_URL}/tracer/bulk-annotation/", headers=headers(), json=payload, timeout=60)
resp.raise_for_status()
pretty(resp.json())