//native
type Replicate = {
token: string;
};
/**
* Create a prediction using a deployment
* Create a prediction for the deployment and inputs you provide.
*/
export async function main(
auth: Replicate,
deployment_owner: string,
deployment_name: string,
body: {
input: {};
stream?: false | true;
webhook?: string;
webhook_events_filter?: "start" | "output" | "logs" | "completed"[];
},
Prefer?: string,
) {
const url = new URL(
`https://api.replicate.com/v1/deployments/${deployment_owner}/${deployment_name}/predictions`,
);
const response = await fetch(url, {
method: "POST",
headers: {
...(Prefer ? { Prefer: Prefer } : {}),
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
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