openai/openai-python · error · ValueError

Expected a non-empty value for `conversation_id` but receive

Error message

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

What it means

Conversation items create() posts to /conversations/{conversation_id}/items and validates conversation_id is non-empty before sending. The ValueError fires synchronously in the sync client when the argument is falsy, so no HTTP request is wasted. This is a required path parameter with no default.

Source

Thrown at src/openai/resources/conversations/items.py:82

        Create items in a conversation with the given ID.

        Args:
          items: The items to add to the conversation. You may add up to 20 items at a time.

          include: Additional fields to include in the response. See the `include` parameter for
              [listing Conversation items above](https://platform.openai.com/docs/api-reference/conversations/list-items#conversations_list_items-include)
              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 conversation_id:
            raise ValueError(f"Expected a non-empty value for `conversation_id` but received {conversation_id!r}")
        return self._post(
            path_template("/conversations/{conversation_id}/items", conversation_id=conversation_id),
            body=maybe_transform({"items": items}, item_create_params.ItemCreateParams),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                query=maybe_transform({"include": include}, item_create_params.ItemCreateParams),
                security={"bearer_auth": True},
            ),
            cast_to=ConversationItemList,
        )

    def retrieve(
        self,
        item_id: str,
        *,

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Capture the id from conversations.create() and pass that value
  2. Check the parameter is a non-empty string before calling items.create
  3. Use keyword arguments to avoid positional mix-ups

Example fix

# before
client.conversations.items.create(conversation_id=conv, items=items)  # conv is None

# after
conv = client.conversations.create().id
client.conversations.items.create(conversation_id=conv, items=items)
Defensive patterns

Strategy: validation

Validate before calling

if not conversation_id:
    raise ValueError("cannot add items without a conversation_id")
client.conversations.items.create(conversation_id=conversation_id, items=items)

Type guard

def is_non_empty_str(v: object) -> bool:
    return isinstance(v, str) and len(v) > 0

Try / catch

try:
    client.conversations.items.create(conversation_id=cid, items=items)
except ValueError as e:
    raise RuntimeError(f"bad request arguments: {e}") from e

Prevention

When it happens

Trigger: Calling client.conversations.items.create(conversation_id='', items=[...]) or passing an unbound/None variable as the conversation id in the synchronous client.

Common situations: Building items for a conversation whose creation response wasn't captured, threading ids through multiple functions where one branch leaves it None, or typos in keyword argument names leaving the real parameter unset.

Related errors


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