Skip to main content

Error Handling

Learn how to handle errors gracefully when using the Kanva API.

Error Response Format

All errors follow a consistent format:

{
"success": false,
"error": "Human-readable error message"
}

HTTP Status Codes

CodeMeaningAction
400Bad RequestFix the request format or parameters
401UnauthorizedCheck your API key
403ForbiddenYou don't have access to this resource
404Not FoundThe project or job doesn't exist
408Request TimeoutPrediction took too long (use async mode)
429Too Many RequestsYou've hit the rate limit
500Internal Server ErrorRetry later or contact support

Common Errors

Invalid Input Features

{
"success": false,
"error": "Invalid input: missing required feature 'date'"
}

Solution: Ensure all required features are included and correctly named.

Type Mismatch

{
"success": false,
"error": "Type error: feature 'value' expected numeric, got string"
}

Solution: Check that feature values match the expected data types.

Array Length Mismatch

{
"success": false,
"error": "All input arrays must have the same length"
}

Solution: Ensure all feature arrays have equal lengths for batch predictions.

Retry Strategy

For transient errors (5xx, network issues), implement exponential backoff:

import time
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

session = requests.Session()
retries = Retry(
total=3,
backoff_factor=0.5,
status_forcelist=[500, 502, 503, 504]
)
session.mount("https://", HTTPAdapter(max_retries=retries))

response = session.post(url, headers=headers, json=data)

Rate Limit Handling

When you receive a 429 error, check the Retry-After header:

if response.status_code == 429:
retry_after = int(response.headers.get("Retry-After", 60))
time.sleep(retry_after)
# Retry the request

See Rate Limits for more details.