Skip to content

Commit

Permalink
fix(count_tokens): correctly set beta header
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Nov 1, 2024
1 parent e4856dd commit e5b4b54
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/anthropic/resources/beta/messages/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from typing import List, Union, Iterable
from itertools import chain
from typing_extensions import Literal, overload

import httpx
Expand Down Expand Up @@ -1124,9 +1125,16 @@ def count_tokens(
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}),
**strip_not_given(
{
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["token-counting-2024-11-01"]))
if is_given(betas)
else NOT_GIVEN
}
),
**(extra_headers or {}),
}
extra_headers = {"anthropic-beta": "token-counting-2024-11-01", **(extra_headers or {})}
return self._post(
"/v1/messages/count_tokens?beta=true",
body=maybe_transform(
Expand Down Expand Up @@ -2225,9 +2233,16 @@ async def count_tokens(
timeout: Override the client-level default timeout for this request, in seconds
"""
extra_headers = {
**strip_not_given({"anthropic-beta": ",".join(str(e) for e in betas) if is_given(betas) else NOT_GIVEN}),
**strip_not_given(
{
"anthropic-beta": ",".join(chain((str(e) for e in betas), ["token-counting-2024-11-01"]))
if is_given(betas)
else NOT_GIVEN
}
),
**(extra_headers or {}),
}
extra_headers = {"anthropic-beta": "token-counting-2024-11-01", **(extra_headers or {})}
return await self._post(
"/v1/messages/count_tokens?beta=true",
body=await async_maybe_transform(
Expand Down

0 comments on commit e5b4b54

Please sign in to comment.