Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/picture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env -S npm run tsn -T
import OpenAI from 'openai';

// gets API Key from environment variable OPENAI_API_KEY
const openai = new OpenAI();

async function main() {
// Generate an image based on the prompt
const response = await openai.images.generate({
model: 'dall-e-3',
prompt: 'An astronaut lounging in a tropical resort in space, pixel art',
});
console.log(response); // Log the response to the console, a URL link to image will be in the response.data[0].url
if (response.data && response.data[0] && response.data[0].url) {
console.log('Image URL:', response.data[0].url); // Log the image URL
} else {
console.log('Image URL not found in response.');
}
}

main().catch(console.error);