Skip to main content

Introduction

The Inference API is a FastAPI-based service that provides credit risk prediction capabilities using a deep learning model. The API predicts whether a customer’s credit risk is “good” or “bad” based on various customer attributes.

Base URL

http://localhost:8000

API Information

title
string
Credit Score Prediction API
version
string
1.0.0
description
string
API to predict the credit risk of a customer using a deep learning model

Authentication

Currently, the API does not require authentication. It is configured with CORS middleware to allow requests from any origin (*).
In production environments, you should limit the allowed origins to specific trusted domains for security.

CORS Configuration

The API is configured with the following CORS settings:
  • Allow Origins: * (all origins)
  • Allow Credentials: true
  • Allow Methods: * (all methods)
  • Allow Headers: * (all headers)

Architecture

The API uses a singleton pattern for model inference, ensuring efficient resource usage:
  1. Model Loading: The deep learning model is loaded once at startup from model_weights_001.pth
  2. Preprocessor: A scikit-learn preprocessor (preprocessor.joblib) handles feature engineering
  3. Configuration: Model architecture is defined in model_config_001.yaml
  4. Inference Engine: PyTorch-based neural network runs on CPU for predictions

Interactive Documentation

FastAPI automatically generates interactive API documentation:
  • Swagger UI: Available at /docs
  • ReDoc: Available at /redoc
  • Root Endpoint: Redirects to /docs

Client Examples

import requests

base_url = "http://localhost:8000"

# Make a prediction request
payload = {
    "Age": 35,
    "Sex": "male",
    "Job": "unskilled and resident",
    "Housing": "free",
    "Saving accounts": "NA",
    "Checking account": "NA",
    "Credit amount": 9055,
    "Duration": 36,
    "Purpose": "education"
}

response = requests.post(
    f"{base_url}/credit_score_prediction",
    json=payload
)

result = response.json()
print(f"Prediction: {result['prediction']}")
print(f"Probability: {result['probability']}")

Error Handling

The API returns standard HTTP status codes:
  • 200: Successful prediction
  • 422: Validation error (invalid input data)
  • 500: Internal server error during inference

Running the Server

Start the API server using uvicorn:
uvicorn server.api:app --reload --port 8000
Or with uv:
uv run uvicorn server.api:app --reload --port 8000

Next Steps

Credit Score Prediction

Learn about the prediction endpoint

API Schema

View complete request/response schemas

Build docs developers (and LLMs) love