@arkane_absolute/sdk
Version:
Arkane SDK for interacting with Arkane API
36 lines (35 loc) • 1.22 kB
JavaScript
import axios from "axios";
export class ArkaneSDK {
constructor(options) {
if (!options.apiKey) {
throw new Error("API key is required");
}
this.apiUrl = options.apiUrl ?? "http://localhost:8080";
this.apiKey = options.apiKey;
this.timeoutMs = options.timeoutMs ?? 10000;
}
async predict(data) {
try {
// Прямой вызов axios.post без создания экземпляра axios
const response = await axios.post(`${this.apiUrl}/predict`, data, {
headers: {
"Content-Type": "application/json",
"x-api-key": this.apiKey,
},
timeout: this.timeoutMs,
});
return response.data;
}
catch (error) {
if (error.response) {
throw new Error(`API Error: ${error.response.status} - ${error.response.data}`);
}
else if (error.request) {
throw new Error("No response received from server.");
}
else {
throw new Error(`Request setup error: ${error.message}`);
}
}
}
}