-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-openrouter-image.ts
More file actions
42 lines (36 loc) · 1.13 KB
/
Copy pathtest-openrouter-image.ts
File metadata and controls
42 lines (36 loc) · 1.13 KB
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
37
38
39
40
41
42
import "dotenv/config";
async function main() {
const apiKey = process.env.OPENROUTER_API_KEY;
if (!apiKey) {
console.error("No OPENROUTER_API_KEY found");
return;
}
console.log("Testing OpenRouter Image Generation...");
try {
const response = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
// model: "black-forest-labs/flux-schnell",
model: "openai/dall-e-3", // let's test if DALL-E 3 works on openrouter
messages: [
{
role: "user",
content: "A detailed portrait of a fantasy wizard with a long white beard and a blue hat.",
}
],
// this is how OpenRouter docs suggest requesting images
modalities: ["image"],
})
});
const data = await response.json();
console.log("Response Status:", response.status);
console.log("Response Data:", JSON.stringify(data, null, 2));
} catch (error) {
console.error("Error:", error);
}
}
main();