const generate = async (tool, input) => {
const response = await fetch('https://api.artificialstudio.ai/api/run', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'YOUR_API_KEY'
},
body: JSON.stringify({ tool, input })
});
if (!response.ok) {
const error = await response.json();
switch (response.status) {
case 401:
throw new Error('Invalid API key');
case 402:
throw new Error('Insufficient credits');
case 429:
throw new Error('Rate limit exceeded. Retry later.');
default:
throw new Error(error.message || 'Request failed');
}
}
return response.json();
};