openai/openai-python · error · ValueError

Expected a non-empty value for `step_id` but received {step_

Error message

Expected a non-empty value for `step_id` but received {step_id!r}

What it means

`steps.retrieve` validates `step_id` (third and last check) and raises this ValueError when it is falsy. The step ID (e.g. `step_abc123`) is required to address an individual run step resource.

Source

Thrown at src/openai/resources/beta/threads/runs/steps.py:88

              See the
              [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
              for more information.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        """
        if not thread_id:
            raise ValueError(f"Expected a non-empty value for `thread_id` but received {thread_id!r}")
        if not run_id:
            raise ValueError(f"Expected a non-empty value for `run_id` but received {run_id!r}")
        if not step_id:
            raise ValueError(f"Expected a non-empty value for `step_id` but received {step_id!r}")
        extra_headers = {"OpenAI-Beta": "assistants=v2", **(extra_headers or {})}
        return self._get(
            path_template(
                "/threads/{thread_id}/runs/{run_id}/steps/{step_id}",
                thread_id=thread_id,
                run_id=run_id,
                step_id=step_id,
            ),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform({"include": include}, step_retrieve_params.StepRetrieveParams),
                security={"bearer_auth": True},
            ),
            cast_to=RunStep,
        )

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Pass `step.id` from the step object you obtained via listing or events
  2. Validate the step_id string is non-empty before retrieving
  3. When parsing events, default to skipping the call if the field is missing

Example fix

# before
step = client.beta.threads.runs.steps.retrieve(thread_id=thread_id, run_id=run_id, step_id=step)  # step is an object/None

# after
step = client.beta.threads.runs.steps.retrieve(thread_id=thread_id, run_id=run_id, step_id=step.id)
Defensive patterns

Strategy: type-guard

Validate before calling

step_id = step.id if hasattr(step, "id") else step
if not isinstance(step_id, str) or not step_id:
    raise ValueError("step_id must be a non-empty string")
step = client.beta.threads.runs.steps.retrieve(thread_id=thread_id, run_id=run_id, step_id=step_id)

Type guard

def is_valid_step_id(value: object) -> TypeGuard[str]:
    return isinstance(value, str) and value.startswith("step_")

Try / catch

try:
    step = client.beta.threads.runs.steps.retrieve(thread_id=thread_id, run_id=run_id, step_id=step_id)
except ValueError as e:
    if "step_id" in str(e):
        continue  # skip malformed references when iterating
    raise

Prevention

When it happens

Trigger: Calling retrieve with `step_id=None`/`""` — e.g. iterating `run.steps` but passing the whole step object or an uninitialized variable instead of `step.id`.

Common situations: Confusing the step object with its ID, parsing step IDs from webhook/event payloads where the field is absent, or off-by-one logic producing an empty value.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of openai/openai-python@9917c6e28e (2026-08-28). Data as JSON: /api/errors/8eda925a6359dbf7. Report an issue: GitHub.