openai/openai-python · error · ValueError

Expected a non-empty value for `character_id` but received {

Error message

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

What it means

Videos.get_character retrieves a video character via GET /videos/characters/{character_id} and requires a non-empty character_id path parameter. The SDK raises ValueError client-side when the value is falsy so it never issues a request to a malformed URL.

Source

Thrown at src/openai/resources/videos.py:585

        extra_headers: Headers | None = None,
        extra_query: Query | None = None,
        extra_body: Body | None = None,
        timeout: float | httpx2.Timeout | None | NotGiven = not_given,
    ) -> VideoGetCharacterResponse:
        """
        Fetch a character.

        Args:
          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 character_id:
            raise ValueError(f"Expected a non-empty value for `character_id` but received {character_id!r}")
        return self._get(
            path_template("/videos/characters/{character_id}", character_id=character_id),
            options=make_request_options(
                extra_headers=extra_headers,
                extra_query=extra_query,
                extra_body=extra_body,
                timeout=timeout,
                security={"bearer_auth": True},
            ),
            cast_to=VideoGetCharacterResponse,
        )

    @typing_extensions.deprecated("The Sora API is scheduled to permanently shut down on September 24, 2026.")
    def remix(
        self,
        video_id: str,
        *,
        prompt: str,

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Confirm character_id is a non-empty string before calling
  2. Extract ids with character.id from the API response objects
  3. Filter out entries missing ids before the loop

Example fix

// before
for c in characters:
    client.videos.get_character(character_id=c.get("id"))

// after
for c in characters:
    if c.id:
        client.videos.get_character(character_id=c.id)
Defensive patterns

Strategy: validation

Validate before calling

if not character_id:
    skip_or_raise()

Type guard

def is_valid_character_id(v: object) -> TypeGuard[str]:
    return isinstance(v, str) and bool(v.strip())

Prevention

When it happens

Trigger: Calling client.videos.get_character(character_id="") or with None, e.g. when iterating over a list of characters where one entry lacked an id.

Common situations: Mapping over character objects where some entries are dicts without an 'id' key, or referencing a character field that does not exist on the response model.

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/905250076acdee09. Report an issue: GitHub.