1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
   2
   3from __future__ import annotations
   4
   5import os
   6from typing import Any, cast
   7
   8import pytest
   9
  10from openai import OpenAI, AsyncOpenAI
  11from tests.utils import assert_matches_type
  12from openai.pagination import SyncCursorPage, AsyncCursorPage
  13from openai.types.beta.threads import (
  14    Run,
  15)
  16
  17# pyright: reportDeprecated=false
  18
  19base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
  20
  21
  22class TestRuns:
  23    parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
  24
  25    @parametrize
  26    def test_method_create_overload_1(self, client: OpenAI) -> None:
  27        with pytest.warns(DeprecationWarning):
  28            run = client.beta.threads.runs.create(
  29                thread_id="thread_id",
  30                assistant_id="assistant_id",
  31            )
  32
  33        assert_matches_type(Run, run, path=["response"])
  34
  35    @parametrize
  36    def test_method_create_with_all_params_overload_1(self, client: OpenAI) -> None:
  37        with pytest.warns(DeprecationWarning):
  38            run = client.beta.threads.runs.create(
  39                thread_id="thread_id",
  40                assistant_id="assistant_id",
  41                include=["step_details.tool_calls[*].file_search.results[*].content"],
  42                additional_instructions="additional_instructions",
  43                additional_messages=[
  44                    {
  45                        "content": "string",
  46                        "role": "user",
  47                        "attachments": [
  48                            {
  49                                "file_id": "file_id",
  50                                "tools": [{"type": "code_interpreter"}],
  51                            }
  52                        ],
  53                        "metadata": {"foo": "string"},
  54                    }
  55                ],
  56                instructions="instructions",
  57                max_completion_tokens=256,
  58                max_prompt_tokens=256,
  59                metadata={"foo": "string"},
  60                model="string",
  61                parallel_tool_calls=True,
  62                reasoning_effort="none",
  63                response_format="auto",
  64                stream=False,
  65                temperature=1,
  66                tool_choice="none",
  67                tools=[{"type": "code_interpreter"}],
  68                top_p=1,
  69                truncation_strategy={
  70                    "type": "auto",
  71                    "last_messages": 1,
  72                },
  73            )
  74
  75        assert_matches_type(Run, run, path=["response"])
  76
  77    @parametrize
  78    def test_raw_response_create_overload_1(self, client: OpenAI) -> None:
  79        with pytest.warns(DeprecationWarning):
  80            response = client.beta.threads.runs.with_raw_response.create(
  81                thread_id="thread_id",
  82                assistant_id="assistant_id",
  83            )
  84
  85        assert response.is_closed is True
  86        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
  87        run = response.parse()
  88        assert_matches_type(Run, run, path=["response"])
  89
  90    @parametrize
  91    def test_streaming_response_create_overload_1(self, client: OpenAI) -> None:
  92        with pytest.warns(DeprecationWarning):
  93            with client.beta.threads.runs.with_streaming_response.create(
  94                thread_id="thread_id",
  95                assistant_id="assistant_id",
  96            ) as response:
  97                assert not response.is_closed
  98                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
  99
 100                run = response.parse()
 101                assert_matches_type(Run, run, path=["response"])
 102
 103        assert cast(Any, response.is_closed) is True
 104
 105    @parametrize
 106    def test_path_params_create_overload_1(self, client: OpenAI) -> None:
 107        with pytest.warns(DeprecationWarning):
 108            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 109                client.beta.threads.runs.with_raw_response.create(
 110                    thread_id="",
 111                    assistant_id="assistant_id",
 112                )
 113
 114    @parametrize
 115    def test_method_create_overload_2(self, client: OpenAI) -> None:
 116        with pytest.warns(DeprecationWarning):
 117            run_stream = client.beta.threads.runs.create(
 118                thread_id="thread_id",
 119                assistant_id="assistant_id",
 120                stream=True,
 121            )
 122
 123        run_stream.response.close()
 124
 125    @parametrize
 126    def test_method_create_with_all_params_overload_2(self, client: OpenAI) -> None:
 127        with pytest.warns(DeprecationWarning):
 128            run_stream = client.beta.threads.runs.create(
 129                thread_id="thread_id",
 130                assistant_id="assistant_id",
 131                stream=True,
 132                include=["step_details.tool_calls[*].file_search.results[*].content"],
 133                additional_instructions="additional_instructions",
 134                additional_messages=[
 135                    {
 136                        "content": "string",
 137                        "role": "user",
 138                        "attachments": [
 139                            {
 140                                "file_id": "file_id",
 141                                "tools": [{"type": "code_interpreter"}],
 142                            }
 143                        ],
 144                        "metadata": {"foo": "string"},
 145                    }
 146                ],
 147                instructions="instructions",
 148                max_completion_tokens=256,
 149                max_prompt_tokens=256,
 150                metadata={"foo": "string"},
 151                model="string",
 152                parallel_tool_calls=True,
 153                reasoning_effort="none",
 154                response_format="auto",
 155                temperature=1,
 156                tool_choice="none",
 157                tools=[{"type": "code_interpreter"}],
 158                top_p=1,
 159                truncation_strategy={
 160                    "type": "auto",
 161                    "last_messages": 1,
 162                },
 163            )
 164
 165        run_stream.response.close()
 166
 167    @parametrize
 168    def test_raw_response_create_overload_2(self, client: OpenAI) -> None:
 169        with pytest.warns(DeprecationWarning):
 170            response = client.beta.threads.runs.with_raw_response.create(
 171                thread_id="thread_id",
 172                assistant_id="assistant_id",
 173                stream=True,
 174            )
 175
 176        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 177        stream = response.parse()
 178        stream.close()
 179
 180    @parametrize
 181    def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
 182        with pytest.warns(DeprecationWarning):
 183            with client.beta.threads.runs.with_streaming_response.create(
 184                thread_id="thread_id",
 185                assistant_id="assistant_id",
 186                stream=True,
 187            ) as response:
 188                assert not response.is_closed
 189                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 190
 191                stream = response.parse()
 192                stream.close()
 193
 194        assert cast(Any, response.is_closed) is True
 195
 196    @parametrize
 197    def test_path_params_create_overload_2(self, client: OpenAI) -> None:
 198        with pytest.warns(DeprecationWarning):
 199            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 200                client.beta.threads.runs.with_raw_response.create(
 201                    thread_id="",
 202                    assistant_id="assistant_id",
 203                    stream=True,
 204                )
 205
 206    @parametrize
 207    def test_method_retrieve(self, client: OpenAI) -> None:
 208        with pytest.warns(DeprecationWarning):
 209            run = client.beta.threads.runs.retrieve(
 210                run_id="run_id",
 211                thread_id="thread_id",
 212            )
 213
 214        assert_matches_type(Run, run, path=["response"])
 215
 216    @parametrize
 217    def test_raw_response_retrieve(self, client: OpenAI) -> None:
 218        with pytest.warns(DeprecationWarning):
 219            response = client.beta.threads.runs.with_raw_response.retrieve(
 220                run_id="run_id",
 221                thread_id="thread_id",
 222            )
 223
 224        assert response.is_closed is True
 225        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 226        run = response.parse()
 227        assert_matches_type(Run, run, path=["response"])
 228
 229    @parametrize
 230    def test_streaming_response_retrieve(self, client: OpenAI) -> None:
 231        with pytest.warns(DeprecationWarning):
 232            with client.beta.threads.runs.with_streaming_response.retrieve(
 233                run_id="run_id",
 234                thread_id="thread_id",
 235            ) as response:
 236                assert not response.is_closed
 237                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 238
 239                run = response.parse()
 240                assert_matches_type(Run, run, path=["response"])
 241
 242        assert cast(Any, response.is_closed) is True
 243
 244    @parametrize
 245    def test_path_params_retrieve(self, client: OpenAI) -> None:
 246        with pytest.warns(DeprecationWarning):
 247            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 248                client.beta.threads.runs.with_raw_response.retrieve(
 249                    run_id="run_id",
 250                    thread_id="",
 251                )
 252
 253            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
 254                client.beta.threads.runs.with_raw_response.retrieve(
 255                    run_id="",
 256                    thread_id="thread_id",
 257                )
 258
 259    @parametrize
 260    def test_method_update(self, client: OpenAI) -> None:
 261        with pytest.warns(DeprecationWarning):
 262            run = client.beta.threads.runs.update(
 263                run_id="run_id",
 264                thread_id="thread_id",
 265            )
 266
 267        assert_matches_type(Run, run, path=["response"])
 268
 269    @parametrize
 270    def test_method_update_with_all_params(self, client: OpenAI) -> None:
 271        with pytest.warns(DeprecationWarning):
 272            run = client.beta.threads.runs.update(
 273                run_id="run_id",
 274                thread_id="thread_id",
 275                metadata={"foo": "string"},
 276            )
 277
 278        assert_matches_type(Run, run, path=["response"])
 279
 280    @parametrize
 281    def test_raw_response_update(self, client: OpenAI) -> None:
 282        with pytest.warns(DeprecationWarning):
 283            response = client.beta.threads.runs.with_raw_response.update(
 284                run_id="run_id",
 285                thread_id="thread_id",
 286            )
 287
 288        assert response.is_closed is True
 289        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 290        run = response.parse()
 291        assert_matches_type(Run, run, path=["response"])
 292
 293    @parametrize
 294    def test_streaming_response_update(self, client: OpenAI) -> None:
 295        with pytest.warns(DeprecationWarning):
 296            with client.beta.threads.runs.with_streaming_response.update(
 297                run_id="run_id",
 298                thread_id="thread_id",
 299            ) as response:
 300                assert not response.is_closed
 301                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 302
 303                run = response.parse()
 304                assert_matches_type(Run, run, path=["response"])
 305
 306        assert cast(Any, response.is_closed) is True
 307
 308    @parametrize
 309    def test_path_params_update(self, client: OpenAI) -> None:
 310        with pytest.warns(DeprecationWarning):
 311            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 312                client.beta.threads.runs.with_raw_response.update(
 313                    run_id="run_id",
 314                    thread_id="",
 315                )
 316
 317            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
 318                client.beta.threads.runs.with_raw_response.update(
 319                    run_id="",
 320                    thread_id="thread_id",
 321                )
 322
 323    @parametrize
 324    def test_method_list(self, client: OpenAI) -> None:
 325        with pytest.warns(DeprecationWarning):
 326            run = client.beta.threads.runs.list(
 327                thread_id="thread_id",
 328            )
 329
 330        assert_matches_type(SyncCursorPage[Run], run, path=["response"])
 331
 332    @parametrize
 333    def test_method_list_with_all_params(self, client: OpenAI) -> None:
 334        with pytest.warns(DeprecationWarning):
 335            run = client.beta.threads.runs.list(
 336                thread_id="thread_id",
 337                after="after",
 338                before="before",
 339                limit=0,
 340                order="asc",
 341            )
 342
 343        assert_matches_type(SyncCursorPage[Run], run, path=["response"])
 344
 345    @parametrize
 346    def test_raw_response_list(self, client: OpenAI) -> None:
 347        with pytest.warns(DeprecationWarning):
 348            response = client.beta.threads.runs.with_raw_response.list(
 349                thread_id="thread_id",
 350            )
 351
 352        assert response.is_closed is True
 353        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 354        run = response.parse()
 355        assert_matches_type(SyncCursorPage[Run], run, path=["response"])
 356
 357    @parametrize
 358    def test_streaming_response_list(self, client: OpenAI) -> None:
 359        with pytest.warns(DeprecationWarning):
 360            with client.beta.threads.runs.with_streaming_response.list(
 361                thread_id="thread_id",
 362            ) as response:
 363                assert not response.is_closed
 364                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 365
 366                run = response.parse()
 367                assert_matches_type(SyncCursorPage[Run], run, path=["response"])
 368
 369        assert cast(Any, response.is_closed) is True
 370
 371    @parametrize
 372    def test_path_params_list(self, client: OpenAI) -> None:
 373        with pytest.warns(DeprecationWarning):
 374            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 375                client.beta.threads.runs.with_raw_response.list(
 376                    thread_id="",
 377                )
 378
 379    @parametrize
 380    def test_method_cancel(self, client: OpenAI) -> None:
 381        with pytest.warns(DeprecationWarning):
 382            run = client.beta.threads.runs.cancel(
 383                run_id="run_id",
 384                thread_id="thread_id",
 385            )
 386
 387        assert_matches_type(Run, run, path=["response"])
 388
 389    @parametrize
 390    def test_raw_response_cancel(self, client: OpenAI) -> None:
 391        with pytest.warns(DeprecationWarning):
 392            response = client.beta.threads.runs.with_raw_response.cancel(
 393                run_id="run_id",
 394                thread_id="thread_id",
 395            )
 396
 397        assert response.is_closed is True
 398        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 399        run = response.parse()
 400        assert_matches_type(Run, run, path=["response"])
 401
 402    @parametrize
 403    def test_streaming_response_cancel(self, client: OpenAI) -> None:
 404        with pytest.warns(DeprecationWarning):
 405            with client.beta.threads.runs.with_streaming_response.cancel(
 406                run_id="run_id",
 407                thread_id="thread_id",
 408            ) as response:
 409                assert not response.is_closed
 410                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 411
 412                run = response.parse()
 413                assert_matches_type(Run, run, path=["response"])
 414
 415        assert cast(Any, response.is_closed) is True
 416
 417    @parametrize
 418    def test_path_params_cancel(self, client: OpenAI) -> None:
 419        with pytest.warns(DeprecationWarning):
 420            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 421                client.beta.threads.runs.with_raw_response.cancel(
 422                    run_id="run_id",
 423                    thread_id="",
 424                )
 425
 426            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
 427                client.beta.threads.runs.with_raw_response.cancel(
 428                    run_id="",
 429                    thread_id="thread_id",
 430                )
 431
 432    @parametrize
 433    def test_method_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
 434        with pytest.warns(DeprecationWarning):
 435            run = client.beta.threads.runs.submit_tool_outputs(
 436                run_id="run_id",
 437                thread_id="thread_id",
 438                tool_outputs=[{}],
 439            )
 440
 441        assert_matches_type(Run, run, path=["response"])
 442
 443    @parametrize
 444    def test_method_submit_tool_outputs_with_all_params_overload_1(self, client: OpenAI) -> None:
 445        with pytest.warns(DeprecationWarning):
 446            run = client.beta.threads.runs.submit_tool_outputs(
 447                run_id="run_id",
 448                thread_id="thread_id",
 449                tool_outputs=[
 450                    {
 451                        "output": "output",
 452                        "tool_call_id": "tool_call_id",
 453                    }
 454                ],
 455                stream=False,
 456            )
 457
 458        assert_matches_type(Run, run, path=["response"])
 459
 460    @parametrize
 461    def test_raw_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
 462        with pytest.warns(DeprecationWarning):
 463            response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
 464                run_id="run_id",
 465                thread_id="thread_id",
 466                tool_outputs=[{}],
 467            )
 468
 469        assert response.is_closed is True
 470        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 471        run = response.parse()
 472        assert_matches_type(Run, run, path=["response"])
 473
 474    @parametrize
 475    def test_streaming_response_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
 476        with pytest.warns(DeprecationWarning):
 477            with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
 478                run_id="run_id",
 479                thread_id="thread_id",
 480                tool_outputs=[{}],
 481            ) as response:
 482                assert not response.is_closed
 483                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 484
 485                run = response.parse()
 486                assert_matches_type(Run, run, path=["response"])
 487
 488        assert cast(Any, response.is_closed) is True
 489
 490    @parametrize
 491    def test_path_params_submit_tool_outputs_overload_1(self, client: OpenAI) -> None:
 492        with pytest.warns(DeprecationWarning):
 493            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 494                client.beta.threads.runs.with_raw_response.submit_tool_outputs(
 495                    run_id="run_id",
 496                    thread_id="",
 497                    tool_outputs=[{}],
 498                )
 499
 500            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
 501                client.beta.threads.runs.with_raw_response.submit_tool_outputs(
 502                    run_id="",
 503                    thread_id="thread_id",
 504                    tool_outputs=[{}],
 505                )
 506
 507    @parametrize
 508    def test_method_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
 509        with pytest.warns(DeprecationWarning):
 510            run_stream = client.beta.threads.runs.submit_tool_outputs(
 511                run_id="run_id",
 512                thread_id="thread_id",
 513                stream=True,
 514                tool_outputs=[{}],
 515            )
 516
 517        run_stream.response.close()
 518
 519    @parametrize
 520    def test_raw_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
 521        with pytest.warns(DeprecationWarning):
 522            response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
 523                run_id="run_id",
 524                thread_id="thread_id",
 525                stream=True,
 526                tool_outputs=[{}],
 527            )
 528
 529        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 530        stream = response.parse()
 531        stream.close()
 532
 533    @parametrize
 534    def test_streaming_response_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
 535        with pytest.warns(DeprecationWarning):
 536            with client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
 537                run_id="run_id",
 538                thread_id="thread_id",
 539                stream=True,
 540                tool_outputs=[{}],
 541            ) as response:
 542                assert not response.is_closed
 543                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 544
 545                stream = response.parse()
 546                stream.close()
 547
 548        assert cast(Any, response.is_closed) is True
 549
 550    @parametrize
 551    def test_path_params_submit_tool_outputs_overload_2(self, client: OpenAI) -> None:
 552        with pytest.warns(DeprecationWarning):
 553            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 554                client.beta.threads.runs.with_raw_response.submit_tool_outputs(
 555                    run_id="run_id",
 556                    thread_id="",
 557                    stream=True,
 558                    tool_outputs=[{}],
 559                )
 560
 561            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
 562                client.beta.threads.runs.with_raw_response.submit_tool_outputs(
 563                    run_id="",
 564                    thread_id="thread_id",
 565                    stream=True,
 566                    tool_outputs=[{}],
 567                )
 568
 569
 570class TestAsyncRuns:
 571    parametrize = pytest.mark.parametrize(
 572        "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
 573    )
 574
 575    @parametrize
 576    async def test_method_create_overload_1(self, async_client: AsyncOpenAI) -> None:
 577        with pytest.warns(DeprecationWarning):
 578            run = await async_client.beta.threads.runs.create(
 579                thread_id="thread_id",
 580                assistant_id="assistant_id",
 581            )
 582
 583        assert_matches_type(Run, run, path=["response"])
 584
 585    @parametrize
 586    async def test_method_create_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
 587        with pytest.warns(DeprecationWarning):
 588            run = await async_client.beta.threads.runs.create(
 589                thread_id="thread_id",
 590                assistant_id="assistant_id",
 591                include=["step_details.tool_calls[*].file_search.results[*].content"],
 592                additional_instructions="additional_instructions",
 593                additional_messages=[
 594                    {
 595                        "content": "string",
 596                        "role": "user",
 597                        "attachments": [
 598                            {
 599                                "file_id": "file_id",
 600                                "tools": [{"type": "code_interpreter"}],
 601                            }
 602                        ],
 603                        "metadata": {"foo": "string"},
 604                    }
 605                ],
 606                instructions="instructions",
 607                max_completion_tokens=256,
 608                max_prompt_tokens=256,
 609                metadata={"foo": "string"},
 610                model="string",
 611                parallel_tool_calls=True,
 612                reasoning_effort="none",
 613                response_format="auto",
 614                stream=False,
 615                temperature=1,
 616                tool_choice="none",
 617                tools=[{"type": "code_interpreter"}],
 618                top_p=1,
 619                truncation_strategy={
 620                    "type": "auto",
 621                    "last_messages": 1,
 622                },
 623            )
 624
 625        assert_matches_type(Run, run, path=["response"])
 626
 627    @parametrize
 628    async def test_raw_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
 629        with pytest.warns(DeprecationWarning):
 630            response = await async_client.beta.threads.runs.with_raw_response.create(
 631                thread_id="thread_id",
 632                assistant_id="assistant_id",
 633            )
 634
 635        assert response.is_closed is True
 636        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 637        run = response.parse()
 638        assert_matches_type(Run, run, path=["response"])
 639
 640    @parametrize
 641    async def test_streaming_response_create_overload_1(self, async_client: AsyncOpenAI) -> None:
 642        with pytest.warns(DeprecationWarning):
 643            async with async_client.beta.threads.runs.with_streaming_response.create(
 644                thread_id="thread_id",
 645                assistant_id="assistant_id",
 646            ) as response:
 647                assert not response.is_closed
 648                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 649
 650                run = await response.parse()
 651                assert_matches_type(Run, run, path=["response"])
 652
 653        assert cast(Any, response.is_closed) is True
 654
 655    @parametrize
 656    async def test_path_params_create_overload_1(self, async_client: AsyncOpenAI) -> None:
 657        with pytest.warns(DeprecationWarning):
 658            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 659                await async_client.beta.threads.runs.with_raw_response.create(
 660                    thread_id="",
 661                    assistant_id="assistant_id",
 662                )
 663
 664    @parametrize
 665    async def test_method_create_overload_2(self, async_client: AsyncOpenAI) -> None:
 666        with pytest.warns(DeprecationWarning):
 667            run_stream = await async_client.beta.threads.runs.create(
 668                thread_id="thread_id",
 669                assistant_id="assistant_id",
 670                stream=True,
 671            )
 672
 673        await run_stream.response.aclose()
 674
 675    @parametrize
 676    async def test_method_create_with_all_params_overload_2(self, async_client: AsyncOpenAI) -> None:
 677        with pytest.warns(DeprecationWarning):
 678            run_stream = await async_client.beta.threads.runs.create(
 679                thread_id="thread_id",
 680                assistant_id="assistant_id",
 681                stream=True,
 682                include=["step_details.tool_calls[*].file_search.results[*].content"],
 683                additional_instructions="additional_instructions",
 684                additional_messages=[
 685                    {
 686                        "content": "string",
 687                        "role": "user",
 688                        "attachments": [
 689                            {
 690                                "file_id": "file_id",
 691                                "tools": [{"type": "code_interpreter"}],
 692                            }
 693                        ],
 694                        "metadata": {"foo": "string"},
 695                    }
 696                ],
 697                instructions="instructions",
 698                max_completion_tokens=256,
 699                max_prompt_tokens=256,
 700                metadata={"foo": "string"},
 701                model="string",
 702                parallel_tool_calls=True,
 703                reasoning_effort="none",
 704                response_format="auto",
 705                temperature=1,
 706                tool_choice="none",
 707                tools=[{"type": "code_interpreter"}],
 708                top_p=1,
 709                truncation_strategy={
 710                    "type": "auto",
 711                    "last_messages": 1,
 712                },
 713            )
 714
 715        await run_stream.response.aclose()
 716
 717    @parametrize
 718    async def test_raw_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
 719        with pytest.warns(DeprecationWarning):
 720            response = await async_client.beta.threads.runs.with_raw_response.create(
 721                thread_id="thread_id",
 722                assistant_id="assistant_id",
 723                stream=True,
 724            )
 725
 726        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 727        stream = response.parse()
 728        await stream.close()
 729
 730    @parametrize
 731    async def test_streaming_response_create_overload_2(self, async_client: AsyncOpenAI) -> None:
 732        with pytest.warns(DeprecationWarning):
 733            async with async_client.beta.threads.runs.with_streaming_response.create(
 734                thread_id="thread_id",
 735                assistant_id="assistant_id",
 736                stream=True,
 737            ) as response:
 738                assert not response.is_closed
 739                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 740
 741                stream = await response.parse()
 742                await stream.close()
 743
 744        assert cast(Any, response.is_closed) is True
 745
 746    @parametrize
 747    async def test_path_params_create_overload_2(self, async_client: AsyncOpenAI) -> None:
 748        with pytest.warns(DeprecationWarning):
 749            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 750                await async_client.beta.threads.runs.with_raw_response.create(
 751                    thread_id="",
 752                    assistant_id="assistant_id",
 753                    stream=True,
 754                )
 755
 756    @parametrize
 757    async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
 758        with pytest.warns(DeprecationWarning):
 759            run = await async_client.beta.threads.runs.retrieve(
 760                run_id="run_id",
 761                thread_id="thread_id",
 762            )
 763
 764        assert_matches_type(Run, run, path=["response"])
 765
 766    @parametrize
 767    async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
 768        with pytest.warns(DeprecationWarning):
 769            response = await async_client.beta.threads.runs.with_raw_response.retrieve(
 770                run_id="run_id",
 771                thread_id="thread_id",
 772            )
 773
 774        assert response.is_closed is True
 775        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 776        run = response.parse()
 777        assert_matches_type(Run, run, path=["response"])
 778
 779    @parametrize
 780    async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
 781        with pytest.warns(DeprecationWarning):
 782            async with async_client.beta.threads.runs.with_streaming_response.retrieve(
 783                run_id="run_id",
 784                thread_id="thread_id",
 785            ) as response:
 786                assert not response.is_closed
 787                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 788
 789                run = await response.parse()
 790                assert_matches_type(Run, run, path=["response"])
 791
 792        assert cast(Any, response.is_closed) is True
 793
 794    @parametrize
 795    async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
 796        with pytest.warns(DeprecationWarning):
 797            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 798                await async_client.beta.threads.runs.with_raw_response.retrieve(
 799                    run_id="run_id",
 800                    thread_id="",
 801                )
 802
 803            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
 804                await async_client.beta.threads.runs.with_raw_response.retrieve(
 805                    run_id="",
 806                    thread_id="thread_id",
 807                )
 808
 809    @parametrize
 810    async def test_method_update(self, async_client: AsyncOpenAI) -> None:
 811        with pytest.warns(DeprecationWarning):
 812            run = await async_client.beta.threads.runs.update(
 813                run_id="run_id",
 814                thread_id="thread_id",
 815            )
 816
 817        assert_matches_type(Run, run, path=["response"])
 818
 819    @parametrize
 820    async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
 821        with pytest.warns(DeprecationWarning):
 822            run = await async_client.beta.threads.runs.update(
 823                run_id="run_id",
 824                thread_id="thread_id",
 825                metadata={"foo": "string"},
 826            )
 827
 828        assert_matches_type(Run, run, path=["response"])
 829
 830    @parametrize
 831    async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
 832        with pytest.warns(DeprecationWarning):
 833            response = await async_client.beta.threads.runs.with_raw_response.update(
 834                run_id="run_id",
 835                thread_id="thread_id",
 836            )
 837
 838        assert response.is_closed is True
 839        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 840        run = response.parse()
 841        assert_matches_type(Run, run, path=["response"])
 842
 843    @parametrize
 844    async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
 845        with pytest.warns(DeprecationWarning):
 846            async with async_client.beta.threads.runs.with_streaming_response.update(
 847                run_id="run_id",
 848                thread_id="thread_id",
 849            ) as response:
 850                assert not response.is_closed
 851                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 852
 853                run = await response.parse()
 854                assert_matches_type(Run, run, path=["response"])
 855
 856        assert cast(Any, response.is_closed) is True
 857
 858    @parametrize
 859    async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
 860        with pytest.warns(DeprecationWarning):
 861            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 862                await async_client.beta.threads.runs.with_raw_response.update(
 863                    run_id="run_id",
 864                    thread_id="",
 865                )
 866
 867            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
 868                await async_client.beta.threads.runs.with_raw_response.update(
 869                    run_id="",
 870                    thread_id="thread_id",
 871                )
 872
 873    @parametrize
 874    async def test_method_list(self, async_client: AsyncOpenAI) -> None:
 875        with pytest.warns(DeprecationWarning):
 876            run = await async_client.beta.threads.runs.list(
 877                thread_id="thread_id",
 878            )
 879
 880        assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
 881
 882    @parametrize
 883    async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
 884        with pytest.warns(DeprecationWarning):
 885            run = await async_client.beta.threads.runs.list(
 886                thread_id="thread_id",
 887                after="after",
 888                before="before",
 889                limit=0,
 890                order="asc",
 891            )
 892
 893        assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
 894
 895    @parametrize
 896    async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
 897        with pytest.warns(DeprecationWarning):
 898            response = await async_client.beta.threads.runs.with_raw_response.list(
 899                thread_id="thread_id",
 900            )
 901
 902        assert response.is_closed is True
 903        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 904        run = response.parse()
 905        assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
 906
 907    @parametrize
 908    async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
 909        with pytest.warns(DeprecationWarning):
 910            async with async_client.beta.threads.runs.with_streaming_response.list(
 911                thread_id="thread_id",
 912            ) as response:
 913                assert not response.is_closed
 914                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 915
 916                run = await response.parse()
 917                assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
 918
 919        assert cast(Any, response.is_closed) is True
 920
 921    @parametrize
 922    async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
 923        with pytest.warns(DeprecationWarning):
 924            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 925                await async_client.beta.threads.runs.with_raw_response.list(
 926                    thread_id="",
 927                )
 928
 929    @parametrize
 930    async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
 931        with pytest.warns(DeprecationWarning):
 932            run = await async_client.beta.threads.runs.cancel(
 933                run_id="run_id",
 934                thread_id="thread_id",
 935            )
 936
 937        assert_matches_type(Run, run, path=["response"])
 938
 939    @parametrize
 940    async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
 941        with pytest.warns(DeprecationWarning):
 942            response = await async_client.beta.threads.runs.with_raw_response.cancel(
 943                run_id="run_id",
 944                thread_id="thread_id",
 945            )
 946
 947        assert response.is_closed is True
 948        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 949        run = response.parse()
 950        assert_matches_type(Run, run, path=["response"])
 951
 952    @parametrize
 953    async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
 954        with pytest.warns(DeprecationWarning):
 955            async with async_client.beta.threads.runs.with_streaming_response.cancel(
 956                run_id="run_id",
 957                thread_id="thread_id",
 958            ) as response:
 959                assert not response.is_closed
 960                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
 961
 962                run = await response.parse()
 963                assert_matches_type(Run, run, path=["response"])
 964
 965        assert cast(Any, response.is_closed) is True
 966
 967    @parametrize
 968    async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
 969        with pytest.warns(DeprecationWarning):
 970            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
 971                await async_client.beta.threads.runs.with_raw_response.cancel(
 972                    run_id="run_id",
 973                    thread_id="",
 974                )
 975
 976            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
 977                await async_client.beta.threads.runs.with_raw_response.cancel(
 978                    run_id="",
 979                    thread_id="thread_id",
 980                )
 981
 982    @parametrize
 983    async def test_method_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
 984        with pytest.warns(DeprecationWarning):
 985            run = await async_client.beta.threads.runs.submit_tool_outputs(
 986                run_id="run_id",
 987                thread_id="thread_id",
 988                tool_outputs=[{}],
 989            )
 990
 991        assert_matches_type(Run, run, path=["response"])
 992
 993    @parametrize
 994    async def test_method_submit_tool_outputs_with_all_params_overload_1(self, async_client: AsyncOpenAI) -> None:
 995        with pytest.warns(DeprecationWarning):
 996            run = await async_client.beta.threads.runs.submit_tool_outputs(
 997                run_id="run_id",
 998                thread_id="thread_id",
 999                tool_outputs=[
1000                    {
1001                        "output": "output",
1002                        "tool_call_id": "tool_call_id",
1003                    }
1004                ],
1005                stream=False,
1006            )
1007
1008        assert_matches_type(Run, run, path=["response"])
1009
1010    @parametrize
1011    async def test_raw_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
1012        with pytest.warns(DeprecationWarning):
1013            response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1014                run_id="run_id",
1015                thread_id="thread_id",
1016                tool_outputs=[{}],
1017            )
1018
1019        assert response.is_closed is True
1020        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1021        run = response.parse()
1022        assert_matches_type(Run, run, path=["response"])
1023
1024    @parametrize
1025    async def test_streaming_response_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
1026        with pytest.warns(DeprecationWarning):
1027            async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
1028                run_id="run_id",
1029                thread_id="thread_id",
1030                tool_outputs=[{}],
1031            ) as response:
1032                assert not response.is_closed
1033                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1034
1035                run = await response.parse()
1036                assert_matches_type(Run, run, path=["response"])
1037
1038        assert cast(Any, response.is_closed) is True
1039
1040    @parametrize
1041    async def test_path_params_submit_tool_outputs_overload_1(self, async_client: AsyncOpenAI) -> None:
1042        with pytest.warns(DeprecationWarning):
1043            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1044                await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1045                    run_id="run_id",
1046                    thread_id="",
1047                    tool_outputs=[{}],
1048                )
1049
1050            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
1051                await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1052                    run_id="",
1053                    thread_id="thread_id",
1054                    tool_outputs=[{}],
1055                )
1056
1057    @parametrize
1058    async def test_method_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
1059        with pytest.warns(DeprecationWarning):
1060            run_stream = await async_client.beta.threads.runs.submit_tool_outputs(
1061                run_id="run_id",
1062                thread_id="thread_id",
1063                stream=True,
1064                tool_outputs=[{}],
1065            )
1066
1067        await run_stream.response.aclose()
1068
1069    @parametrize
1070    async def test_raw_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
1071        with pytest.warns(DeprecationWarning):
1072            response = await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1073                run_id="run_id",
1074                thread_id="thread_id",
1075                stream=True,
1076                tool_outputs=[{}],
1077            )
1078
1079        assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1080        stream = response.parse()
1081        await stream.close()
1082
1083    @parametrize
1084    async def test_streaming_response_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
1085        with pytest.warns(DeprecationWarning):
1086            async with async_client.beta.threads.runs.with_streaming_response.submit_tool_outputs(
1087                run_id="run_id",
1088                thread_id="thread_id",
1089                stream=True,
1090                tool_outputs=[{}],
1091            ) as response:
1092                assert not response.is_closed
1093                assert response.http_request.headers.get("X-Stainless-Lang") == "python"
1094
1095                stream = await response.parse()
1096                await stream.close()
1097
1098        assert cast(Any, response.is_closed) is True
1099
1100    @parametrize
1101    async def test_path_params_submit_tool_outputs_overload_2(self, async_client: AsyncOpenAI) -> None:
1102        with pytest.warns(DeprecationWarning):
1103            with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
1104                await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1105                    run_id="run_id",
1106                    thread_id="",
1107                    stream=True,
1108                    tool_outputs=[{}],
1109                )
1110
1111            with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
1112                await async_client.beta.threads.runs.with_raw_response.submit_tool_outputs(
1113                    run_id="",
1114                    thread_id="thread_id",
1115                    stream=True,
1116                    tool_outputs=[{}],
1117                )