Beep AI MLServer
The companion server that hosts published models.
What MLServer is
Beep AI MLServer is a separate Flask application in the Beep.AI.MLServer folder of the repository. It stores published model bundles, builds an environment for each one, and answers prediction requests over REST. MLStudio publishes to it and can request predictions from it.
Start it
cd Beep.AI.MLServer
python run.py
It listens on 0.0.0.0:5008 by default and debug is off. The dashboard is at /, the Swagger UI is at /api/v1/, and a setup page at /setup lets you choose the database and create the first administrator. For production there are wsgi.py and gunicorn.conf.py (bind address from configuration, 4 workers, sync worker class, graceful timeout 10 seconds, keepalive 5 seconds).
Configuration
MLServer reads config/mlserver_config.json and then config/mlserver_config.<env>.json. The environment name comes from MLSERVER_ENV (default development; dev, test, qa, prod and production are accepted aliases). Any key can be overridden with an environment variable named MLSERVER_<KEY> in capitals.
In production, putting secret_key or jwt_secret_key in the files without setting MLSERVER_SECRET_KEY stops the server with an error. MLSERVER_JWT_SECRET_KEY is optional.
| Key | Default |
|---|---|
| server_host | 0.0.0.0 |
| server_port | 5008 |
| debug | false |
| db_engine | sqlite |
| db_file | mlserver.db |
| db_pool_size / db_max_overflow / db_pool_timeout | 10 / 20 / 30 |
| models_folder | deployed_models |
| bundle_storage_backend | local |
| bundle_storage_s3_prefix | mlserver-bundles |
| max_bundle_size_mb | 500 |
| env_build_timeout_seconds | 600 |
| request_timeout_seconds | 30 |
| inference_timeout_seconds | 120 |
| job_workers | 4 |
| job_queue_backend | threadpool |
| redis_url | redis://localhost:6379/0 |
| job_max_retries / job_retry_backoff_seconds | 3 / 5 |
| jwt_access_token_expires | 3600 |
| require_model_approval | false |
| enforce_token_expiry_in_production | true |
| default_token_expiry_days | 90 |
| log_level / log_format | INFO / text |
| rate_limit_predict | 60 per minute |
| rate_limit_storage_backend | memory |
| drift_detection_enabled | true |
| drift_threshold_psi | 0.10 |
| drift_baseline_sample_size | 10000 |
| drift_recalculate_interval_minutes | 60 |
| circuit_breaker_enabled | true |
| circuit_breaker_failure_threshold | 5 |
| circuit_breaker_open_seconds | 60 |
| circuit_breaker_slowcall_threshold_ms | 5000 |
| webhook_delivery_enabled | true |
| webhook_timeout_seconds | 10 |
| webhook_max_attempts | 3 |
| webhook_retry_backoff_seconds | [5, 25, 125] |
| promotion_request_timeout_seconds | 60 |
| gunicorn_workers | 4 |
Roles and tokens
MLServer roles are admin, ops, developer and consumer. Admin ranks highest, ops and developer next, consumer lowest. A model moves through the statuses pending, building, built, review_pending, approved, rejected, active, failed and retired.
Sign in to get tokens, or create API tokens:
curl -X POST http://127.0.0.1:5008/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "<user>", "password": "<password>"}'
The reply has access_token and refresh_token. Renew with POST /api/v1/auth/refresh. GET /api/v1/auth/me shows who you are.
API tokens: GET or POST /api/v1/tokens. A create request takes name, role, model_scope and expires_days (0 means no expiry). The plain token is shown once. Developers can create only consumer tokens. Read or delete one with /api/v1/tokens/<id>. The tokens page in the dashboard is /tokens.
Publish a model
A bundle is a ZIP file that contains a scoring_script.py (the API takes it base64 encoded in bundle_b64). From MLStudio, use the MLServer models page at /ml-server/models/publish, or call the MLStudio route POST /api/v1/ml-server/bundle-models with bundle_path and name. MLStudio then sends the bundle, base64 encoded, to MLServer. You can also call MLServer directly.
curl -X POST http://127.0.0.1:5008/api/v1/models \
-H "Authorization: Bearer <token>" -H "Content-Type: application/json" \
-d '{"name": "churn", "bundle_b64": "<base64-of-bundle>", "task_type": "classification", "framework": "scikit-learn"}'
- Needs the developer role. Optional fields: description, task_type, framework, input_schema, output_schema, mlstudio_experiment_id, mlstudio_project_id, mlstudio_source.
- Success is 201. The version number increases automatically for the same model name.
- The size limit is max_bundle_size_mb. A bundle without scoring_script.py is refused (BUNDLE_MISSING_SCRIPT).
- MLServer builds the model's environment in the background. Watch the status on the model page. If the build failed, use rebuild-env.
- With require_model_approval on, a reviewer approves or rejects it from the review queue.
Request predictions
curl -X POST http://127.0.0.1:5008/api/v1/models/<model_id>/predict \
-H "Authorization: Bearer <token>" -H "Content-Type: application/json" \
-d '{"data": [{"age": 41, "plan": "basic"}]}'
Success is 200 with success, model_id, model_name, version, predictions, row_count and latency_ms. With "async": true the reply is 202 with job_id, status and poll_url. Check the job at /api/v1/jobs/<job_id>.
MLServer API summary
| Group | Routes under /api/v1 |
|---|---|
| Health | /health, /health/live, /health/ready |
| Auth | /auth/login, /auth/refresh, /auth/me |
| Tokens | /tokens, /tokens/<id> |
| Models | /models (list, publish), /models/review-queue, /models/<id> (GET, PUT, DELETE), /models/<id>/versions, /models/<id>/rebuild-env, /models/<id>/approve, /models/<id>/reject, /models/<id>/metrics |
| Predict | /models/<id>/predict |
| Jobs | /jobs/<job_id> (listing all jobs is administrator only) |
| Routes | /routes, /routes/<name>, /routes/<name>/predict. A route splits traffic between models by weight. |
| Admin | stats, settings, users, my-models, access groups, token access groups, access control audit, audit, models/<id>/promote, webhooks (create, list, change, remove, test) |
| Reference | openapi.json, a Postman collection and an errors catalogue |
MLServer errors
| Code | Meaning |
|---|---|
| INVALID_TOKEN, TOKEN_EXPIRED, INVALID_CREDENTIALS | Token or login problem. |
| INSUFFICIENT_ROLE, MODEL_SCOPE_ERROR, FORBIDDEN | Your role or token scope does not allow it. |
| MODEL_NOT_FOUND, RESOURCE_NOT_FOUND, JOB_NOT_FOUND | 404. |
| MODEL_NOT_ACTIVE | 409. The model is not in the active status. |
| MODEL_CIRCUIT_OPEN | 503 with retry_after. The model failed repeatedly and is paused. |
| BUNDLE_TOO_LARGE, BUNDLE_MISSING_SCRIPT, BUNDLE_INVALID | Bundle problems. |
| INFERENCE_TIMEOUT, INFERENCE_FAILED | Prediction problems. |
| VALIDATION_ERROR | 400. The request body is wrong. |
| INTERNAL_ERROR | Server side failure. |
Using MLServer from MLStudio
| MLStudio route under /api/v1/ml-server | What it does |
|---|---|
| GET bundle-models | List your published models (calls MLServer my-models). |
| POST bundle-models | Publish. Body bundle_path and name. Success is 201. |
| GET, PUT, DELETE bundle-models/<id> | Read, change, or retire. |
| GET bundle-models/<id>/versions | Version list. |
| POST predict | Body {"data": [rows], "async": false}. |
| GET jobs/<job_id> | Job status. |
MLStudio sends the key from ml_server_api_key as a Bearer token. Web pages: /ml-server/models and /ml-server/models/<id>.