How to Get Result
Retrieve results from completed WaveSpeedAI tasks.
Endpoint
GET https://api.wavespeed.ai/api/v3/predictions/{task-id}Request
curl --location --request GET 'https://api.wavespeed.ai/api/v3/predictions/pred_abc123' \
--header 'Authorization: Bearer ${WAVESPEED_API_KEY}'Response (Processing)
{
"code": 200,
"message": "success",
"data": {
"id": "pred_abc123",
"model": "wavespeed-ai/flux-dev",
"status": "processing",
"outputs": [],
"created_at": "2024-01-01T12:00:00.000Z"
}
}Response (Completed)
{
"code": 200,
"message": "success",
"data": {
"id": "pred_abc123",
"model": "wavespeed-ai/flux-dev",
"status": "completed",
"outputs": [
"https://cdn.wavespeed.ai/generated/image123.png"
],
"timings": {
"inference": 2500
},
"created_at": "2024-01-01T12:00:00.000Z"
}
}Response (Failed)
{
"code": 200,
"message": "success",
"data": {
"id": "pred_abc123",
"status": "failed",
"error": "Error message here",
"created_at": "2024-01-01T12:00:00.000Z"
}
}Status Values
| Status | Description | Action |
|---|---|---|
created | Task queued | Continue polling |
processing | Generation in progress | Continue polling |
completed | Success | Get outputs |
failed | Error occurred | Check error field |
Polling Example
import os
import requests
import time
api_key = os.environ.get("WAVESPEED_API_KEY")
def get_result(task_id, max_wait=300):
"""Poll for result with timeout."""
url = f"https://api.wavespeed.ai/api/v3/predictions/{task_id}"
headers = {"Authorization": f"Bearer {api_key}"}
start = time.time()
while time.time() - start < max_wait:
response = requests.get(url, headers=headers)
data = response.json()["data"]
if data["status"] == "completed":
return data["outputs"]
elif data["status"] == "failed":
raise Exception(data.get("error", "Unknown error"))
time.sleep(1) # Wait before next poll
raise Exception("Timeout waiting for result")
# Usage
outputs = get_result("pred_abc123")
print(outputs[0])Output Fields
| Field | Type | Description |
|---|---|---|
outputs | array | URLs to generated content |
timings.inference | integer | Generation time in ms |
error | string | Error message (if failed) |
Alternatives to Polling
- Webhooks — Receive notifications. See How to Use Webhooks
- Streaming — Real-time updates. See How to Use Streaming
- Python SDK — Auto-polling. See Python SDK