API Documentation

SafeMail API

SafeMail exposes a focused HTTP endpoint for classifying email content. This reference matches the current FastAPI route and response structure.

Quick start

Send a GET request to /spam_email_classifier and provide the email text through the required email query parameter.

RequestHTTP
GET /spam_email_classifier?email=Congratulations%20you%20won%20a%20prize

A successful request returns the model prediction and its probability array.

200 OKJSON
{
  "prediction": 1,
  "probabilities": [0.0812, 0.9188]
}

Endpoint

GET/spam_email_classifier

The route receives one email message, converts it using the trained TF-IDF vectorizer, then evaluates the resulting vector with the saved logistic regression model.

Public gateway

GEThttps://spam-email-classifier.p.rapidapi.com/spam_email_classifier

Consumers should call the API through RapidAPI rather than the underlying hosting provider. RapidAPI handles subscriptions, API keys, quotas, and plan limits before forwarding approved requests to the classifier.

Processing flow

  1. Read the email query parameter.
  2. Transform the text with tfidf.transform([email]).
  3. Generate the class with logistic.predict(x).
  4. Generate probability values with logistic.predict_proba(x).
  5. Return both values as JSON.

Authentication

Requests made through RapidAPI require the consumer's RapidAPI application key. RapidAPI supplies the key and host values in its generated code snippets after the user subscribes to a plan.

HeaderRequiredValue
X-RapidAPI-KeyYesThe subscriber's own RapidAPI application key.
X-RapidAPI-HostYesspam-email-classifier.p.rapidapi.com

Users should obtain their key from RapidAPI after subscribing. SafeMail documentation never publishes a shared consumer key.

Parameters

NameLocationTypeRequiredDescription
emailQuery stringstringYesThe email text that should be classified.

Email content should be URL-encoded. Most HTTP libraries handle this automatically when query parameters are passed through their normal parameter APIs.

GET request size. SafeMail itself does not define a frontend character limit here. Practical URL length can still be limited by the browser, reverse proxy, CDN, host, or web server in front of the API.

Response

Successful requests return a JSON object with two fields.

FieldTypeDescription
predictionintegerThe class returned by logistic.predict().
probabilitiesarray[number]The probability values returned by logistic.predict_proba(), converted to a JSON array.
Example responseJSON
{
  "prediction": 0,
  "probabilities": [
    0.9674,
    0.0326
  ]
}

Interpreting the output

The website does not decide whether a message is spam. It simply displays the values returned by your trained model.

The probability array follows the classifier's internal class ordering. In scikit-learn this ordering is available through the model's classes_ attribute. If your project defines class 0 as legitimate and class 1 as spam, you can label those values accordingly in your client.

Important: a high probability is model confidence, not a guarantee that the classification is objectively correct. Real accuracy depends on the dataset, train/test split, preprocessing, class balance, and how similar new emails are to the training data.

Errors and validation

Missing email parameter

Because email is a required FastAPI query parameter, omitting it produces a validation error before the model is called.

422 Unprocessable EntityJSON
{
  "detail": [
    {
      "loc": ["query", "email"],
      "msg": "Field required",
      "type": "missing"
    }
  ]
}

Client-side handling

Production clients should handle non-200 responses, timeouts, unavailable servers, invalid JSON, and infrastructure-level request size limits instead of assuming every request succeeds.

Examples

Public requests are made through the RapidAPI Gateway at spam-email-classifier.p.rapidapi.com. Each consumer uses their own RapidAPI key.

cURL

cURL
curl --request GET \
  --url 'https://spam-email-classifier.p.rapidapi.com/spam_email_classifier?email=Congratulations%21%20You%20won%20a%20free%20prize.' \
  --header 'X-RapidAPI-Key: YOUR_RAPIDAPI_KEY' \
  --header 'X-RapidAPI-Host: spam-email-classifier.p.rapidapi.com'

Python

Python
import os
import requests

url = "https://spam-email-classifier.p.rapidapi.com/spam_email_classifier"
headers = {
    "X-RapidAPI-Key": os.environ["RAPIDAPI_KEY"],
    "X-RapidAPI-Host": "spam-email-classifier.p.rapidapi.com"
}
params = {
    "email": "Meeting tomorrow at 10 AM"
}

response = requests.get(
    url,
    headers=headers,
    params=params,
    timeout=10
)
response.raise_for_status()
result = response.json()

print(result["prediction"])
print(result["probabilities"])

Node.js

Node.js
const params = new URLSearchParams({
  email: "Meeting tomorrow at 10 AM"
});

const response = await fetch(
  `https://spam-email-classifier.p.rapidapi.com/spam_email_classifier?${params}`,
  {
    headers: {
      "X-RapidAPI-Key": process.env.RAPIDAPI_KEY,
      "X-RapidAPI-Host": "spam-email-classifier.p.rapidapi.com"
    }
  }
);

if (!response.ok) {
  throw new Error(`Request failed: ${response.status}`);
}

const result = await response.json();
console.log(result.prediction);
console.log(result.probabilities);
Keep API keys private. Do not hard-code a RapidAPI key into public frontend JavaScript. Server-side code should read the key from an environment variable or secret store.

Integration notes

URL encoding

Do not append raw email bodies directly to the URL. Email text can contain spaces, punctuation, line breaks, ampersands, question marks, and other characters with special meaning in a query string. Use your HTTP library's query-parameter support.

Class mapping

Document the meaning of each trained class in your application. The API returns the model's numeric class directly, so the user-facing labels should reflect the exact class mapping used during training.

Probability thresholds

You can use the returned probabilities to build your own decision threshold instead of relying only on the model's default predicted class. This can be useful when false positives are particularly expensive.

Model limitations

TF-IDF with logistic regression can work well for text classification, but performance on new mail depends heavily on the vocabulary and patterns represented in the training data. Re-evaluate the model on held-out or newly collected data before making strong accuracy claims on the public site.

Production usage

Use the RapidAPI Gateway URL in consumer integrations so subscriptions, quotas, and rate limits are enforced consistently. Applications should also use request timeouts, error handling, logging, and a clear fallback when the classifier cannot be reached.