Authentication overview
Financial Modeling Prep (FMP) secures access to its financial data APIs primarily through API keys. An API key is a unique identifier provided to users upon registration, which must be included in every request to the FMP API. This mechanism allows FMP to identify the requesting user, enforce access policies, and track usage against account quotas, including the free tier's 250 requests per day. The API key model is a common authentication pattern for web services, offering a balance of security and ease of implementation for developers integrating financial data into their applications.
The FMP API supports RESTful endpoints, with API keys passed as a query parameter in the URL. This approach is consistent across all data categories offered, including stock market data, forex, cryptocurrency, and economic indicators. Developers are responsible for safeguarding their API keys to prevent unauthorized access and usage.
Supported authentication methods
Financial Modeling Prep exclusively uses API keys for authentication across all its services. This direct method requires developers to append their unique key to each API request URL. There are no alternative authentication flows such as OAuth 2.0 or mutual TLS supported for direct API access. The simplicity of API key authentication facilitates quick integration, while placing the responsibility for key security on the developer.
The following table outlines the specifics of the API key authentication method used by Financial Modeling Prep:
| Method | When to Use | Security Level | Credential Format | Credential Transport |
|---|---|---|---|---|
| API Key | All API requests to Financial Modeling Prep | Basic (requires secure key management) | Alphanumeric string | URL Query Parameter |
Getting your credentials
To obtain your Financial Modeling Prep API key, you need to register for an account on their platform. The process typically involves:
- Account Registration: Navigate to the Financial Modeling Prep homepage and sign up for a new account. You can choose between the free tier or a paid subscription based on your anticipated usage.
- Dashboard Access: After successful registration and login, you will be redirected to your developer dashboard.
- API Key Retrieval: Your unique API key will be prominently displayed on your developer dashboard. It is automatically generated upon account creation.
- Key Management: The dashboard provides options to regenerate your API key if it is compromised or if you need a new one for security reasons.
Once you have your API key, you can immediately begin making authenticated requests to the Financial Modeling Prep API. Ensure you copy the key accurately, as any discrepancies will result in authentication failures.
Authenticated request example
To make an authenticated request to the Financial Modeling Prep API, you must append your API key as a query parameter named apikey to the request URL. The following examples demonstrate how to fetch historical stock data for Apple (AAPL) using different programming languages, assuming YOUR_API_KEY is replaced with your actual key.
Python example
import requests
API_KEY = "YOUR_API_KEY"
SYMBOL = "AAPL"
URL = f"https://financialmodelingprep.com/api/v3/historical-price-full/{SYMBOL}?apikey={API_KEY}"
try:
response = requests.get(URL)
response.raise_for_status() # Raise an HTTPError for bad responses (4xx or 5xx)
data = response.json()
print(data)
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
JavaScript (Fetch API) example
const API_KEY = "YOUR_API_KEY";
const SYMBOL = "AAPL";
const URL = `https://financialmodelingprep.com/api/v3/historical-price-full/${SYMBOL}?apikey=${API_KEY}`;
fetch(URL)
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error("An error occurred:", error);
});
cURL example
curl "https://financialmodelingprep.com/api/v3/historical-price-full/AAPL?apikey=YOUR_API_KEY"
In all these examples, replace YOUR_API_KEY with the actual API key obtained from your FMP developer dashboard. Incorrect or missing API keys will result in 401 Unauthorized or 403 Forbidden errors.
Security best practices
While API keys offer convenience, their security relies heavily on correct handling. Adhering to best practices is crucial to prevent unauthorized access to your account and data:
- Keep API Keys Confidential: Treat your API key like a password. Do not hardcode it directly into client-side code (e.g., frontend JavaScript that runs in a user's browser) as it can be easily extracted. Instead, use server-side environments or secure environment variables. For client-side applications, route requests through a backend proxy server that adds the API key securely.
- Use Environment Variables: Store your API key in environment variables rather than directly in your code. This practice prevents the key from being committed to version control systems (like Git) and exposed if your repository becomes public. Most programming languages and deployment platforms support environment variables.
- Avoid Public Repositories: Never commit your API key, even within environment variable configuration files, to public code repositories. If your code must be public, ensure that sensitive keys are explicitly excluded using
.gitignoreor similar mechanisms. - Restrict Access: Limit who has access to your API key within your development team. Follow the principle of least privilege, granting access only to those who absolutely need it.
- Regenerate Keys Periodically: Financial Modeling Prep allows you to regenerate your API key from your dashboard. Consider regenerating keys periodically or immediately if you suspect a compromise. This can mitigate the impact of a leaked key.
- Monitor Usage: Regularly check your API usage statistics on the FMP developer dashboard. Unusual spikes in usage could indicate unauthorized access or a compromised key.
- Secure Communication: Always use HTTPS when making API requests. Financial Modeling Prep's API endpoints are served over HTTPS, which encrypts data in transit, protecting your API key and the data you retrieve from eavesdropping. The IETF's RFC 7230 defines the HTTP/1.1 message syntax and routing, emphasizing the use of secure transport.
- Implement Rate Limiting and Error Handling: While FMP enforces its own rate limits, implementing client-side rate limiting and robust error handling can prevent accidental overuse of your quota and provide better user experience in case of API issues.
By following these best practices, developers can enhance the security of their applications when integrating with the Financial Modeling Prep API, protecting both their data and their account.