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

Python

Python

Cài đặt

pip install openai

Đồng bộ

from openai import OpenAI

client = OpenAI(
    base_url="https://api.bazaarlink.ai/v1",
    api_key="sk-bl-YOUR_API_KEY",
)

response = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)

print(response.choices[0].message.content)

Bất đồng bộ

import asyncio
from openai import AsyncOpenAI

client = AsyncOpenAI(
    base_url="https://api.bazaarlink.ai/v1",
    api_key="sk-bl-YOUR_API_KEY",
)

async def main():
    response = await client.chat.completions.create(
        model="anthropic/claude-sonnet-4.6",
        messages=[{"role": "user", "content": "Hello async world!"}],
    )
    print(response.choices[0].message.content)

asyncio.run(main())

Streaming bất đồng bộ

async def stream_chat():
    stream = await client.chat.completions.create(
        model="deepseek/deepseek-chat",
        messages=[{"role": "user", "content": "Tell me a story"}],
        stream=True,
    )
    async for chunk in stream:
        content = chunk.choices[0].delta.content
        if content:
            print(content, end="", flush=True)

asyncio.run(stream_chat())
Support
Hi! How can we help you?
Send a message and we'll get back to you soon.
Python | BazaarLink