Skip to content

Commit

Permalink
fix: allow header params to override default headers (#690)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stainless Bot authored and stainless-app[bot] committed Oct 15, 2024
1 parent da840f1 commit ecb6141
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/anthropic/resources/beta/messages/batches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/anthropic/resources/beta/prompt_caching/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit ecb6141

Please sign in to comment.