Email Classification API

POST Email Classification API

/api/v1/ai/email-classification

Automatically categorize incoming emails to route them to correct departments and detect urgency.

Request Body Parameters

Field Type Required Description
email_content string Required The main body of the email to classify (Max: 10,000 characters).
subject string Optional Optional email subject line. Providing this increases classification accuracy.
allowed_categories array of strings Optional Optional strict list of allowed categories (e.g., ["sales", "support", "billing"]). If provided, the AI will force the email into one of these buckets.
detect_urgency boolean Optional Optional. If true, the AI will evaluate the email and return an urgency level (low, medium, high, critical). Default is false.
extract_schema object Optional Optional schema definition (JSON object) of exact data points you want extracted from the email. Example: {"order_number":"string", "refund_amount":"number"}
custom_instructions string Optional Optional specific rules to guide the data extraction process.
model string Optional Optional AI model to use.

Example Request (Dynamic Routing)

In this example, we provide the allowed_categories array. The AI guarantees the category will match one of these options perfectly, allowing you to easily write if/else statements in your codebase.

JSON Request
{
  "subject": "Double charged on my last invoice!",
  "email_content": "Hello, I was looking at my bank statement and I was charged twice for my Pro subscription this month. Please refund one of the charges immediately as this is unacceptable.",
  "allowed_categories": ["sales", "support", "billing", "spam"],
  "detect_urgency": true
}
cURL
curl -X POST https://rsflowhub.com/api/v1/ai/email-classification \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "subject": "Double charged on my last invoice!",
    "email_content": "Hello, I was looking at my bank statement and I was charged twice for my Pro subscription this month. Please refund one of the charges immediately as this is unacceptable.",
    "allowed_categories": ["sales", "support", "billing", "spam"],
    "detect_urgency": true
  }'

Example Response

The API processes the email and outputs the category and urgency level.

JSON Response
{
  "success": true,
  "data": {
    "result": {
      "category": "billing",
      "confidence": 0.98,
      "urgency": "high"
    }
  },
  "meta": {
    "credits_used": 2,
    "credits_remaining": 997
  }
}

Advanced: Classification + Data Extraction

This endpoint allows you to simultaneously classify the email AND extract strictly typed data by providing an extract_schema. The credit cost will adjust automatically based on the length of the email and extracted data.

JSON Request
{
  "subject": "Cancel order #88492 immediately",
  "email_content": "I placed an order yesterday for the standard plan, but I changed my mind. Please cancel it and refund the $49.00 back to my card ending in 4421.",
  "allowed_categories": ["sales", "support", "billing"],
  "detect_urgency": true,
  "extract_schema": {
    "order_number": "string",
    "requested_action": "string",
    "refund_amount_cents": "integer",
    "card_last_four": "string"
  },
  "custom_instructions": "Convert all refund amounts into cents (e.g. 49.00 becomes 4900)."
}
JSON Response
{
  "success": true,
  "data": {
    "result": {
      "category": "billing",
      "confidence": 0.99,
      "urgency": "high",
      "extracted_data": {
        "order_number": "88492",
        "requested_action": "cancel and refund",
        "refund_amount_cents": 4900,
        "card_last_four": "4421"
      }
    }
  },
  "meta": {
    "credits_used": 3,
    "credits_remaining": 994
  }
}

API Request Example

Use the cURL snippet below to test the endpoint.

cURL
curl -X POST 'https://rsflowhub.com/api/v1/ai/email-classification' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "subject": "Help with password reset",
    "email_content": "I cannot login to my account. Please assist.",
    "allowed_categories": [
        "sales",
        "support",
        "billing"
    ],
    "detect_urgency": true
}'

Ready to build?

Create your free account and make your first API call in minutes.