{"record":{"id":"4c9572674d52219a","repo":"openai/openai-python","slug":"expected-list-delta-entry-to-have-an-index-key-4c9572","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/_deltas.py","lineNumber":47,"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":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/openai/openai-python/blob/9917c6e28e66e90e1227b3d223c06a8c5441515a/src/openai/lib/streaming/_deltas.py#L29-L65","documentation":"Raised by accumulate_delta in _deltas.py when a list delta entry is a dict missing the required 'index' key; the KeyError is converted into this descriptive RuntimeError. The index key is how the accumulator locates the accumulated entry to merge into.","triggerScenarios":"Chat/Responses streaming deltas whose list entries omit index; API/SDK schema drift; manually crafted delta objects missing the key.","commonSituations":"Beta endpoint schema evolution; stale SDK pins; fixtures written against outdated docs.","solutions":["Upgrade the openai package","Add an integer index to each list delta entry you construct","Pin compatible API/SDK versions during beta windows","Wrap accumulation in try/except RuntimeError with list replacement fallback"],"exampleFix":"# before\nentry = {\"text\": \"hi\"}\n\n# after\nentry = {\"index\": 0, \"text\": \"hi\"}","handlingStrategy":"validation","validationCode":"def entries_indexed(entries) -> bool:\n    return all(isinstance(e, dict) and \"index\" in e for e in entries)","typeGuard":"def is_indexed_delta_entry(entry) -> bool:\n    return isinstance(entry, dict) and \"index\" in entry","tryCatchPattern":"try:\n    acc = accumulate_delta(acc, delta)\nexcept RuntimeError:\n    acc[key] = copy.deepcopy(delta[key])","preventionTips":["Add integer index keys to every list delta entry","Upgrade openai package before reporting schema bugs","Pin compatible versions in beta periods"],"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"}