Examples
Complete patterns for starting and following a mission.
Python stream consumer
import json
import os
import httpx
headers = {"Authorization": f"Bearer {os.environ['BLOODHOUND_API_KEY']}"}
mission = httpx.post(
"https://hound.aiia.ro/eve/v1/session",
headers=headers,
json={"message": "MISSION TYPE: research\nMISSION BUDGET TYPE: fixed\nMISSION BUDGET (hard maximum): $2.00 USD\n\nMISSION OBJECTIVE:\nCompare three current UK payroll platforms for a 50-person company, using primary sources."},
).raise_for_status().json()
url = f"https://hound.aiia.ro/eve/v1/session/{mission['sessionId']}/stream?startIndex=0"
with httpx.stream("GET", url, headers=headers, timeout=None) as response:
response.raise_for_status()
for line in response.iter_lines():
event = json.loads(line)
print(event["type"])
if event["type"] in {"session.completed", "session.failed"}:
breakTypeScript stream consumer
const response = await fetch(streamUrl, {
headers: { authorization: `Bearer ${process.env.BLOODHOUND_API_KEY}` },
});
if (!response.ok || !response.body) throw new Error(`Stream failed: ${response.status}`);
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
let buffer = "";
for (;;) {
const { value, done } = await reader.read();
if (done) break;
buffer += value;
const lines = buffer.split("\n");
buffer = lines.pop() ?? "";
for (const line of lines) {
if (!line.trim()) continue;
const event = JSON.parse(line);
console.log(event.type);
}
}Next steps
Review streaming before adding retries and checkpoints.
