BazaarLinkBazaarLink
เข้าสู่ระบบ
เอกสารAPI ข้อมูลอ้างอิงSDK ข้อมูลอ้างอิงการใช้งาน AgentAI ทักษะ
สารบัญ

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

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 | BazaarLink