Skip to content

API_QUICKSTART

Nick edited this page Mar 10, 2026 · 1 revision

PATAS API Quickstart

Quick start in 5 minutes


Base URL

http://localhost:8000/api/v1

For production deployments, replace with your PATAS server URL.


Main Endpoint: /api/v1/analyze

The /api/v1/analyze endpoint bundles the complete workflow:

  1. Ingest messages
  2. Run pattern mining (optional)
  3. Evaluate rules (optional)
  4. Export rules (optional)

Perfect for: Small-medium batch analysis, RapidAPI integration, quick prototyping.

Basic Example

Request:

POST /api/v1/analyze
Content-Type: application/json

{
  "messages": [
    {
      "id": "msg_001",
      "text": "Buy now! http://spam.com",
      "is_spam": true
    }
  ],
  "run_mining": true
}

Response:

{
  "patterns": [
    {
      "id": 1,
      "type": "url",
      "description": "URL pattern: http://spam.com",
      "group_size": 2,
      "similarity_reason": "Messages contain the same suspicious URL: http://spam.com",
      "sql_query": "SELECT id FROM reports WHERE message_content LIKE '%http://spam.com%'"
    }
  ],
  "rules": [...],
  "meta": {
    "ingested_count": 1,
    "patterns_created": 1,
    "timings": {...}
  }
}

Code Examples

Python

import requests

response = requests.post(
    'http://localhost:8000/api/v1/analyze',
    json={
        'messages': [
            {
                'id': 'msg_001',
                'text': 'Buy now! http://spam.com',
                'is_spam': True
            }
        ],
        'run_mining': True,
        'run_evaluation': True,
        'export_backend': 'sql'
    }
)

result = response.json()
print(f"Discovered {len(result['patterns'])} patterns")

# Access SQL queries
for pattern in result['patterns']:
    print(f"SQL: {pattern['sql_query']}")

cURL

curl -X POST http://localhost:8000/api/v1/analyze \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"id": "1", "text": "Buy now! http://spam.com", "is_spam": true}
    ],
    "run_mining": true
  }'

JavaScript

const response = await fetch('http://localhost:8000/api/v1/analyze', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    messages: [
      { id: '1', text: 'Buy now! http://spam.com', is_spam: true }
    ],
    run_mining: true
  })
});

const result = await response.json();
console.log(`Discovered ${result.patterns.length} patterns`);

Pattern Groups and SQL Output

Each pattern in the response includes:

  • group_size: Number of messages in this pattern group
  • sources_count: Number of unique sources
  • senders_count: Number of unique senders
  • similarity_reason: Explanation of why messages are similar
  • sql_query: SQL query for blocking

Example SQL query:

SELECT id, message_content, sender, source 
FROM reports 
WHERE LOWER(message_content) LIKE '%http://spam.com%'

This query can be used to:

  • Identify all messages matching the pattern
  • Apply blocking rules in your system
  • Generate reports

Lower-Level Endpoints

For large datasets, use lower-level endpoints:

  1. Ingest: POST /api/v1/messages/ingest
  2. Mine: POST /api/v1/patterns/mine
  3. Evaluate: POST /api/v1/rules/eval-shadow
  4. Promote: POST /api/v1/rules/promote
  5. Export: GET /api/v1/rules/export

See API Reference for details.


Error Handling

try:
    response = requests.post('http://localhost:8000/api/v1/analyze', json=data)
    response.raise_for_status()
    result = response.json()
except requests.exceptions.HTTPError as e:
    error_detail = e.response.json().get("detail", "Unknown error")
    print(f"Error: {error_detail}")

Next Steps

Clone this wiki locally