Spaces:
Configuration error
Configuration error
β Castor Price Forecasting API - Ready for Deployment
π― Your API Key
castor_d167aa169b5e4219a66779e45fbaaefe
Status: β ACTIVE AND RUNNING
π Server Information
| Property | Value |
|---|---|
| Server URL (Local) | http://127.0.0.1:5000 |
| Server URL (Network) | http://172.16.32.97:5000 |
| Port | 5000 |
| Status | β Running |
| Environment | Python 3.12 + Flask |
π Quick Start Examples
1. Health Check (No Auth Required)
curl http://127.0.0.1:5000/api/health
Response:
{
"status": "healthy",
"timestamp": "2025-12-04T23:08:39",
"service": "Castor Price Forecasting API"
}
2. Get Forecast (With Auth)
curl -X POST http://127.0.0.1:5000/api/forecast \
-H "Content-Type: application/json" \
-H "X-API-Key: castor_d167aa169b5e4219a66779e45fbaaefe" \
-d '{
"product": "Castor",
"start_date": "2025-12-01",
"end_date": "2026-01-31"
}'
3. JavaScript Integration
const forecast = await fetch('http://127.0.0.1:5000/api/forecast', {
method: 'POST',
headers: {
'X-API-Key': 'castor_d167aa169b5e4219a66779e45fbaaefe',
'Content-Type': 'application/json'
},
body: JSON.stringify({
product: 'Castor',
start_date: '2025-12-01',
end_date: '2026-01-31'
})
});
const data = await forecast.json();
console.log(data.forecast);
4. Python Integration
import requests
response = requests.post(
'http://127.0.0.1:5000/api/forecast',
headers={
'X-API-Key': 'castor_d167aa169b5e4219a66779e45fbaaefe'
},
json={
'product': 'Castor',
'start_date': '2025-12-01',
'end_date': '2026-01-31'
}
)
forecast_data = response.json()
for item in forecast_data['forecast'][:5]:
print(f"{item['date']}: ARIMA={item['arima_price']}, LSTM={item['lstm_price']}")
π Available Endpoints
| Endpoint | Method | Auth Required | Description |
|---|---|---|---|
/ |
GET | No | API Documentation |
/api/health |
GET | No | Health Check |
/api/generate-key |
POST | No | Generate New API Key |
/api/forecast |
POST | Yes | Get Combined Forecast |
/api/forecast/arima |
POST | Yes | Get ARIMA Forecast Only |
/api/forecast/lstm |
POST | Yes | Get LSTM Forecast Only |
π§ Deployment Options
Option 1: Docker (Recommended for Production)
docker build -t castor-api .
docker run -p 5000:5000 castor-api
Option 2: Gunicorn (Production WSGI)
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 api_production:app
Option 3: Direct Python (Development)
python api_production.py
π¦ Files Included
| File | Purpose |
|---|---|
api_production.py |
Main API server |
api_keys.json |
API key storage |
DEPLOYMENT_GUIDE.md |
Complete deployment guide |
API_CREDENTIALS.md |
Credentials reference |
test_api_production.py |
API test suite |
βοΈ API Key Management
View Keys
cat api_keys.json
Generate New Key
curl -X POST http://127.0.0.1:5000/api/generate-key \
-H "Content-Type: application/json" \
-d '{"name": "my_app"}'
Revoke Key
Edit api_keys.json and set "active": false
π‘οΈ Security Checklist
- β API keys required for forecast endpoints
- β CORS enabled for cross-origin requests
- β Keys stored in JSON file (upgrade to database in production)
- β Request counting and tracking enabled
- β Error handling for invalid requests
For Production:
- Use HTTPS instead of HTTP
- Implement database for key storage
- Add rate limiting
- Use environment variables for configuration
- Implement request logging
- Set up monitoring and alerts
π§ͺ Testing the API
python test_api_production.py
Expected output:
β
Health: PASSED
β
Forecast: PASSED
β
ARIMA: PASSED
β
All tests passed! API is ready for deployment.
π API Response Example
Request:
{
"product": "Castor",
"start_date": "2025-12-01",
"end_date": "2025-12-03"
}
Response:
{
"status": "success",
"product": "Castor",
"last_known_price": 3856.50,
"forecast_period": {
"start": "2025-12-01",
"end": "2025-12-03",
"days": 3
},
"forecast": [
{
"date": "2025-12-01",
"arima_price": 3856.50,
"lstm_price": 3856.54,
"average_price": 3856.52
},
{
"date": "2025-12-02",
"arima_price": 3856.50,
"lstm_price": 3856.89,
"average_price": 3856.70
},
{
"date": "2025-12-03",
"arima_price": 3856.50,
"lstm_price": 3857.24,
"average_price": 3856.87
}
],
"timestamp": "2025-12-04T23:08:39"
}
π¨ Error Handling
Unauthorized (401)
{
"status": "error",
"message": "Invalid or missing API key. Generate one using /api/generate-key"
}
Not Found (404)
{
"status": "error",
"message": "Product not found in database"
}
Bad Request (400)
{
"status": "error",
"message": "Invalid date format"
}
π‘ Tips for App Developers
- Cache Results: Store forecasts locally to reduce API calls
- Handle Errors: Always check
statusfield in response - Set Timeouts: Use 30-second request timeout
- Store Key Securely: Use environment variables, not hardcoded
- Monitor Usage: Track requests_count in api_keys.json
π Support
For issues or questions:
- Check
DEPLOYMENT_GUIDE.mdfor detailed information - Review API response for error messages
- Test with
test_api_production.py - Enable debug logging in
api_production.py
β¨ Next Steps
- Test Locally: Use the examples above to verify the API
- Integrate into App: Use the provided code samples
- Deploy to Production: Follow
DEPLOYMENT_GUIDE.md - Monitor: Track API usage and performance
API Status: β READY FOR PRODUCTION DEPLOYMENT
Generated: 2025-12-04 API Key: castor_d167aa169b5e4219a66779e45fbaaefe Server: Running on http://127.0.0.1:5000