Thia Aide For Developers
Thia Aide API Documentation
Integrate AI-powered chat into your applications with our simple REST API
API Overview
Base URL
https://thiaide.com/api/
Version: 1.0
Format: JSON
Authentication: API Key in request body
Authentication
All requests require an API key sent in the request body. You can obtain an API key from your Thia Aide dashboard.
Note: Never expose your API key in client-side code. Always make requests from your backend server.
Endpoints
Send Message
POST /api/
Sends a message to the AI and receives a response.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| api_key | string | Required | Your API key |
| prompt | string | Required | The message/question for the AI |
| timestamp | integer | Required | Current Unix timestamp |
| temperature | float | Optional | Controls randomness (0-1, default: 0.7) |
| max_tokens | integer | Optional | Maximum response length (default: 500) |
| language | string | Optional | Response language (en, bg, etc.) |
Response Format
Success Response (200 OK)
{
"response": "This is the AI-generated response...",
"tokens_used": 150,
"client_info": {
"api_usage": {
"tokens": 150,
"calls": 1
}
}
}
Error Response
{
"error": "Invalid API key"
}
or
{
"error": {
"message": "API key not found",
"code": 401
}
}
Check API Status
GET /api/status
Check if the API is online and responding.
Response
{
"status": "online",
"timestamp": 1700000000
}
⚠️ HTTP Status Codes
| Code | Description |
|---|---|
| 200 | Success – Request processed successfully |
| 400 | Bad Request – Missing required parameters |
| 401 | Unauthorized – Invalid API key |
| 429 | Too Many Requests – Rate limit exceeded |
| 500 | Internal Server Error – Server-side issue |
Code Examples
PHP (WordPress)
<?php
// Send message using WordPress HTTP API
function ask_thiaide($prompt) {
$api_url = 'https://thiaide.com/api/';
$api_key = 'your_api_key_here';
$response = wp_remote_post($api_url, array(
'headers' => array(
'Content-Type' => 'application/json',
'User-Agent' => 'Your-Plugin/1.0'
),
'body' => json_encode(array(
'api_key' => $api_key,
'prompt' => $prompt,
'timestamp' => time()
)),
'timeout' => 130,
'sslverify' => true
));
if (is_wp_error($response)) {
return array(
'success' => false,
'error' => $response->get_error_message()
);
}
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if (isset($data['error'])) {
return array(
'success' => false,
'error' => $data['error']
);
}
return array(
'success' => true,
'text' => $data['response'],
'tokens' => $data['tokens_used'] ?? 0
);
}
// Usage
$result = ask_thiaide('What is WordPress?');
if ($result['success']) {
echo $result['text'];
} else {
echo 'Error: ' . $result['error'];
}
?>
PHP (Plain)
<?php
// Send message using cURL
function ask_thiaide($prompt) {
$api_url = 'https://thiaide.com/api/';
$api_key = 'your_api_key_here';
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'User-Agent: Your-App/1.0'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
'api_key' => $api_key,
'prompt' => $prompt,
'timestamp' => time()
)));
curl_setopt($ch, CURLOPT_TIMEOUT, 130);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code !== 200) {
return array(
'success' => false,
'error' => "HTTP Error: $http_code"
);
}
$data = json_decode($response, true);
return array(
'success' => true,
'text' => $data['response']
);
}
// Usage
$result = ask_thiaide('Hello AI!');
print_r($result);
?>
JavaScript
// Send message using Fetch API
async function askThiaide(prompt) {
const apiUrl = 'https://thiaide.com/api/';
const apiKey = 'your_api_key_here';
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'Your-App/1.0'
},
body: JSON.stringify({
api_key: apiKey,
prompt: prompt,
timestamp: Math.floor(Date.now() / 1000)
})
});
const data = await response.json();
if (data.error) {
throw new Error(data.error);
}
return {
success: true,
text: data.response,
tokens: data.tokens_used
};
} catch (error) {
return {
success: false,
error: error.message
};
}
}
// Usage
askThiaide('What is JavaScript?').then(result => {
if (result.success) {
console.log('AI says:', result.text);
} else {
console.error('Error:', result.error);
}
});
Python
import requests
import time
def ask_thiaide(prompt):
api_url = 'https://thiaide.com/api/'
api_key = 'your_api_key_here'
payload = {
'api_key': api_key,
'prompt': prompt,
'timestamp': int(time.time())
}
headers = {
'Content-Type': 'application/json',
'User-Agent': 'Your-App/1.0'
}
try:
response = requests.post(api_url, json=payload, headers=headers, timeout=130)
response.raise_for_status()
data = response.json()
if 'error' in data:
return {'success': False, 'error': data['error']}
return {
'success': True,
'text': data['response'],
'tokens': data.get('tokens_used', 0)
}
except requests.exceptions.RequestException as e:
return {'success': False, 'error': str(e)}
# Usage
result = ask_thiaide('Write a haiku about coding')
if result['success']:
print(result['text'])
else:
print(f"Error: {result['error']}")
cURL
# Send message using cURL
curl -X POST https://thiaide.com/api/ \
-H "Content-Type: application/json" \
-H "User-Agent: Your-App/1.0" \
-d '{
"api_key": "your_api_key_here",
"prompt": "Tell me a joke",
"timestamp": '"$(date +%s)"'
}'
# Check API status
curl https://thiaide.com/api/status
✅ Best Practices
DO:
- Always validate API responses
- Implement proper error handling
- Cache responses when appropriate
- Use timeout values (130s recommended)
- Store API keys securely (never in client-side code)
DON’T:
- Hardcode API keys in JavaScript
- Ignore rate limits
- Send sensitive personal information
- Make requests without proper error handling
Error Handling Examples
function safe_thiaide_request($prompt) {
try {
$response = wp_remote_post('https://thiaide.com/api/', [
'timeout' => 130,
'body' => json_encode([
'api_key' => getenv('THIAIDE_API_KEY'),
'prompt' => $prompt,
'timestamp' => time()
])
]);
if (is_wp_error($response)) {
throw new Exception($response->get_error_message());
}
$code = wp_remote_retrieve_response_code($response);
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
switch ($code) {
case 200:
return $data['response'];
case 401:
throw new Exception('Invalid API key');
case 429:
throw new Exception('Rate limit exceeded. Try again later.');
default:
throw new Exception("API Error: " . ($data['error'] ?? 'Unknown error'));
}
} catch (Exception $e) {
error_log('Thiaide API Error: ' . $e->getMessage());
return 'Sorry, I encountered an error. Please try again.';
}
}

