Last active
December 30, 2022 18:38
-
-
Save JenniferFuBook/e46d3785bb6d0141589418c207bb5b9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { NextApiRequest, NextApiResponse } from 'next' | |
import { Configuration, OpenAIApi, ImagesResponseDataInner } from 'openai'; | |
const configuration = new Configuration({ | |
apiKey: process.env.OPENAI_API_KEY, | |
}); | |
const openai = new OpenAIApi(configuration); | |
type Data = { | |
result: ImagesResponseDataInner[], | |
} | |
export default async function handler( | |
req: NextApiRequest, | |
res: NextApiResponse<Data> | |
) { | |
const {prompt, n, size} = req.body; | |
const result = await openai.createImage({ | |
prompt, | |
n, | |
size, | |
}); | |
res.status(200).json({ result: result.data.data }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment