Skip to content

Authentication

All FinBrain API v2 requests require authentication using your API key. The v2 API supports multiple authentication methods for flexibility and backward compatibility.

The API checks for credentials in the following order of precedence:

Pass your API key as a Bearer token in the Authorization header:

Authorization: Bearer YOUR_API_KEY

This is the recommended method for all new integrations. It keeps credentials out of URLs and is compatible with standard HTTP tooling.

Pass your API key in the X-API-Key header:

X-API-Key: YOUR_API_KEY

Pass your API key as the apiKey query parameter:

https://api.finbrain.tech/v2/predictions/daily/AAPL?apiKey=YOUR_API_KEY

4. Legacy Query Parameter (v1 Backward Compatibility)

Section titled “4. Legacy Query Parameter (v1 Backward Compatibility)”

The v1 token query parameter is still supported for backward compatibility:

https://api.finbrain.tech/v2/predictions/daily/AAPL?token=YOUR_API_KEY
Terminal window
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.finbrain.tech/v2/predictions/daily/AAPL"
  1. Visit finbrain.tech
  2. Create an account or sign in
  3. Navigate to your account dashboard
  4. Copy your API key

Returned when the API key is missing or invalid.

Response:

{
"success": false,
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or missing API key"
}
}

Common causes:

  • Missing API key in the request
  • Typo in the API key
  • Using an expired or revoked API key

Returned when the API key is valid but lacks permission for the requested resource.

Response:

{
"success": false,
"error": {
"code": "FORBIDDEN",
"message": "Access denied for this resource"
}
}

Common causes:

  • Endpoint not included in your subscription tier
  • Account suspended
  • Accessing a restricted resource

Returned when rate limits are exceeded.

Response:

{
"success": false,
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Rate limit exceeded. Please slow down."
}
}

The v2 API includes rate limit information in every response via HTTP headers:

HeaderDescription
X-RateLimit-LimitMaximum requests allowed per hour
X-RateLimit-RemainingRequests remaining in current window
X-RateLimit-ResetTime when rate limit resets (ISO 8601)

Example response headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 847
X-RateLimit-Reset: 2026-03-09T15:00:00Z

When you exceed the rate limit, the API returns a 429 Too Many Requests response. Use the X-RateLimit-Reset header to determine when you can resume making requests.

TierRequests/Hour
Free100
Basic1,000
Professional10,000
EnterpriseCustom

Never hardcode your API key. Use environment variables:

import os
import requests
api_key = os.environ.get("FINBRAIN_API_KEY")
headers = {"Authorization": f"Bearer {api_key}"}
response = requests.get(
"https://api.finbrain.tech/v2/predictions/daily/AAPL",
headers=headers
)

For local development, use a .env file:

.env
FINBRAIN_API_KEY=your_api_key_here

Add .env to your .gitignore:

.gitignore
.env

In production, use your platform’s secrets management:

  • AWS: Secrets Manager or Parameter Store
  • Google Cloud: Secret Manager
  • Azure: Key Vault
  • Heroku: Config Vars
  • Vercel: Environment Variables
  1. Never commit API keys to version control
  2. Don’t expose keys in client-side code - use a backend proxy
  3. Rotate keys periodically - especially after team member changes
  4. Use different keys for development and production
  5. Monitor usage - check for unexpected API call patterns
  6. Prefer header-based auth - query parameters can leak in server logs and browser history