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
}
}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.output contains the proxy image URL
console.log(data.output);
// Display image in HTML
// document.getElementById('image').src = data.output;