Skip to content

Error Codes

This page documents all error codes returned by the FinBrain API and how to handle them in your application.

All errors are returned as JSON with the following structure:

{
"error": "Error Type",
"message": "Human-readable error description"
}

The request is malformed or contains invalid parameters.

{
"error": "Bad Request",
"message": "Invalid ticker symbol: XYZ123"
}

Python SDK Exception: BadRequest

Common causes:

  • Invalid ticker symbol
  • Invalid market identifier
  • Invalid prediction type (not daily or monthly)
  • Malformed date parameters

How to fix:

  • Verify the ticker symbol exists using /available/tickers
  • Check the market name using /available/markets
  • Ensure dates are in YYYY-MM-DD format

API key missing or invalid.

{
"error": "Unauthorized",
"message": "Invalid or missing API key"
}

Python SDK Exception: AuthenticationError

Common causes:

  • Missing token query parameter
  • Invalid API key
  • Expired API key
  • Typo in API key

How to fix:

  • Ensure the token parameter is included in every request
  • Verify your API key is correct
  • Check your account dashboard for key status

Authenticated, but not authorised to perform this action.

{
"error": "Forbidden",
"message": "Access denied for this resource"
}

Python SDK Exception: PermissionDenied

Common causes:

  • Endpoint not included in your subscription tier
  • Account suspended
  • Accessing a premium endpoint with a free tier key

How to fix:

  • Check your subscription tier and available endpoints
  • Upgrade your subscription if needed
  • Contact support if you believe this is an error

Requested data or endpoint not found.

{
"error": "Not Found",
"message": "Ticker INVALID not found in market S&P 500"
}

Python SDK Exception: NotFound

Common causes:

  • Ticker doesn’t exist in the specified market
  • Endpoint path is incorrect
  • Data not available for the specified date range

How to fix:

  • Verify the ticker exists using /available/tickers
  • Check the endpoint path in the API reference
  • Try a different date range

Endpoint exists, but the HTTP method is not supported.

{
"error": "Method Not Allowed",
"message": "POST method not supported for this endpoint"
}

Python SDK Exception: MethodNotAllowed

Common causes:

  • Using POST instead of GET
  • Using PUT, DELETE, or PATCH on read-only endpoints

How to fix:

  • All FinBrain API endpoints use GET requests
  • Change your HTTP method to GET

Internal error on FinBrain’s side. Retrying later may help.

{
"error": "Internal Server Error",
"message": "An unexpected error occurred"
}

Python SDK Exception: ServerError

Common causes:

  • Server-side issues
  • Database connectivity problems
  • Temporary service disruption

How to fix:

  • Retry the request after a short delay
  • Check FinBrain status page for outages
  • Contact support if the issue persists
from finbrain import FinBrainClient
from finbrain.exceptions import (
AuthenticationError,
NotFound,
ServerError,
FinBrainError
)
import time
fb = FinBrainClient(api_key="YOUR_API_KEY")
def get_predictions_with_retry(ticker, max_retries=3):
"""Get predictions with automatic retry on failure"""
for attempt in range(max_retries):
try:
return fb.predictions.ticker(ticker, prediction_type="daily")
except AuthenticationError:
# Auth error - don't retry
raise Exception("Invalid API key")
except NotFound:
# Not found - don't retry
raise Exception(f"Ticker {ticker} not found")
except ServerError:
# Server error - retry with backoff
if attempt == max_retries - 1:
raise
wait_time = 2 ** attempt
print(f"Server error. Retrying in {wait_time}s...")
time.sleep(wait_time)
except FinBrainError:
# Other API error - retry
if attempt == max_retries - 1:
raise
time.sleep(1)
raise Exception("Max retries exceeded")
# Usage
try:
data = get_predictions_with_retry("AAPL")
print(data)
except Exception as e:
print(f"Error: {e}")

The Python SDK provides typed exceptions for each error code:

ExceptionHTTP StatusDescription
BadRequest400The request is malformed or contains invalid parameters
AuthenticationError401API key missing or invalid
PermissionDenied403Authenticated, but not authorised to perform this action
NotFound404Requested data or endpoint not found
MethodNotAllowed405Endpoint exists, but the HTTP method is not supported
ServerError500Internal error on FinBrain’s side
InvalidResponseN/AResponse couldn’t be parsed as JSON
FinBrainErrorN/ABase class for all SDK exceptions
  1. Always check status codes - Don’t assume success
  2. Implement retry logic - Use exponential backoff for 500 errors
  3. Cache responses - Reduce API calls by caching data locally
  4. Validate inputs - Check ticker symbols before making requests
  5. Handle errors gracefully - Provide meaningful error messages to users