API Authentication
All FinBrain API requests require authentication using your API key. This guide explains how to obtain and use your API key.
Getting Your API Key
Section titled “Getting Your API Key”- Visit finbrain.tech and create an account
- Navigate to your account dashboard
- Copy your API key from the API section
Your API key is a unique string that identifies your account and tracks your usage.
Using Your API Key
Section titled “Using Your API Key”The FinBrain API uses token-based authentication. Include your API key as a query parameter in every request:
?token=YOUR_API_KEYExample Requests
Section titled “Example Requests”from finbrain import FinBrainClient
# Initialize with your API keyfb = FinBrainClient(api_key="YOUR_API_KEY")
# All subsequent calls use this key automatically# Use as_dataframe=True for pandas DataFramesdf = fb.predictions.ticker("AAPL", prediction_type="daily", as_dataframe=True)sentiment_df = fb.sentiments.ticker("S&P 500", "AAPL", as_dataframe=True)const API_KEY = "YOUR_API_KEY";const BASE_URL = "https://api.finbrain.tech/v1";
async function getPredictions(ticker) { const response = await fetch( `${BASE_URL}/ticker/${ticker}/predictions/daily?token=${API_KEY}` ); return response.json();}
const data = await getPredictions("AAPL");console.log(data);# Get predictions for Applecurl "https://api.finbrain.tech/v1/ticker/AAPL/predictions/daily?token=YOUR_API_KEY"
# Get sentiment datacurl "https://api.finbrain.tech/v1/sentiments/S%26P%20500/AAPL?token=YOUR_API_KEY"
# Get insider transactionscurl "https://api.finbrain.tech/v1/insidertransactions/S%26P%20500/AAPL?token=YOUR_API_KEY"API Key Security
Section titled “API Key Security”Follow these best practices to keep your API key secure:
- Store your API key in environment variables
- Use secrets management in production (AWS Secrets Manager, HashiCorp Vault, etc.)
- Rotate your key periodically
- Use different keys for development and production
- Commit your API key to version control
- Share your API key publicly
- Include your API key in client-side code
- Log requests that contain your API key
Environment Variables Example
Section titled “Environment Variables Example”import osfrom finbrain import FinBrainClient
# Load from environment variableapi_key = os.environ.get("FINBRAIN_API_KEY")fb = FinBrainClient(api_key=api_key)const API_KEY = process.env.FINBRAIN_API_KEY;
const response = await fetch( `https://api.finbrain.tech/v1/ticker/AAPL/predictions/daily?token=${API_KEY}`);# Set environment variableexport FINBRAIN_API_KEY="your_api_key_here"
# Use in requestscurl "https://api.finbrain.tech/v1/ticker/AAPL/predictions/daily?token=$FINBRAIN_API_KEY"Authentication Errors
Section titled “Authentication Errors”If authentication fails, you’ll receive one of these error responses:
401 Unauthorized
Section titled “401 Unauthorized”{ "error": "Unauthorized", "message": "Invalid or missing API key"}Causes:
- Missing
tokenparameter - Invalid API key
- Expired API key
Solution: Verify your API key is correct and included in the request.
403 Forbidden
Section titled “403 Forbidden”{ "error": "Forbidden", "message": "Access denied for this resource"}Causes:
- Your subscription doesn’t include this endpoint
- Account suspended
- Rate limit exceeded
Solution: Check your subscription tier or contact support.
Rate Limits
Section titled “Rate Limits”API rate limits depend on your subscription tier:
| Tier | Requests/Day | Requests/Minute |
|---|---|---|
| Free | 100 | 10 |
| Basic | 1,000 | 60 |
| Professional | 10,000 | 300 |
| Enterprise | Unlimited | Custom |
When you exceed your rate limit, you’ll receive a 429 Too Many Requests response.
Next Steps
Section titled “Next Steps”- Quick Start - Make your first API call
- API Reference - Complete endpoint documentation
- Error Codes - All error responses explained