{"record":{"id":"48547f7f3dd3a332","repo":"openai/openai-python","slug":"unexpected-list-delta-entry-index-value-is-not","errorCode":null,"errorMessage":"Unexpected, list delta entry `index` value is not an integer; {index}","messagePattern":"Unexpected, list delta entry `index` value is not an integer; (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/openai/lib/streaming/_assistants.py","lineNumber":1027,"sourceCode":"            acc_value = accumulate_delta(acc_value, delta_value)\n        elif is_list(acc_value) and is_list(delta_value):\n            # for lists of non-dictionary items we'll only ever get new entries\n            # in the array, existing entries will never be changed\n            if all(isinstance(x, (str, int, float)) for x in acc_value):\n                acc_value.extend(delta_value)\n                continue\n\n            for delta_entry in delta_value:\n                if not is_dict(delta_entry):\n                    raise TypeError(f\"Unexpected list delta entry is not a dictionary: {delta_entry}\")\n\n                try:\n                    index = delta_entry[\"index\"]\n                except KeyError as exc:\n                    raise RuntimeError(f\"Expected list delta entry to have an `index` key; {delta_entry}\") from exc\n\n                if not isinstance(index, int):\n                    raise TypeError(f\"Unexpected, list delta entry `index` value is not an integer; {index}\")\n\n                try:\n                    acc_entry = acc_value[index]\n                except IndexError:\n                    acc_value.insert(index, delta_entry)\n                else:\n                    if not is_dict(acc_entry):\n                        raise TypeError(\"not handled yet\")\n\n                    acc_value[index] = accumulate_delta(acc_entry, delta_entry)\n\n        acc[key] = acc_value\n\n    return acc\n","sourceCodeStart":1009,"sourceCodeEnd":1042,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/streaming/_assistants.py#L1009-L1042","documentation":"Raised inside accumulate_delta when a list delta entry's index value is present but not an int (e.g. a string '0' or None). The merger indexes Python lists with it, so a non-integer index is rejected with this TypeError showing the bad value.","triggerScenarios":"Delta payloads where index is serialized as a string or null; schema changes in beta streaming endpoints; test fixtures using JSON-ish typed indices.","commonSituations":"Version mismatch between SDK accumulator strictness and API serialization; middleware/proxies rewriting JSON; handcrafted delta dicts in unit tests.","solutions":["Ensure index is a plain int (json.loads yields int for JSON numbers - check for manual coercion)","Upgrade the SDK to match the current API schema","Validate/normalize delta entries before accumulation in custom pipelines","Catch TypeError and replace the accumulated list as a fallback"],"exampleFix":"# before\nentry = {\"index\": \"0\", \"text\": \"hi\"}\n\n# after\nentry = {\"index\": 0, \"text\": \"hi\"}","handlingStrategy":"validation","validationCode":"def entries_have_int_index(entries) -> bool:\n    return all(\n        isinstance(e, dict) and type(e.get(\"index\")) is int for e in entries\n    )","typeGuard":"null","tryCatchPattern":"try:\n    acc = accumulate_delta(acc, delta)\nexcept TypeError:\n    acc[key] = copy.deepcopy(delta)","preventionTips":["Normalize index to int before accumulating custom deltas","Watch for middleware that stringifies JSON values","Upgrade SDK when API serialization changes"],"tags":["streaming","delta-accumulation","typeerror","python"],"backgroundTag":"delta-schema-mismatch","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}