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 datetime import datetime
import httpx
from openai import OpenAI
http_client = httpx.Client(
http2=False,
timeout=httpx.Timeout(60.0, connect=20.0),
trust_env=False,
)
client = OpenAI(
base_url="https://chat-proxy.bitseek.ai/v1",
api_key="<API-KEY>",
http_client=http_client,
)
conversation_id = f"conv-{int(datetime.now().timestamp())}"
stream = client.chat.completions.create(
model="bitseek-auto",
messages=[
{
"role": "user",
"content": "Hello, please introduce yourself, then call get_weather for Singapore.",
}
],
temperature=0.2,
tools=[
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather by city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}
],
extra_headers={
"Accept": "text/event-stream",
"X-Conversation-Id": conversation_id,
},
stream=True,
)
print("AI: ", end="")
for chunk in stream:
delta = chunk.choices[0].delta
if delta and delta.content:
print(delta.content, end="", flush=True)
print()
Key Parameters
base_url: Set tohttps://chat-proxy.bitseek.ai/v1api_key: Your valid API key for authenticationmodel: Usebitseek-autotemperature: Optional, normalized to0 ~ 2tools: Optional, OpenAI tool definitions for tool-call loopstream=True: Enables SSE streaming response