BazaarLinkBazaarLink
Đăng nhập
Tài liệuTham chiếu APITham chiếu SDKSử dụng AgentKỹ năng AI
Mục lục

TypeScript / Node.js Tích hợp

TypeScript / Node.js Tích hợp

Cài đặt

npm install openai

Sử dụng cơ bản

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 ?? "";
}

Streaming

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 ?? "");
}
Support
Hi! How can we help you?
Send a message and we'll get back to you soon.
TypeScript / Node.js Tích hợp | BazaarLink