Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,9 @@ The polling methods are:
client.beta.threads.create_and_run_poll(...)
client.beta.threads.runs.create_and_poll(...)
client.beta.threads.runs.submit_tool_outputs_and_poll(...)
client.beta.vector_stores.files.upload_and_poll(...)
client.beta.vector_stores.files.create_and_poll(...)
client.beta.vector_stores.file_batches.create_and_poll(...)
client.beta.vector_stores.file_batches.upload_and_poll(...)
client.vector_stores.files.upload_and_poll(...)
client.vector_stores.files.create_and_poll(...)
client.vector_stores.file_batches.create_and_poll(...)
client.vector_stores.file_batches.upload_and_poll(...)
client.videos.create_and_poll(...)
```
2 changes: 1 addition & 1 deletion src/openai/lib/_parsing/_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def parse_response(
type_=ParsedResponseOutputText[TextFormatT],
value={
**item.to_dict(),
"parsed": parse_text(item.text, text_format=text_format),
"parsed": parse_text(item.text, text_format=text_format) if item.text is not None else None,
},
)
)
Expand Down
5 changes: 5 additions & 0 deletions src/openai/lib/streaming/responses/_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,11 @@ def accumulate_event(self, event: RawResponseStreamEvent) -> ParsedResponseSnaps
if output.type == "message":
content = output.content[event.content_index]
assert content.type == "output_text"
# content_part.added snapshots may carry text=None when the
# server streams a not-yet-materialized part. Normalize to ""
# so the first delta doesn't raise TypeError on '+='.
if content.text is None:
content.text = ""
content.text += event.delta
elif event.type == "response.function_call_arguments.delta":
output = snapshot.output[event.output_index]
Expand Down
24 changes: 12 additions & 12 deletions src/openai/resources/chat/completions/completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def parse(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
safety_identifier: str | Omit = omit,
seed: Optional[int] | Omit = omit,
Expand Down Expand Up @@ -264,7 +264,7 @@ def create(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
response_format: completion_create_params.ResponseFormat | Omit = omit,
safety_identifier: str | Omit = omit,
Expand Down Expand Up @@ -571,7 +571,7 @@ def create(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
response_format: completion_create_params.ResponseFormat | Omit = omit,
safety_identifier: str | Omit = omit,
Expand Down Expand Up @@ -877,7 +877,7 @@ def create(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
response_format: completion_create_params.ResponseFormat | Omit = omit,
safety_identifier: str | Omit = omit,
Expand Down Expand Up @@ -1182,7 +1182,7 @@ def create(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
response_format: completion_create_params.ResponseFormat | Omit = omit,
safety_identifier: str | Omit = omit,
Expand Down Expand Up @@ -1461,7 +1461,7 @@ def stream(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
safety_identifier: str | Omit = omit,
seed: Optional[int] | Omit = omit,
Expand Down Expand Up @@ -1612,7 +1612,7 @@ async def parse(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
safety_identifier: str | Omit = omit,
seed: Optional[int] | Omit = omit,
Expand Down Expand Up @@ -1767,7 +1767,7 @@ async def create(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
response_format: completion_create_params.ResponseFormat | Omit = omit,
safety_identifier: str | Omit = omit,
Expand Down Expand Up @@ -2074,7 +2074,7 @@ async def create(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
response_format: completion_create_params.ResponseFormat | Omit = omit,
safety_identifier: str | Omit = omit,
Expand Down Expand Up @@ -2380,7 +2380,7 @@ async def create(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
response_format: completion_create_params.ResponseFormat | Omit = omit,
safety_identifier: str | Omit = omit,
Expand Down Expand Up @@ -2685,7 +2685,7 @@ async def create(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
response_format: completion_create_params.ResponseFormat | Omit = omit,
safety_identifier: str | Omit = omit,
Expand Down Expand Up @@ -2964,7 +2964,7 @@ def stream(
prediction: Optional[ChatCompletionPredictionContentParam] | Omit = omit,
presence_penalty: Optional[float] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning_effort: Optional[ReasoningEffort] | Omit = omit,
safety_identifier: str | Omit = omit,
seed: Optional[int] | Omit = omit,
Expand Down
32 changes: 16 additions & 16 deletions src/openai/resources/responses/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -396,7 +396,7 @@ def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -645,7 +645,7 @@ def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -892,7 +892,7 @@ def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -995,7 +995,7 @@ def stream(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -1036,7 +1036,7 @@ def stream(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -1187,7 +1187,7 @@ def parse(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -1823,7 +1823,7 @@ async def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -2073,7 +2073,7 @@ async def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -2322,7 +2322,7 @@ async def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -2569,7 +2569,7 @@ async def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -2672,7 +2672,7 @@ def stream(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -2713,7 +2713,7 @@ def stream(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -2868,7 +2868,7 @@ async def parse(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -4543,7 +4543,7 @@ def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down Expand Up @@ -4623,7 +4623,7 @@ async def create(
previous_response_id: Optional[str] | Omit = omit,
prompt: Optional[ResponsePromptParam] | Omit = omit,
prompt_cache_key: str | Omit = omit,
prompt_cache_retention: Optional[Literal["in-memory", "24h"]] | Omit = omit,
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] | Omit = omit,
reasoning: Optional[Reasoning] | Omit = omit,
safety_identifier: str | Omit = omit,
service_tier: Optional[Literal["auto", "default", "flex", "scale", "priority"]] | Omit = omit,
Expand Down
2 changes: 1 addition & 1 deletion src/openai/types/chat/completion_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class CompletionCreateParamsBase(TypedDict, total=False):
[Learn more](https://platform.openai.com/docs/guides/prompt-caching).
"""

prompt_cache_retention: Optional[Literal["in-memory", "24h"]]
prompt_cache_retention: Optional[Literal["in_memory", "24h"]]
"""The retention policy for the prompt cache.
Set to `24h` to enable extended prompt caching, which keeps cached prefixes
Expand Down
4 changes: 2 additions & 2 deletions src/openai/types/responses/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class Response(BaseModel):
[Learn more](https://platform.openai.com/docs/guides/prompt-caching).
"""

prompt_cache_retention: Optional[Literal["in-memory", "24h"]] = None
prompt_cache_retention: Optional[Literal["in_memory", "24h"]] = None
"""The retention policy for the prompt cache.

Set to `24h` to enable extended prompt caching, which keeps cached prefixes
Expand Down Expand Up @@ -315,7 +315,7 @@ def output_text(self) -> str:
for output in self.output:
if output.type == "message":
for content in output.content:
if content.type == "output_text":
if content.type == "output_text" and content.text is not None:
texts.append(content.text)

return "".join(texts)
2 changes: 1 addition & 1 deletion src/openai/types/responses/response_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class ResponseCreateParamsBase(TypedDict, total=False):
[Learn more](https://platform.openai.com/docs/guides/prompt-caching).
"""

prompt_cache_retention: Optional[Literal["in-memory", "24h"]]
prompt_cache_retention: Optional[Literal["in_memory", "24h"]]
"""The retention policy for the prompt cache.
Set to `24h` to enable extended prompt caching, which keeps cached prefixes
Expand Down
2 changes: 1 addition & 1 deletion src/openai/types/responses/response_output_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ResponseOutputText(BaseModel):
annotations: List[Annotation]
"""The annotations of the text output."""

text: str
text: Optional[str] = None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep streamed output text non-null before delta appends

Changing ResponseOutputText.text to optional allows response.content_part.added snapshots to carry text=None, but streaming accumulation still assumes a string and does content.text += event.delta in src/openai/lib/streaming/responses/_responses.py (lines 349-354). In streams where a content part starts as null and then receives response.output_text.delta events, this will raise a TypeError and terminate parsing; please preserve a non-null invariant for streamed output_text content (or normalize null to "" before appending).

Useful? React with 👍 / 👎.

"""The text output from the model."""

type: Literal["output_text"]
Expand Down
Loading