API Reference

Scout exposes a RESTful API for all its operations. This allows for programmatic control over Test creation, management, recommendations, and system administration.

The base URL for the API is typically http://localhost:8000 when running locally with default Docker Compose settings.

Authentication

API endpoints can be protected. If API protection is enabled (via Admin controls or SCOUT_PROTECTED_API env var), requests to protected endpoints must include an Authorization header with a Bearer token.

Authorization: Bearer YOUR_AUTH_TOKEN

You can generate an auth token via the Admin UI or the POST /admin/generate_token endpoint.

Endpoints that require authentication are marked with (Protected).

Admin Endpoints

These endpoints are for managing the Scout system itself.

Get Protection Status

  • GET /admin/get_protection

  • Description: Checks if API protection is currently enabled.

  • Response:

    {
      "protected_api": true_or_false
    }

Set Protection Status

  • POST /admin/set_protection

  • Description: Enables or disables API protection.

  • Request Body:

  • Response:

Generate Authentication Token

  • POST /admin/generate_token

  • Description: Generates a new authentication token. If API protection is enabled, this token will be required for protected endpoints. The current token (if one exists) will be invalidated/replaced.

  • Response:

Check Redis Health

  • GET /admin/redis_health

  • Description: Checks the connection to Redis and provides some basic stats.

  • Response:

Get Test Default Configuration

  • GET /admin/model_config

  • Description: Retrieves the default configuration settings for new Tests.

  • Response (example values):

Update Test Default Configuration

  • POST /admin/model_config

  • Description: Updates the default configuration settings for new Tests.

  • Request Body:

  • Response:

Get System Configuration

  • GET /admin/system_config

  • Description: Retrieves general system configuration settings.

  • Response (example values):

Update System Configuration

  • POST /admin/system_config

  • Description: Updates general system configuration settings. Restart might be needed for some changes (e.g., host/port).

  • Request Body:

  • Response:

Update Redis Configuration (Live)

  • POST /admin/redis_config

  • Description: Updates Redis connection parameters (host, port) and context Time-To-Live (TTL) live. Note that changing these for an active system could disrupt operations if the new Redis is not a mirror or if context TTL changes drastically.

  • Request Body:

  • Response:

    (Or an error message if connection to new Redis fails)

Test Endpoints

These endpoints are for creating, managing, and interacting with Tests.

Create Test

  • POST /api/create_model (Protected)

  • Description: Creates a new Test.

  • Request Body (CreateModelRequest):

  • Response:

Delete Test

  • POST /api/delete_model/{cb_model_id} (Protected)

  • Description: Deletes a Test and all its associated data.

  • Path Parameter:

    • cb_model_id (string): The ID of the Test to delete.

  • Response:

    (Or a 404 if Test not found)

List Tests

  • GET /api/models

  • Description: Retrieves a list of all active Tests with summary information.

  • Response (Array of Test summaries):

Get Test Details

  • GET /api/model_details/{cb_model_id}

  • Description: Retrieves detailed information and performance metrics for a specific Test.

  • Path Parameter:

    • cb_model_id (string): The ID of the Test.

  • Response (example, structure may vary with details):

    (Or a 404 if Test not found)

Update Test (Report Rewards)

  • POST /api/update_model/{cb_model_id} (Protected)

  • Description: Updates a Test with new reward data. This is how the Test learns.

  • Path Parameter:

    • cb_model_id (string): The ID of the Test to update.

  • Request Body (UpdateModelRequest):

  • Response:

  • POST /api/fetch_recommended_variant (Protected)

  • Description: Fetches a recommended variant from the specified Test. Optionally stores context for the decision if request_id is provided.

  • Request Body (FetchActionRequest):

  • Response:

Rollout Global Variant

  • POST /api/rollout_global_variant/{cb_model_id} (Protected)

  • Description: Forces all future recommendations from this Test to be a specific variant, overriding the bandit logic.

  • Path Parameter:

    • cb_model_id (string): The ID of the Test.

  • Request Body (RolloutGlobalVariantRequest):

  • Response:

Clear Global Variant Rollout

  • POST /api/clear_global_variant/{cb_model_id} (Protected)

  • Description: Clears any active global variant rollout for the Test, returning it to normal bandit operation.

  • Path Parameter:

    • cb_model_id (string): The ID of the Test.

  • Response:

Log Streaming

Stream Logs

  • GET /logs/stream

  • Description: Streams application logs in real-time. This is a StreamingResponse.

  • Response Type: text/event-stream

  • Output: A stream of Server-Sent Events (SSE), where each event data is a JSON string representing a log entry. Example log entry structure:

    (Actual log format depends on the application's logging configuration.)

Metrics

Get Prometheus Metrics

  • GET /metrics

  • Description: Each backend worker exposes this endpoint to provide its application and Test metrics in the OpenMetrics format. In a multi-worker setup, a monitoring system like Prometheus should be configured to scrape each worker individually.

  • Response Type: application/openmetrics-text; version=1.0.0; charset=utf-8

  • Output: Standard Prometheus metrics exposition format, including:

    • HTTP request counts and latencies (http_requests_total, http_request_duration_seconds)

    • Test predictions, updates, and rewards (model_predictions_total, model_updates_total, model_rewards_total, model_reward histogram)

    • Redis operations (redis_operations_total, redis_operation_duration_seconds)

    • Active Test counts (active_models)

    • And more, as defined in metrics.py.

This API reference should provide a solid foundation for developers integrating with Scout.

Last updated