openai/openai-python · error · TypeError

Unexpected, list delta entry `index` value is not an integer

Error message

Unexpected, list delta entry `index` value is not an integer; {index}

What it means

Raised by accumulate_delta in _deltas.py when a list delta entry has an index of the wrong type (not an int, e.g. string or None). List merging uses the value directly as a Python list index, so non-integer indices are rejected with this TypeError echoing the value.

Source

Thrown at src/openai/lib/streaming/_deltas.py:50

            acc_value = accumulate_delta(acc_value, delta_value)
        elif is_list(acc_value) and is_list(delta_value):
            # for lists of non-dictionary items we'll only ever get new entries
            # in the array, existing entries will never be changed
            if all(isinstance(x, (str, int, float)) for x in acc_value):
                acc_value.extend(delta_value)
                continue

            for delta_entry in delta_value:
                if not is_dict(delta_entry):
                    raise TypeError(f"Unexpected list delta entry is not a dictionary: {delta_entry}")

                try:
                    index = delta_entry["index"]
                except KeyError as exc:
                    raise RuntimeError(f"Expected list delta entry to have an `index` key; {delta_entry}") from exc

                if not isinstance(index, int):
                    raise TypeError(f"Unexpected, list delta entry `index` value is not an integer; {index}")

                try:
                    acc_entry = acc_value[index]
                except IndexError:
                    acc_value.insert(index, delta_entry)
                else:
                    if not is_dict(acc_entry):
                        raise TypeError("not handled yet")

                    acc_value[index] = accumulate_delta(acc_entry, delta_entry)

        acc[key] = acc_value

    return acc

View on GitHub (pinned to 9917c6e28e)

Solutions

  1. Coerce/ensure index is int before accumulating custom deltas
  2. Upgrade the SDK to the current release
  3. Validate delta shape in custom accumulation pipelines
  4. Catch TypeError and replace the list as fallback

Example fix

# before
entry = {"index": None, "text": "hi"}

# after
entry = {"index": 0, "text": "hi"}
Defensive patterns

Strategy: validation

Validate before calling

def indices_are_ints(entries) -> bool:
    return all(type(e.get("index")) is int for e in entries if isinstance(e, dict))

Type guard

null

Try / catch

try:
    acc = accumulate_delta(acc, delta)
except TypeError:
    acc[key] = copy.deepcopy(delta[key])

Prevention

When it happens

Trigger: Streaming deltas where index arrives as a string or null; proxies/middleware altering JSON types; test fixtures with stringified indices.

Common situations: Serialization differences in beta APIs; SDK version mismatches; hand-normalized payloads.

Related errors


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