跳到正文
老马Chat laomachat.com

Chat Completions

适合现有 OpenAI SDK、IDE 和传统 messages 对话。

历史由客户端管理每次请求都需在 messages 中发送所需历史,API 不会自动续接上一轮对话。这不等于零留存;网页聊天历史、计费用量记录、技术日志和上游处理范围请参阅隐私政策。

流式输出

stream.pypython
import os
from getpass import getpass
from openai import OpenAI

api_key = os.environ.get("LAOMACHAT_API_KEY") or getpass("LaomaChat API Key: ")
client = OpenAI(
    api_key=api_key,
    base_url="https://api.laomachat.com/v1",
    timeout=300.0,
    max_retries=0,
)

stream = client.chat.completions.create(
    model="grok-4.6",
    messages=[{"role": "user", "content": "写一首四行短诗。"}],
    stream=True,
    stream_options={"include_usage": True},
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
    if chunk.usage:
        print(f"\nusage: {chunk.usage}")

非流式读取 response.choices[0].message.content;流式逐块读取 chunk.choices[0].delta.content。