API

APIコードジェネレーター

言語とタスクを選ぶと、OpenAIとは異なる点も含め、Reflectionのドキュメントに沿ったコードを生成します。

Beam-501B-A23B
言語
reasoning_effort
空欄の場合はAPIのデフォルト値が使われます。推論トークンもこの上限に含まれます。

インストールと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を指定すると、トークン数を含む最後のチャンクが追加されます。

パラメータのサポート状況

対応
  • 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
非対応
  • 画像、音声、ファイルの入力
  • 1以外のn、logprobs、logit_bias
  • user、metadata、audio、predictionを指定するとエラーが返されます
  • stopは受け付けられますが、効果はありません
  • Responses、Embeddings、Images、Audio、Files、Batch、Assistants API

対処が必要なエラー

ステータスとコード意味
400 unsupported_valuenoneやminimalなど、モデルが受け付けないreasoning_effortの値です。
400 missing_required_parameterreasoning_contentを含めずに以前のassistantメッセージが送信されたか、json_schemaが指定されていません。
401APIキーがないか、無効です。
429 rate_limit_exceeded1分あたりまたは1日あたりの上限に達しました。Retry-Afterを確認してから再試行してください。
503 inference_capacity_unavailable一時的に容量が不足しています。Retry-Afterを確認してから再試行してください。

ソース一覧: openai-compatibility · reasoning · tool-calling · structured-outputs · errors