Python SSE Client Example

This example shows how to call the Bitseek Chat SSE service using the official openai Python library.

Installation

pip install openai

Code Example

from openai import OpenAI

# 1. Initialize the client
# Point the base_url to the Bitseek Chat service address
# Use your authentication key for api_key
client = OpenAI(
    base_url="https://chat-proxy.bitseek.ai/v1",
    api_key="<API-KEY>"
)

# 2. Make a streaming request
# Set the stream parameter to True
stream = client.chat.completions.create(
    messages=[{"role": "user", "content": "Write a short poem about the starry sky"}],
    stream=True
)

# 3. Process the streaming response
# Iterate through the event stream and print the content
print("AI: ", end="")
for chunk in stream:
    content = chunk.choices[0].delta.content
    if content:
        print(content, end="", flush=True)

print()  # Newline at the end

Key Parameters

  • base_url: Set to https://chat-proxy.bitseek.ai/v1
  • api_key: Your valid API key for authentication
  • stream=True: Enables SSE streaming response

results matching ""

    No results matching ""