Get Result
Poll a prediction until it completes or reaches a failure terminal status.
Endpoint
GET https://api.wavespeed.ai/api/v3/predictions/{task-id}/resultUse the id returned when you submit the prediction. Send your API key in the Authorization header.
Status handling
| Status | Action |
|---|---|
completed | Return outputs |
failed, cancelled, timeout, deleted | Stop and report the error |
| Any other status | Continue polling |
Wait at least 2 seconds between requests.
Python
import os
import time
import requests
task_id = "pred_abc123"
url = f"https://api.wavespeed.ai/api/v3/predictions/{task_id}/result"
headers = {"Authorization": f"Bearer {os.environ['WAVESPEED_API_KEY']}"}
failure_statuses = {"failed", "cancelled", "timeout", "deleted"}
while True:
response = requests.get(url, headers=headers, timeout=30)
response.raise_for_status()
result = response.json()["data"]
status = result["status"]
if status == "completed":
print(result.get("outputs", []))
break
if status in failure_statuses:
raise RuntimeError(result.get("error") or f"Task ended with status: {status}")
time.sleep(2)Node.js
const taskId = "pred_abc123";
const url = `https://api.wavespeed.ai/api/v3/predictions/${taskId}/result`;
const failureStatuses = new Set(["failed", "cancelled", "timeout", "deleted"]);
while (true) {
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.WAVESPEED_API_KEY}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const result = (await response.json()).data;
const { status } = result;
if (status === "completed") {
console.log(result.outputs ?? []);
break;
}
if (failureStatuses.has(status)) {
throw new Error(result.error || `Task ended with status: ${status}`);
}
await new Promise(resolve => setTimeout(resolve, 2000));
}Shell
TASK_ID="pred_abc123"
RESULT_URL="https://api.wavespeed.ai/api/v3/predictions/${TASK_ID}/result"
while true; do
RESULT=$(curl --silent --show-error --fail-with-body \
"$RESULT_URL" \
--header "Authorization: Bearer $WAVESPEED_API_KEY" | jq '.data')
STATUS=$(printf '%s' "$RESULT" | jq -r '.status')
case "$STATUS" in
completed) printf '%s\n' "$RESULT" | jq '.outputs'; break ;;
failed|cancelled|timeout|deleted) printf '%s\n' "$RESULT" >&2; exit 1 ;;
*) sleep 2 ;;
esac
doneThe outputs array can contain URLs, text, or structured values depending on the model.
See Submit Task for how to create a prediction.