Python: Prefer runtime kwargs for conversation_id in OpenAI Responses client (#3312)

* prefer kwargs conversation_id over options

* addressed comments
This commit is contained in:
Giles Odigwe
2026-01-22 22:05:00 -08:00
committed by GitHub
Unverified
parent e229dfa7e5
commit e8b32ca337
2 changed files with 20 additions and 2 deletions
@@ -2114,6 +2114,20 @@ async def test_prepare_options_store_parameter_handling() -> None:
assert "previous_response_id" not in options
async def test_conversation_id_precedence_kwargs_over_options() -> None:
"""When both kwargs and options contain conversation_id, kwargs wins."""
client = OpenAIResponsesClient(model_id="test-model", api_key="test-key")
messages = [ChatMessage(role="user", text="Hello")]
# options has a stale response id, kwargs carries the freshest one
opts = {"conversation_id": "resp_old_123"}
run_opts = await client._prepare_options(messages, opts, conversation_id="resp_new_456") # type: ignore
# Verify kwargs takes precedence and maps to previous_response_id for resp_* IDs
assert run_opts.get("previous_response_id") == "resp_new_456"
assert "conversation" not in run_opts
def test_with_callable_api_key() -> None:
"""Test OpenAIResponsesClient initialization with callable API key."""