-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
29 lines (26 loc) · 972 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { NextApiRequest, NextApiResponse } from 'next'
import { Prediction } from '../../../types/prediction'
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<Prediction | { detail: string }>,
) {
const response = await fetch('https://api.replicate.com/v1/predictions', {
method: 'POST',
headers: {
Authorization: `Token ${process.env.REPLICATE_API_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
// Pinned to a specific version of Stable Diffusion
// See https://replicate.com/stability-ai/stable-diffusion/versions
version: '6359a0cab3ca6e4d3320c33d79096161208e9024d174b2311e5a21b6c7e1131c',
input: { prompt: req.body.prompt },
}),
})
if (response.status !== 201) {
const error = await response.json()
res.status(500).json({ detail: error.detail })
}
const prediction = await response.json()
res.status(201).json(prediction)
}