From ecb6141bd54f318620a50a65c379583193383ba8 Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Sat, 12 Oct 2024 19:57:48 +0000 Subject: [PATCH] fix: allow header params to override default headers (#690) --- .../resources/beta/messages/batches.py | 20 +++++++++---------- .../resources/beta/prompt_caching/messages.py | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/anthropic/resources/beta/messages/batches.py b/src/anthropic/resources/beta/messages/batches.py index 6fed43b2..afa7f8d9 100644 --- a/src/anthropic/resources/beta/messages/batches.py +++ b/src/anthropic/resources/beta/messages/batches.py @@ -81,11 +81,11 @@ def create( timeout: Override the client-level default timeout for this request, in seconds """ - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return self._post( "/v1/messages/batches?beta=true", body=maybe_transform({"requests": requests}, batch_create_params.BatchCreateParams), @@ -128,11 +128,11 @@ def retrieve( """ if not message_batch_id: raise ValueError(f"Expected a non-empty value for `message_batch_id` but received {message_batch_id!r}") - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return self._get( f"/v1/messages/batches/{message_batch_id}?beta=true", options=make_request_options( @@ -179,11 +179,11 @@ def list( timeout: Override the client-level default timeout for this request, in seconds """ - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return self._get_api_list( "/v1/messages/batches?beta=true", page=SyncPage[BetaMessageBatch], @@ -236,11 +236,11 @@ def cancel( """ if not message_batch_id: raise ValueError(f"Expected a non-empty value for `message_batch_id` but received {message_batch_id!r}") - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return self._post( f"/v1/messages/batches/{message_batch_id}/cancel?beta=true", options=make_request_options( @@ -290,12 +290,12 @@ def results( f"No `results_url` for the given batch; Has it finished processing? {batch.processing_status}" ) - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = {"Accept": "application/binary", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return self._get( batch.results_url, options=make_request_options( @@ -358,11 +358,11 @@ async def create( timeout: Override the client-level default timeout for this request, in seconds """ - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return await self._post( "/v1/messages/batches?beta=true", body=await async_maybe_transform({"requests": requests}, batch_create_params.BatchCreateParams), @@ -405,11 +405,11 @@ async def retrieve( """ if not message_batch_id: raise ValueError(f"Expected a non-empty value for `message_batch_id` but received {message_batch_id!r}") - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return await self._get( f"/v1/messages/batches/{message_batch_id}?beta=true", options=make_request_options( @@ -456,11 +456,11 @@ def list( timeout: Override the client-level default timeout for this request, in seconds """ - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return self._get_api_list( "/v1/messages/batches?beta=true", page=AsyncPage[BetaMessageBatch], @@ -513,11 +513,11 @@ async def cancel( """ if not message_batch_id: raise ValueError(f"Expected a non-empty value for `message_batch_id` but received {message_batch_id!r}") - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return await self._post( f"/v1/messages/batches/{message_batch_id}/cancel?beta=true", options=make_request_options( @@ -567,12 +567,12 @@ async def results( f"No `results_url` for the given batch; Has it finished processing? {batch.processing_status}" ) - extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} extra_headers = {"Accept": "application/binary", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "message-batches-2024-09-24", **(extra_headers or {})} return await self._get( batch.results_url, options=make_request_options( diff --git a/src/anthropic/resources/beta/prompt_caching/messages.py b/src/anthropic/resources/beta/prompt_caching/messages.py index 3a7d8af4..0584200b 100644 --- a/src/anthropic/resources/beta/prompt_caching/messages.py +++ b/src/anthropic/resources/beta/prompt_caching/messages.py @@ -878,11 +878,11 @@ def create( ) -> PromptCachingBetaMessage | Stream[RawPromptCachingBetaMessageStreamEvent]: if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT: timeout = 600 - extra_headers = {"anthropic-beta": "prompt-caching-2024-07-31", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "prompt-caching-2024-07-31", **(extra_headers or {})} return self._post( "/v1/messages?beta=prompt_caching", body=maybe_transform( @@ -1808,11 +1808,11 @@ async def create( ) -> PromptCachingBetaMessage | AsyncStream[RawPromptCachingBetaMessageStreamEvent]: if not is_given(timeout) and self._client.timeout == DEFAULT_TIMEOUT: timeout = 600 - extra_headers = {"anthropic-beta": "prompt-caching-2024-07-31", **(extra_headers or {})} extra_headers = { **strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}), **(extra_headers or {}), } + extra_headers = {"anthropic-beta": "prompt-caching-2024-07-31", **(extra_headers or {})} return await self._post( "/v1/messages?beta=prompt_caching", body=await async_maybe_transform(