MCPcopy
hub / github.com/Anil-matcha/Open-Generative-AI / submitAndPoll

Function submitAndPoll

packages/studio/src/muapi.js:42–61  ·  view source on GitHub ↗
(endpoint, payload, key, onRequestId, maxAttempts = 60)

Source from the content-addressed store, hash-verified

40}
41
42async function submitAndPoll(endpoint, payload, key, onRequestId, maxAttempts = 60) {
43 const url = `${BASE_URL}/api/v1/${endpoint}`;
44 const response = await fetch(url, {
45 method: 'POST',
46 headers: { 'Content-Type': 'application/json', 'x-api-key': key },
47 body: JSON.stringify(payload)
48 });
49 if (!response.ok) {
50 const errText = await response.text();
51 notifyAuthRequired(response.status, errText);
52 throw new Error(`API Request Failed: ${response.status} ${response.statusText} - ${errText.slice(0, 100)}`);
53 }
54 const submitData = await response.json();
55 const requestId = submitData.request_id || submitData.id;
56 if (!requestId) return submitData;
57 if (onRequestId) onRequestId(requestId);
58 const result = await pollForResult(requestId, key, maxAttempts);
59 const outputUrl = result.outputs?.[0] || result.url || result.output?.url;
60 return { ...result, url: outputUrl };
61}
62
63export async function generateImage(apiKey, params) {
64 const modelInfo = getModelById(params.model);

Callers 11

generateImageFunction · 0.85
generateI2IFunction · 0.85
generateVideoFunction · 0.85
generateI2VFunction · 0.85
processV2VFunction · 0.85
processLipSyncFunction · 0.85
generateAudioFunction · 0.85
runClippingFunction · 0.85
runMotionGraphicsFunction · 0.85
runMotionGraphicsEditFunction · 0.85

Calls 3

notifyAuthRequiredFunction · 0.85
pollForResultFunction · 0.85
onRequestIdFunction · 0.50

Tested by

no test coverage detected