Complete guide to integrating ConstantSense AI into your application.
The ConstantSense AI API is a RESTful API that provides AI model inference capabilities. All requests require authentication via JWT tokens.
https://api.constantsolutions.ai
First, obtain an API token:
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
}
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"
}
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:
text (string, required): Input text for inferencereturn_features (boolean, optional): Return feature vectorsreturn_attention (boolean, optional): Return attention weightsResponse:
{
"prediction": 1,
"confidence": 0.9543,
"logits": [0.234, 2.876],
"features": null,
"processing_time_ms": 42.3,
"tokens_used": 12
}
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:
texts (array, required): List of input texts (max 100)return_features (boolean, optional): Return feature vectorsResponse:
{
"predictions": [1, 0, 1],
"confidences": [0.95, 0.88, 0.76],
"processing_time_ms": 125.7,
"tokens_used": 36
}
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": [...]
}
The API uses standard HTTP status codes:
200 - Success400 - Bad Request (invalid parameters)401 - Unauthorized (invalid/expired token)402 - Payment Required (quota exceeded)429 - Too Many Requests (rate limit exceeded)500 - Internal Server ErrorError Response:
{
"detail": "Quota exceeded. Please upgrade your plan."
}
| Tier | Requests/min | Tokens/month |
|---|---|---|
| Free | 10 | 10,000 |
| Basic | 60 | 100,000 |
| Premium | 300 | 1,000,000 |
| Enterprise | Custom | Unlimited |
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)
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);
Need help? Contact us: