Serverless API Reference
Complete API reference for submitting and managing serverless tasks.
Base URL
https://api.wavespeed.ai/serverlessAuthentication
All requests require an API key:
Authorization: Bearer ${WAVESPEED_API_KEY}Submit Task (Async)
Submit a task and receive a task ID immediately.
Endpoint
POST /v1/runRequest
curl --location --request POST 'https://api.wavespeed.ai/serverless/v1/run' \
--header 'Authorization: Bearer ${WAVESPEED_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"endpoint": "my-endpoint",
"input": {
"prompt": "Hello, Waverless!"
}
}'Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
endpoint | string | Yes | Endpoint name |
input | object | Yes | Input data for your handler |
webhook | string | No | URL to receive result via webhook |
Response
{
"id": "task_abc123",
"status": "PENDING"
}Submit Task (Sync)
Submit a task and wait for the result.
Endpoint
POST /v1/runsyncRequest
curl --location --request POST 'https://api.wavespeed.ai/serverless/v1/runsync' \
--header 'Authorization: Bearer ${WAVESPEED_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"endpoint": "my-endpoint",
"input": {
"prompt": "Hello, Waverless!"
}
}'Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
endpoint | string | Yes | Endpoint name |
input | object | Yes | Input data for your handler |
timeout | integer | No | Max wait time in seconds (default: 300) |
Response
{
"id": "task_abc123",
"status": "COMPLETED",
"output": {
"result": "Processed: Hello, Waverless!"
},
"executionTime": 1500
}Get Task Status
Check the status and result of a task.
Endpoint
GET /v1/status/{task_id}Request
curl --location --request GET 'https://api.wavespeed.ai/serverless/v1/status/task_abc123' \
--header 'Authorization: Bearer ${WAVESPEED_API_KEY}'Response
{
"id": "task_abc123",
"status": "COMPLETED",
"output": {
"result": "Processed: Hello, Waverless!"
},
"executionTime": 1500,
"createdAt": "2024-01-15T10:30:00Z",
"completedAt": "2024-01-15T10:30:01Z"
}Task Status Values
| Status | Description |
|---|---|
PENDING | Task is queued, waiting for worker |
IN_PROGRESS | Worker is processing the task |
COMPLETED | Task finished successfully |
FAILED | Task failed (check error field) |
CANCELLED | Task was cancelled |
Cancel Task
Cancel a pending or in-progress task.
Endpoint
POST /v1/cancel/{task_id}Request
curl --location --request POST 'https://api.wavespeed.ai/serverless/v1/cancel/task_abc123' \
--header 'Authorization: Bearer ${WAVESPEED_API_KEY}'Response
{
"id": "task_abc123",
"status": "CANCELLED"
}List Workers
Get the list of online workers for an endpoint.
Endpoint
GET /v1/workersRequest
curl --location --request GET 'https://api.wavespeed.ai/serverless/v1/workers?endpoint=my-endpoint' \
--header 'Authorization: Bearer ${WAVESPEED_API_KEY}'Response
[
{
"id": "worker-001",
"status": "ONLINE",
"concurrency": 2,
"currentJobs": 1,
"endpoint": "my-endpoint"
}
]Worker Status Values
| Status | Description |
|---|---|
ONLINE | Worker is ready to accept tasks |
BUSY | Worker is at max concurrency |
DRAINING | Worker is shutting down gracefully |
OFFLINE | Worker is not connected |
Error Responses
Error Format
{
"error": {
"code": "INVALID_REQUEST",
"message": "Missing required field: endpoint"
}
}Error Codes
| Code | HTTP Status | Description |
|---|---|---|
UNAUTHORIZED | 401 | Invalid or missing API key |
FORBIDDEN | 403 | No access to this endpoint |
NOT_FOUND | 404 | Task or endpoint not found |
INVALID_REQUEST | 400 | Invalid request parameters |
RATE_LIMITED | 429 | Too many requests |
INTERNAL_ERROR | 500 | Server error |
Webhooks
Receive task results via webhook instead of polling.
Setup
Include a webhook URL when submitting a task:
curl --location --request POST 'https://api.wavespeed.ai/serverless/v1/run' \
--header 'Authorization: Bearer ${WAVESPEED_API_KEY}' \
--header 'Content-Type: application/json' \
--data-raw '{
"endpoint": "my-endpoint",
"input": {"prompt": "Hello"},
"webhook": "https://your-server.com/webhook"
}'Webhook Payload
When the task completes, we POST to your webhook:
{
"id": "task_abc123",
"status": "COMPLETED",
"output": {
"result": "Processed: Hello"
},
"executionTime": 1500
}Python Example
import os
import requests
import time
api_key = os.environ.get("WAVESPEED_API_KEY")
base_url = "https://api.wavespeed.ai/serverless"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
def submit_task(endpoint, input_data):
"""Submit async task."""
response = requests.post(
f"{base_url}/v1/run",
headers=headers,
json={"endpoint": endpoint, "input": input_data}
)
return response.json()
def get_status(task_id):
"""Get task status."""
response = requests.get(
f"{base_url}/v1/status/{task_id}",
headers=headers
)
return response.json()
def wait_for_result(task_id, timeout=300):
"""Poll until task completes."""
start = time.time()
while time.time() - start < timeout:
result = get_status(task_id)
if result["status"] in ["COMPLETED", "FAILED", "CANCELLED"]:
return result
time.sleep(2)
raise TimeoutError("Task timeout")
# Usage
task = submit_task("my-endpoint", {"prompt": "Hello"})
result = wait_for_result(task["id"])
print(result)