Appearance
JavaScript Example — Manual API Call
This example shows how to call the Chat API from your website or backend using JavaScript.
Using Fetch
javascript
const payload = {
user_id: "user123",
session_id: "sess_001",
message: "Hi, I need help",
metadata: {
channel: "custom_integration",
source: "myapp.com"
}
};
async function callChatAPI() {
const res = await fetch("https://api.petameta.com/api/v1/chat", {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": "YOUR_ADMIN_API_KEY"
},
body: JSON.stringify(payload)
});
const data = await res.json();
console.log("AI Response:", data);
}
callChatAPI();Using Node.js (Axios)
javascript
import axios from "axios";
axios.post("https://api.petameta.com/api/v1/chat", payload, {
headers: {
"X-API-Key": process.env.PETAMETA_API_KEY
}
}).then(res => {
console.log(res.data);
}).catch(err => {
console.error(err.response?.data || err);
});