⚠️ Developer Preview
This API is experimental. Endpoints, response formats, and rate limits may change. Not recommended for production use yet.

API Documentation

Complete guide to integrating ConstantSense AI into your application.

Getting Started

The ConstantSense AI API is a RESTful API that provides AI model inference capabilities. All requests require authentication via JWT tokens.

Base URL

https://api.constantsolutions.ai

Authentication

First, obtain an API token:

POST /auth
curl -X POST https://api.constantsolutions.ai/auth \
  -H "Content-Type: application/json" \
  -d '{
    "api_key": "YOUR_API_KEY"
  }'

Response:

{
  "access_token": "eyJhbGciOiJIUzI1NiIs...",
  "token_type": "bearer",
  "expires_in": 86400
}

Endpoints

1. Health Check

GET /health

Check API service status.

curl https://api.constantsolutions.ai/health

Response:

{
  "status": "healthy",
  "model_loaded": true,
  "device": "cuda",
  "version": "1.0.0",
  "timestamp": "2025-12-30T12:00:00Z"
}

2. Single Prediction

POST /predict

Run inference on a single text input.

curl -X POST https://api.constantsolutions.ai/predict \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "This is an amazing product!",
    "return_features": false,
    "return_attention": false
  }'

Request Parameters:

Response:

{
  "prediction": 1,
  "confidence": 0.9543,
  "logits": [0.234, 2.876],
  "features": null,
  "processing_time_ms": 42.3,
  "tokens_used": 12
}

3. Batch Prediction

POST /predict/batch

Run inference on multiple texts simultaneously.

curl -X POST https://api.constantsolutions.ai/predict/batch \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "texts": [
      "This is great!",
      "This is terrible.",
      "Pretty good overall."
    ],
    "return_features": false
  }'

Request Parameters:

Response:

{
  "predictions": [1, 0, 1],
  "confidences": [0.95, 0.88, 0.76],
  "processing_time_ms": 125.7,
  "tokens_used": 36
}

4. Usage Statistics

GET /usage

Get your API usage statistics.

curl https://api.constantsolutions.ai/usage \
  -H "Authorization: Bearer YOUR_TOKEN"

Response:

{
  "user_id": "user_123",
  "month": "2025-12",
  "tokens_used": 45230,
  "requests": 1523,
  "total_cost": 4.52,
  "recent_usage": [...]
}

Error Handling

The API uses standard HTTP status codes:

Error Response:

{
  "detail": "Quota exceeded. Please upgrade your plan."
}

Rate Limits

Tier Requests/min Tokens/month
Free 10 10,000
Basic 60 100,000
Premium 300 1,000,000
Enterprise Custom Unlimited

SDKs and Libraries

Python

import requests

class ConstantSenseClient:
    def __init__(self, api_key):
        self.base_url = "https://api.constantsolutions.ai"
        self.token = self._authenticate(api_key)
    
    def _authenticate(self, api_key):
        response = requests.post(
            f"{self.base_url}/auth",
            json={"api_key": api_key}
        )
        return response.json()["access_token"]
    
    def predict(self, text):
        response = requests.post(
            f"{self.base_url}/predict",
            headers={"Authorization": f"Bearer {self.token}"},
            json={"text": text}
        )
        return response.json()

# Usage
client = ConstantSenseClient("your-api-key")
result = client.predict("This is amazing!")
print(result)

JavaScript/Node.js

const axios = require('axios');

class ConstantSenseClient {
    constructor(apiKey) {
        this.baseUrl = 'https://api.constantsolutions.ai';
        this.authenticate(apiKey);
    }
    
    async authenticate(apiKey) {
        const response = await axios.post(`${this.baseUrl}/auth`, {
            api_key: apiKey
        });
        this.token = response.data.access_token;
    }
    
    async predict(text) {
        const response = await axios.post(
            `${this.baseUrl}/predict`,
            { text },
            { headers: { Authorization: `Bearer ${this.token}` } }
        );
        return response.data;
    }
}

// Usage
const client = new ConstantSenseClient('your-api-key');
const result = await client.predict('This is amazing!');
console.log(result);

Support

Need help? Contact us:

Contact Support Back to Home