跳转到内容

Node.js SDK

此内容尚不支持你的语言。

HiAPI is fully compatible with the OpenAI Node.js SDK. Just change the baseURL.

Terminal window
npm install openai
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://api.hiapi.ai/v1"
});
const response = await client.images.generate({
model: "dall-e-3",
prompt: "a futuristic city at sunset",
size: "1024x1024"
});
console.log(response.data[0].url);
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }]
});
console.log(response.choices[0].message.content);

For video and audio endpoints not covered by the OpenAI SDK, use fetch:

const response = await fetch("https://api.hiapi.ai/v1/videos", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "wan2.7-t2v",
prompt: "sunset timelapse over mountains",
seconds: 5
})
});
const data = await response.json();
console.log(data);