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.
GET /spam_email_classifier?email=Congratulations%20you%20won%20a%20prize
A successful request returns the model prediction and its probability array.
{
"prediction": 1,
"probabilities": [0.0812, 0.9188]
}Endpoint
/spam_email_classifierThe 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
https://spam-email-classifier.p.rapidapi.com/spam_email_classifierConsumers 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
- Read the
emailquery parameter. - Transform the text with
tfidf.transform([email]). - Generate the class with
logistic.predict(x). - Generate probability values with
logistic.predict_proba(x). - 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.
| Header | Required | Value |
|---|---|---|
X-RapidAPI-Key | Yes | The subscriber's own RapidAPI application key. |
X-RapidAPI-Host | Yes | spam-email-classifier.p.rapidapi.com |
Users should obtain their key from RapidAPI after subscribing. SafeMail documentation never publishes a shared consumer key.
Parameters
| Name | Location | Type | Required | Description |
|---|---|---|---|---|
email | Query string | string | Yes | The 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.
Response
Successful requests return a JSON object with two fields.
| Field | Type | Description |
|---|---|---|
prediction | integer | The class returned by logistic.predict(). |
probabilities | array[number] | The probability values returned by logistic.predict_proba(), converted to a JSON array. |
{
"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.
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.
{
"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 --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
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
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);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.