API

API code generator

Pick a language and a task to get code that follows Reflection's documentation, including the details that differ from OpenAI.

Beam-501B-A23B
Language
reasoning_effort
Empty means the API default. Reasoning counts toward this limit.

Install and key

bash
pip install openai
export REFLECTION_API_KEY="<your API key>"

Code

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)
Reasoning streams first in delta.reasoning_content, then the answer in delta.content. include_usage adds a final chunk with token counts.

Parameter support

Supported
  • model, messages with system, developer, user, assistant and tool roles
  • reasoning_effort: low, medium, high, xhigh, max
  • stream and stream_options.include_usage
  • tools, tool_choice, parallel_tool_calls
  • response_format: json_object and json_schema, with strict
  • temperature, top_p, frequency_penalty, presence_penalty, seed, max_completion_tokens
Not supported
  • Image, audio and file inputs
  • n other than 1, logprobs, logit_bias
  • user, metadata, audio and prediction return an error
  • stop is accepted but has no effect
  • Responses, Embeddings, Images, Audio, Files, Batch and Assistants APIs

Errors worth handling

Status and codeWhat it means
400 unsupported_valueA reasoning_effort value the model doesn't accept, such as none or minimal.
400 missing_required_parameterAn earlier assistant message was sent without its reasoning_content, or json_schema is missing.
401The API key is missing or invalid.
429 rate_limit_exceededA per-minute or daily limit was hit. Wait for Retry-After.
503 inference_capacity_unavailableCapacity is temporarily exhausted. Retry after Retry-After.

Sources: openai-compatibility · reasoning · tool-calling · structured-outputs · errors