-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathopenai.ts
More file actions
36 lines (29 loc) · 1001 Bytes
/
openai.ts
File metadata and controls
36 lines (29 loc) · 1001 Bytes
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
30
31
32
33
34
35
36
import 'dotenv/config';
import {Langbase} from '../../../packages/langbase/src/langbase/langbase';
async function main() {
// Check if API keys are available
if (!process.env.LANGBASE_API_KEY) {
console.error('❌ LANGBASE_API_KEY is not set in environment variables');
return;
}
if (!process.env.OPENAI_API_KEY) {
console.error('❌ OPENAI_API_KEY is not set in environment variables');
console.log('Please add your OpenAI API key to the .env file');
return;
}
const langbase = new Langbase({
apiKey: process.env.LANGBASE_API_KEY!
});
try {
const result = await langbase.images.generate({
prompt: "A futuristic cityscape with flying cars and neon lights, cyberpunk style, highly detailed, 8k resolution",
model: "openai:gpt-image-1",
apiKey: process.env.OPENAI_API_KEY!
});
console.log('✅ Image generated successfully!');
console.log('Generated images:', result);
} catch (error) {
console.error('❌ Error generating image:', error);
}
}
main();