//native
type Recraft = {
apiKey: string;
};
/**
* Create Style
*
*/
export async function main(
auth: Recraft,
body: {
images: string[];
private?: false | true;
style:
| "digital_illustration"
| "icon"
| "realistic_image"
| "vector_illustration";
},
) {
const url = new URL(`https://external.api.recraft.ai/v1/styles`);
const formData = new FormData();
for (const [k, v] of Object.entries(body)) {
if (v !== undefined) {
formData.append(k, String(v));
}
}
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: "Bearer " + auth.apiKey,
},
body: formData,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago