{"record":{"id":"0d2f32387d42ded6","repo":"openai/openai-python","slug":"expected-list-delta-entry-to-have-an-index-key","errorCode":null,"errorMessage":"Expected list delta entry to have an `index` key; {delta_entry}","messagePattern":"Expected list delta entry to have an `index` key; (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/openai/lib/streaming/_assistants.py","lineNumber":1024,"sourceCode":"        elif isinstance(acc_value, (int, float)) and isinstance(delta_value, (int, float)):\n            acc_value += delta_value\n        elif is_dict(acc_value) and is_dict(delta_value):\n            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":1006,"sourceCodeEnd":1042,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/streaming/_assistants.py#L1006-L1042","documentation":"Raised inside accumulate_delta when a list delta entry is a dict but has no 'index' key. Indexed list merging needs index to know where to place/merge the entry; its absence (KeyError) is converted to this RuntimeError with the offending entry in the message.","triggerScenarios":"Streaming payloads where list delta dicts omit index - schema drift between the API emitting the delta and the SDK version parsing it, or hand-built delta fixtures in tests that forget the index key.","commonSituations":"API schema evolution outpacing an older pinned SDK; beta endpoints mid-rollout; test fixtures authored from stale docs.","solutions":["Update the openai package to the latest release matching the API","Include an integer index key in every list delta entry you construct","Pin to known-compatible API/SDK versions during beta periods","Catch RuntimeError and fall back to whole-list replacement if resilient accumulation is required"],"exampleFix":"# before\nentry = {\"type\": \"output_text\", \"text\": \"hi\"}  # no index\nacc = accumulate_delta(acc, {\"content\": [entry]})\n\n# after\nentry = {\"index\": 0, \"type\": \"output_text\", \"text\": \"hi\"}\nacc = accumulate_delta(acc, {\"content\": [entry]})","handlingStrategy":"validation","validationCode":"def entries_have_index(entries) -> bool:\n    return all(isinstance(e, dict) and isinstance(e.get(\"index\"), int) for e in entries)","typeGuard":"def is_indexed_delta_entry(entry) -> bool:\n    return is_dict(entry) and isinstance(entry.get(\"index\"), int)","tryCatchPattern":"try:\n    acc = accumulate_delta(acc, delta)\nexcept RuntimeError:\n    acc[key] = copy.deepcopy(delta)","preventionTips":["Always include an integer index in list delta entries","Pin compatible SDK/API versions during betas","Validate fixtures against current schema docs"],"tags":["streaming","delta-accumulation","schema-mismatch","python"],"backgroundTag":"delta-schema-mismatch","analyzedSha":"9917c6e28e66e90e1227b3d223c06a8c5441515a","analyzedAt":"2026-08-28T11:46:34.183Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}