Error Handling
The Predexon API uses standard HTTP status codes and returns consistent error responses to help you handle issues gracefully.
Error Response Format
All errors return a JSON object with error and message fields:
{
"error": "Bad Request",
"message": "Invalid parameter: limit must be between 1 and 100"
}
HTTP Status Codes
| Status Code | Error Type | Description |
|---|
400 | Bad Request | Invalid parameters or malformed request |
401 | Unauthorized | Missing or invalid API key |
403 | Forbidden | API key doesn't have access to this resource |
404 | Not Found | Resource doesn't exist (market, wallet, etc.) |
422 | Validation Error | Request validation failed |
429 | Too Many Requests | Rate limit exceeded |
500 | Internal Server Error | Something went wrong on our end |
503 | Service Unavailable | Service temporarily unavailable |
Common Error Scenarios
Authentication Errors (401)
curl -X GET "https://api.predexon.com/v1/polymarket/markets/active" \
-H "Authorization: Bearer invalid_key"
{
"error": "Unauthorized",
"message": "Invalid API key"
}
Make sure your API key is prefixed with Bearer in the Authorization header.
Invalid Parameters (400)
curl -X GET "https://api.predexon.com/v1/polymarket/markets/active?limit=500"
{
"error": "Bad Request",
"message": "limit must be between 1 and 100"
}
Resource Not Found (404)
curl -X GET "https://api.predexon.com/v1/matching-markets?polymarket_market_slug=nonexistent-market"
{
"error": "Not Found",
"message": "Market not found: nonexistent-market"
}
Rate Limit Exceeded (429)
{
"error": "Too Many Requests",
"message": "Rate limit exceeded. Please wait before making more requests."
}
When you receive a 429, check the RateLimit-Reset header for when you can retry.
Validation Errors (422)
For complex validation failures, the response includes details:
{
"detail": [
{
"loc": ["query", "granularity"],
"msg": "field required",
"type": "value_error.missing"
}
]
}
Handling Errors in Code
Python
import requests
def get_markets():
response = requests.get(
"https://api.predexon.com/v1/polymarket/markets/active",
headers={"Authorization": f"Bearer {API_KEY}"},
params={"limit": 10}
)
if response.status_code == 200:
return response.json()
elif response.status_code == 401:
raise Exception("Invalid API key")
elif response.status_code == 429:
retry_after = response.headers.get("RateLimit-Reset", 60)
raise Exception(f"Rate limited. Retry after {retry_after}s")
elif response.status_code == 400:
error = response.json()
raise Exception(f"Bad request: {error['message']}")
else:
response.raise_for_status()
JavaScript / TypeScript
async function getMarkets() {
const response = await fetch(
"https://api.predexon.com/v1/polymarket/markets/active?limit=10",
{
headers: { Authorization: `Bearer ${API_KEY}` },
}
);
if (response.ok) {
return await response.json();
}
const error = await response.json();
switch (response.status) {
case 401:
throw new Error("Invalid API key");
case 429:
const retryAfter = response.headers.get("RateLimit-Reset") || 60;
throw new Error(`Rate limited. Retry after ${retryAfter}s`);
case 400:
throw new Error(`Bad request: ${error.message}`);
default:
throw new Error(`API error: ${response.status}`);
}
}
Best Practices
Implement Exponential Backoff - When hitting rate limits, use exponential backoff with jitter to avoid thundering herd problems.
- Always check status codes - Don't assume requests succeed
- Parse error messages - They contain useful debugging information
- Handle 429s gracefully - Implement retry logic with backoff
- Log errors - Include the full error response for debugging
- Validate inputs client-side - Catch obvious errors before making requests
Getting Help
If you encounter unexpected errors:
- Check the API Reference for correct parameter usage
- Verify your API key is valid at predexon.com
- Join our Discord for support
- Email [email protected] with error details
Last modified on