What this thread does
Do first: replace response["choices"][0]["message"]["content"] with response.choices[0].message.content and set stream=False when one completed response is expected.
Short answer
Diagnostic: 'ChatCompletion' object is not subscriptable
As of November 2026, OpenAI Python 3.58.0 retains typed responses. The 1.0 migration guide marks the change from dictionary-shaped response objects to Pydantic models. The current SDK example reads completion.choices[0].message.content.
Choose / don't choose
- Typed application code: read attributes directly and retain type checking; don't convert just to reproduce legacy indexing everywhere.
- Existing dictionary consumer: convert once with
response.model_dump()at that boundary. - Streaming consumer: choose the stream iteration contract deliberately; don't treat a stream as a completed ChatCompletion.
Not for: Decisions type migration; see openai-python-3-37-0-decisions-instructions-union-type.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
stream | False is the non-streaming request type; True yields streamed events | Current Chat Completions request types | request schema |
n | Omit for one choice; newer models reject explicit n, even n=1 | Current Chat Completions request types | request schema |
choices[0].message.content | Read attributes after list indexing; content is Optional[str] with default None | Typed SDK response API | SDK example, message type |
model_dump() | Convert the model to a dictionary at a legacy boundary | v1.0.0 migration guide | migration guide |
model_dump(mode="json") | Choose JSON-compatible values when passing the dictionary to a JSON consumer; default mode is "python" | Current SDK model source | model implementation |
Order of operations
1. Keep request payload dictionaries separate from returned model objects. Request messages can remain dictionaries; their shape does not imply the response supports dictionary indexing. 2. Request stream=False and omit n on the creation call when one finished choice is needed. Handle an empty choice list defensively before indexing; handle absent text, refusal or tool output under the application's expected response contract. 3. Read response.choices[0].message.content. Only choices uses [0]. SDK usage. 4. If the downstream interface requires dictionaries, hand it response.model_dump() or JSON-compatible dump mode. Keep that conversion at the boundary so new code retains typed access.
Known failures and fixes
| Error or symptom | Cause | Fix | Source |
|---|---|---|---|
'ChatCompletion' object is not subscriptable | Legacy top-level string-key indexing after the typed-response migration | Use response.choices[0].message.content or convert intentionally | migration guide, current example |
| Streaming request | The streaming request type requires stream=True | Use the non-streaming type’s stream=False, or handle streaming events | request schema |
Sadegh Ghanbari’s report reports the ChatCompletion object-is-not-subscriptable error. The remedy above follows the current SDK and migration documentation.
Missing
- This fixes object access, not model-specific response content. A missing textual answer must be classified before it is passed to a text-only consumer.
- This is a Chat Completions migration recipe; Responses API results have their own typed shape.
Checked
2026-11-24; OpenAI Python 3.58.0 release, 1.0 migration guide, SDK README/helpers and request/model source rechecked. No model requests executed.
Started from a post by @OpenAI, packaged by the editor. Original post