Spaces:
Sleeping
Sleeping
Add Stripe connector: POST /v1/connect/stripe — paste read-only key, auto-score customers from billing data
687722a verified | import time | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from contextlib import asynccontextmanager | |
| from app.config import get_settings | |
| from app.database import init_db | |
| from app.routers import auth, predict, training, audio, usage, benchmarks, connect | |
| settings = get_settings() | |
| _start_time = time.time() | |
| async def lifespan(app: FastAPI): | |
| init_db() | |
| yield | |
| app = FastAPI( | |
| title="RevAI API", | |
| description=""" | |
| ## Churn Prediction & Lead Scoring API | |
| ### Core Features | |
| - **Predict churn**: Send customer data, get churn risk scores + explanations | |
| - **Score leads**: Prioritize sales pipeline by conversion probability | |
| - **Train custom models**: Upload labeled data, get a company-specific XGBoost model | |
| - **Analyze calls**: Transcribe support/sales calls, detect churn intent signals | |
| ### Authentication | |
| All endpoints (except `/v1/health`) require an API key header: | |
| ``` | |
| X-API-Key: revai_live_... | |
| ``` | |
| Get your key by registering at `/v1/auth/register`. | |
| ### Rate Limits | |
| | Tier | Predictions/mo | Models | Req/min | | |
| |---------|---------------|--------|---------| | |
| | Free | 100 | 0 | 10 | | |
| | Maker | 5,000 | 3 | 100 | | |
| | Growth | 50,000 | 10 | 500 | | |
| | Scale | 500,000 | Unlim | 2,000 | | |
| ### Pricing | |
| Visit [RevAI on Payhip](https://payhip.com) to subscribe. | |
| """, | |
| version=settings.version, | |
| lifespan=lifespan, | |
| docs_url="/docs", | |
| redoc_url="/redoc", | |
| openapi_url="/openapi.json", | |
| openapi_tags=[ | |
| {"name": "Prediction", "description": "Churn prediction and lead scoring endpoints"}, | |
| {"name": "training", "description": "Train custom XGBoost models on your labeled data"}, | |
| {"name": "audio", "description": "Analyze support/sales call recordings for churn intent signals"}, | |
| {"name": "auth", "description": "Register, login, and manage API keys"}, | |
| {"name": "benchmarks", "description": "Anonymized industry benchmark comparisons"}, | |
| {"name": "usage", "description": "Check usage, tier limits, and API health"}, | |
| ], | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| async def root_health(): | |
| return { | |
| "status": "ok", | |
| "api": "RevAI", | |
| "version": settings.version, | |
| "uptime": round(time.time() - _start_time, 1), | |
| } | |
| app.include_router(auth.router) | |
| app.include_router(predict.router) | |
| app.include_router(training.router) | |
| app.include_router(audio.router) | |
| app.include_router(benchmarks.router) | |
| app.include_router(usage.router) | |
| app.include_router(connect.router) | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=settings.debug) | |