API
Công cụ tạo mã API
Chọn ngôn ngữ và tác vụ để nhận mã theo tài liệu của Reflection, bao gồm cả những điểm khác với OpenAI.
Beam-501B-A23B
Ngôn ngữ
reasoning_effort
Để trống để dùng mặc định của API. Lập luận được tính vào giới hạn này.
Cài đặt và khóa API
bash
pip install openai
export REFLECTION_API_KEY="<your API key>"Mã
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)Phần lập luận được truyền phát trước trong delta.reasoning_content, sau đó là câu trả lời trong delta.content. include_usage thêm một chunk cuối cùng có số lượng token.
Hỗ trợ tham số
Được hỗ trợ
- model, messages với các vai trò system, developer, user, assistant và tool
- reasoning_effort: low, medium, high, xhigh, max
- stream và stream_options.include_usage
- tools, tool_choice, parallel_tool_calls
- response_format: json_object và json_schema, với strict
- temperature, top_p, frequency_penalty, presence_penalty, seed, max_completion_tokens
Không được hỗ trợ
- Đầu vào hình ảnh, âm thanh và tệp
- n khác 1, logprobs, logit_bias
- user, metadata, audio và prediction sẽ trả về lỗi
- stop được chấp nhận nhưng không có tác dụng
- Các API Responses, Embeddings, Images, Audio, Files, Batch và Assistants
Các lỗi cần xử lý
| Trạng thái và mã lỗi | Ý nghĩa |
|---|---|
| 400 unsupported_value | Giá trị reasoning_effort mà mô hình không chấp nhận, chẳng hạn none hoặc minimal. |
| 400 missing_required_parameter | Tin nhắn assistant trước đó được gửi mà không có reasoning_content, hoặc thiếu json_schema. |
| 401 | API key bị thiếu hoặc không hợp lệ. |
| 429 rate_limit_exceeded | Đã chạm giới hạn theo phút hoặc theo ngày. Hãy chờ Retry-After. |
| 503 inference_capacity_unavailable | Dung lượng tạm thời đã cạn. Hãy thử lại sau Retry-After. |
Nguồn: openai-compatibility · reasoning · tool-calling · structured-outputs · errors