//native
type Togetherai = {
api_key: string;
};
/**
* Create image
* Use an image model to generate an image for a given prompt.
*/
export async function main(
auth: Togetherai,
body: {
prompt: string;
model: string;
steps?: number;
image_url?: string;
seed?: number;
n?: number;
height?: number;
width?: number;
negative_prompt?: string;
response_format?: "base64" | "url";
},
) {
const url = new URL(`https://api.together.xyz/v1/images/generations`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.api_key,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago