Get Result
Poll a prediction until it completes or reaches a failure terminal status.
For a deleted prediction in your organization, this endpoint returns its ID, model, and deleted status without request content or outputs. Stop polling; deletion is terminal. Shared results remain unavailable.
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.
Temporary errors (429, 500, 502, 503, 504) and dropped connections can happen on any request. Retry them with exponential backoff (honor Retry-After) and keep polling; do not stop the task because one request failed. Tasks can run for a long time, so the examples have no overall time limit. Each HTTP request has its own timeout. A client-side timeout does not mean the task failed. See Errors, Retries and Timeouts.
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"}
def get_result():
failures = 0
while True:
try:
response = requests.get(url, headers=headers, timeout=30)
if response.status_code not in {429, 500, 502, 503, 504}:
response.raise_for_status()
return response.json()["data"]
retry_after = response.headers.get("Retry-After", "")
except (requests.ConnectionError, requests.Timeout):
retry_after = ""
failures += 1
time.sleep(int(retry_after) if retry_after.isdigit() else min(30, 2 ** failures))
while True:
result = get_result()
status = result["status"]
if status == "completed":
print(result.get("outputs", []))
break
if status in failure_statuses:
raise RuntimeError(f"Task {task_id}: {result.get('error') or 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"]);
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
async function getResult() {
for (let failures = 1; ; failures++) {
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.WAVESPEED_API_KEY}` },
signal: AbortSignal.timeout(30_000),
}).catch(() => null); // network error or request timeout
if (response?.ok) return (await response.json()).data;
if (response && ![429, 500, 502, 503, 504].includes(response.status)) {
throw new Error(`Task ${taskId}: HTTP ${response.status}`);
}
const retryAfter = Number(response?.headers.get("retry-after"));
await sleep(retryAfter > 0 ? retryAfter * 1000 : Math.min(30_000, 2 ** failures * 1000));
}
}
while (true) {
const result = await getResult();
const { status } = result;
if (status === "completed") {
console.log(result.outputs ?? []);
break;
}
if (failureStatuses.has(status)) {
throw new Error(`Task ${taskId}: ${result.error || status}`);
}
await sleep(2000);
}Shell
TASK_ID="pred_abc123"
RESULT_URL="https://api.wavespeed.ai/api/v3/predictions/${TASK_ID}/result"
while true; do
# Retries 429, 5xx and dropped connections (honoring Retry-After).
if ! RESPONSE=$(curl --silent --show-error --fail-with-body \
--connect-timeout 10 --max-time 30 \
--retry 5 --retry-all-errors --retry-delay 2 \
"$RESULT_URL" \
--header "Authorization: Bearer $WAVESPEED_API_KEY"); then
echo "Task $TASK_ID: result request failed, polling again in 10s" >&2
sleep 10
continue
fi
RESULT=$(printf '%s' "$RESPONSE" | jq '.data')
STATUS=$(printf '%s' "$RESULT" | jq -r '.status')
case "$STATUS" in
completed) printf '%s\n' "$RESULT" | jq '.outputs'; break ;;
failed|cancelled|timeout|deleted) echo "Task $TASK_ID: $STATUS" >&2; 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, and Errors, Retries and Timeouts for retry guidance.