API Overview

The ChatTask API provides programmatic access to our data science and analytics platform. You can use the API to:

  • Run statistical analysis and machine learning models
  • Access predictive analytics tools
  • Integrate ChatTask's capabilities into your applications
  • Automate data processing workflows

Authentication

All API requests require authentication using an API key. Include your API key in the request headers:

HTTP Header
X-API-Key: your_api_key_here

You can obtain your API key from your ChatTask dashboard under API Settings.

Base URL

All API requests should be made to:

https://api.chattask.ai

Health Check

GET /health

Check if the API is running and accessible. This endpoint returns information about the server status, available tools, and system configuration.

Example Response
{
  "status": "healthy",
  "version": "1.2.0",
  "timestamp": 1674656789.123,
  "available_tools": 5,
  "discovered_tools": [
    "linear_regression",
    "ridge_regression",
    "lasso_regression",
    "t_test",
    "arima"
  ]
}

Run Analysis Tools

POST /tools/run

Execute statistical analysis and machine learning models. For long-running analyses, include "pollResponse": true to get an immediate response with a processing ID that you can check later.

Example Request
{
  "taskList": {
    "inputs": {
      "name": "linear_regression",
      "processing_id": "unique_id_123",
      "dataset": [
        {"sales": 100, "marketing": 50, "price": 25},
        {"sales": 150, "marketing": 75, "price": 30},
        {"sales": 120, "marketing": 60, "price": 28}
      ],
      "target": "sales",
      "features": ["marketing", "price"],
      "userContext": {
        "company": "Your Company",
        "objective": "Analyze sales drivers"
      }
    }
  },
  "pollResponse": true  // Optional: for async processing
}
Example Response
{
  "processing_id": "unique_id_123",
  "status": "success",
  "elapsed_secs": 2.34,
  "result": {
    "model_type": "linear_regression",
    "performance": {
      "r_squared": 0.85,
      "mse": 123.45
    },
    "coefficients": {
      "marketing": 1.23,
      "price": 0.78
    },
    "insights": [
      "Marketing spend has a strong positive correlation with sales",
      "Price shows moderate positive correlation with sales"
    ]
  }
}

List Available Tools

GET /tools

Retrieve a list of all available analysis tools along with their descriptions and schemas.

Example Response
[
  {
    "name": "linear_regression",
    "description": "Statistical analysis tool: linear_regression",
    "version": "1.0.0",
    "input_schema": {
      "type": "object",
      "properties": {
        "taskList": {
          "type": "object",
          "required": ["inputs"]
        }
      }
    }
  },
  {
    "name": "t_test",
    "description": "Statistical analysis tool: t_test",
    "version": "1.0.0"
  }
  // ... more tools
]

Get Tool Schema

GET /tools/{tool_name}/schema

Get detailed schema information for a specific tool, including input requirements and example data.

Example Response
{
  "name": "linear_regression",
  "description": "Perform linear regression analysis on your data",
  "version": "1.0.0",
  "input_schema": {
    "type": "object",
    "properties": {
      "taskList": {
        "type": "object",
        "properties": {
          "inputs": {
            "type": "object",
            "required": ["name", "dataset", "target", "features"]
          }
        }
      }
    }
  },
  "example_input": {
    "taskList": {
      "inputs": {
        "name": "linear_regression",
        "dataset": [{"x": 1, "y": 2}, {"x": 2, "y": 4}],
        "target": "y",
        "features": ["x"]
      }
    }
  }
}

Check Job Status

GET /tools/status/{processing_id}

Check the status and retrieve results for a previously submitted analysis job. Useful for long-running analyses.

Query Parameters
  • statusOnly (optional) - If true, returns only status without the full result payload
Example Response
{
  "processing_id": "unique_id_123",
  "status": "success",
  "elapsed_secs": 2.34,
  "result": {
    // Full analysis results (same as /tools/run response)
  }
}

Available Analysis Tools

ChatTask provides a comprehensive suite of statistical and machine learning tools:

Statistical Analysis

  • linear_regression - Linear regression analysis for understanding relationships between variables
  • lasso_regression - Lasso regression with L1 regularization for feature selection
  • ridge_regression - Ridge regression with L2 regularization to handle multicollinearity
  • t_test - Student's t-test for hypothesis testing and comparing means

Time Series Analysis

  • arima - ARIMA (AutoRegressive Integrated Moving Average) for time series forecasting

Async Processing

For long-running analyses, you can use async processing by including "pollResponse": true in your request. This will immediately return a processing ID that you can use to check the status later.

Error Handling

The API uses standard HTTP status codes to indicate success or failure:

  • 200 OK - Request successful
  • 400 Bad Request - Invalid request parameters or unknown tool
  • 401 Unauthorized - Invalid or missing API key
  • 403 Forbidden - API key lacks permission for requested tool
  • 404 Not Found - Resource not found (e.g., processing ID)
  • 429 Too Many Requests - Rate limit exceeded
  • 500 Internal Server Error - Server error
  • 503 Service Unavailable - Service temporarily unavailable
Error Response Format
{
  "error": {
    "code": "INVALID_REQUEST",
    "message": "Missing required parameter: dataset",
    "details": {
      "parameter": "dataset",
      "expected": "array"
    }
  }
}

Code Examples

Python Example

Python
import requests
import json

# Configuration
API_KEY = "your_api_key_here"
BASE_URL = "https://api.chattask.ai"

headers = {
    "X-API-Key": API_KEY,
    "Content-Type": "application/json"
}

# Run linear regression analysis
data = {
    "taskList": {
        "inputs": {
            "name": "linear_regression",
            "processing_id": "python_example_123",
            "dataset": [
                {"sales": 100, "marketing": 50, "price": 25},
                {"sales": 150, "marketing": 75, "price": 30},
                {"sales": 120, "marketing": 60, "price": 28}
            ],
            "target": "sales",
            "features": ["marketing", "price"],
            "userContext": {
                "company": "Python Corp",
                "objective": "Analyze sales drivers"
            }
        }
    }
}

response = requests.post(f"{BASE_URL}/tools/run", 
                        headers=headers, 
                        json=data)

if response.status_code == 200:
    result = response.json()
    print("Analysis completed successfully!")
    print(f"R-squared: {result['result']['performance']['r_squared']}")
else:
    print(f"Error: {response.status_code} - {response.text}")

JavaScript Example

JavaScript
const API_KEY = 'your_api_key_here';
const BASE_URL = 'https://api.chattask.ai';

async function runAnalysis() {
    const data = {
        taskList: {
            inputs: {
                name: "linear_regression",
                processing_id: "js_example_123",
                dataset: [
                    {sales: 100, marketing: 50, price: 25},
                    {sales: 150, marketing: 75, price: 30},
                    {sales: 120, marketing: 60, price: 28}
                ],
                target: "sales",
                features: ["marketing", "price"],
                userContext: {
                    company: "JavaScript Corp",
                    objective: "Analyze sales performance"
                }
            }
        }
    };

    try {
        const response = await fetch(`${BASE_URL}/tools/run`, {
            method: 'POST',
            headers: {
                'X-API-Key': API_KEY,
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(data)
        });

        if (response.ok) {
            const result = await response.json();
            console.log('Analysis completed!');
            console.log('R-squared:', result.result.performance.r_squared);
        } else {
            console.error('Error:', response.status, await response.text());
        }
    } catch (error) {
        console.error('Request failed:', error);
    }
}

runAnalysis();