Skip to content

Instantly share code, notes, and snippets.

@JenniferFuBook
Last active December 30, 2022 18:38
Show Gist options
  • Save JenniferFuBook/e46d3785bb6d0141589418c207bb5b9b to your computer and use it in GitHub Desktop.
Save JenniferFuBook/e46d3785bb6d0141589418c207bb5b9b to your computer and use it in GitHub Desktop.
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