BazaarLinkBazaarLink
登入
文件API 參考SDK 參考Agent 應用AI Skills
章節導覽

TypeScript / Node.js

TypeScript / Node.js

安裝

npm install openai

基本用法

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.bazaarlink.ai/v1",
  apiKey: process.env.BAZAARLINK_API_KEY,
});

async function chat(message: string): Promise<string> {
  const response = await client.chat.completions.create({
    model: "openai/gpt-4o",
    messages: [{ role: "user", content: message }],
  });
  return response.choices[0].message.content ?? "";
}

串流

const stream = await client.chat.completions.create({
  model: "openai/gpt-4o",
  messages: [{ role: "user", content: "Tell me a story" }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
客服
您好!有什麼可以協助?
請留下訊息,我們會盡快回覆。
TypeScript / Node.js | BazaarLink