API Documentation
Learn how to integrate Earl Store AI API into your applications.
Base URL
Semua permintaan API menggunakan base URL berikut:
https://your-domain.comAuthentication
All API requests require authentication using a Bearer token. Include your API key in the Authorization header:
Authorization: Bearer YOUR_API_KEYEndpoints
Chat Completions
POST https://your-domain.com/api/v1/earl/chat/completions
Request Body
model(string, required) - The model ID to usemessages(array, required) - Array of message objectsstream(boolean, optional) - Enable streaming response
Example Request
curl -X POST https://your-domain.com/api/v1/earl/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "openai/gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"stream": false
}'Example Response
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1704067200,
"model": "openai/gpt-4o",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 10,
"total_tokens": 30
}
}Error Responses
Apabila permintaan gagal, API akan mengembalikan respons error dalam format berikut:
401 - Invalid API Key
{
"error": {
"message": "Invalid API key.",
"type": "authentication_error",
"code": "invalid_api_key"
}
}402 - Credits Exhausted
{
"error": {
"message": "Your credits are exhausted. Contact @earlxz on Telegram to top up.",
"type": "insufficient_quota",
"code": "insufficient_credits"
}
}500 - Server Error
{
"error": {
"message": "Server is experiencing issues. Please try again later.",
"type": "server_error",
"code": "internal_error"
}
}Handling Errors
Pastikan aplikasi anda menyemak status code dan handle error dengan betul. Contoh: jika dapat 402, paparkan mesej untuk top up kredit.
Code Examples
JavaScript / Node.js - Chat
// Base URL
const BASE_URL = 'https://your-domain.com';
// Text Generation
const response = await fetch(`${BASE_URL}/api/v1/earl/chat/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
model: 'openai/gpt-4o',
messages: [
{ role: 'user', content: 'Hello!' }
],
stream: false
})
});
const data = await response.json();
console.log(data.choices[0].message.content);JavaScript / Node.js - Image
// Base URL
const BASE_URL = 'https://your-domain.com';
// Image Generation
const response = await fetch(`${BASE_URL}/api/v1/earl/images/generations`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_API_KEY'
},
body: JSON.stringify({
model: 'stable-diffusion-v1-5/stable-diffusion-v1-5',
prompt: 'A beautiful sunset over mountains'
})
});
const data = await response.json();
// data.data[0].url contains the proxy image URL
console.log(data.data[0].url);
// Display image in HTML
// document.getElementById('image').src = data.data[0].url;