API
API 代码生成器
选择语言和任务,即可获取符合 Reflection 文档的代码,其中也包含与 OpenAI 不同的细节。
Beam-501B-A23B
语言
reasoning_effort
留空表示使用 API 默认值。推理内容计入此上限。
安装与密钥
bash
pip install openai
export REFLECTION_API_KEY="<your API key>"代码
main.py
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.reflection.ai/openai/v1",
api_key=os.environ["REFLECTION_API_KEY"],
)
messages = [
{"role": "user", "content": "Write a short poem about sparse experts."},
]
stream = client.chat.completions.create(
model="Beam-501B-A23B",
messages=messages,
reasoning_effort="medium",
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if not chunk.choices: # the last chunk carries only usage
print("\n", chunk.usage)
continue
delta = chunk.choices[0].delta
reasoning = getattr(delta, "reasoning_content", None)
if reasoning:
print(reasoning, end="", flush=True)
if delta.content:
print(delta.content, end="", flush=True)推理内容会先通过 delta.reasoning_content 流式返回,然后答案通过 delta.content 返回。include_usage 会在最后一个数据块中添加 token 数量。
参数支持
支持
- model、包含 system、developer、user、assistant 和 tool 角色的 messages
- reasoning_effort: low, medium, high, xhigh, max
- stream 和 stream_options.include_usage
- tools、tool_choice、parallel_tool_calls
- response_format: json_object 和 json_schema,以及 strict
- temperature、top_p、frequency_penalty、presence_penalty、seed、max_completion_tokens
不支持
- 图像、音频和文件输入
- n 不为 1、logprobs、logit_bias
- user、metadata、audio 和 prediction 会返回错误
- stop 会被接受,但不会产生任何效果
- Responses、Embeddings、Images、Audio、Files、Batch 和 Assistants API
值得处理的错误
| 状态码和错误代码 | 含义 |
|---|---|
| 400 unsupported_value | 模型不接受的 reasoning_effort 值,例如 none 或 minimal。 |
| 400 missing_required_parameter | 发送较早的 assistant 消息时未包含 reasoning_content,或者缺少 json_schema。 |
| 401 | API 密钥缺失或无效。 |
| 429 rate_limit_exceeded | 已达到每分钟或每日限额。请等待 Retry-After 指定的时间。 |
| 503 inference_capacity_unavailable | 当前容量暂时不足。请在 Retry-After 指定的时间后重试。 |
来源: openai-compatibility · reasoning · tool-calling · structured-outputs · errors