You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried downgrading to v0.38.0, but anthropic threw the same error noted in #297, which requires the package to be upgraded for resolution. So we probably do need to update the code to use the new client.messages.count_tokens API.
Took a look into fixing this, but there isn't a clear-cut resolution path at the moment.
The built-in token counting functionality in Anthropic Python SDK has been removed entirely in favor of an server-side implementation in the Messages API. This means that users are now required to provide a separate Anthropic API key. And while the count_tokens API itself is stated free to use, any requests to it will still fail with a BadRequestError if the Anthropic account does not have sufficient funds.
Getting this error when using anthropic models from bedrock.py module of langchain.
The error comes from this module.
Looking at the anthropic code, the api for count_tokens has been changed and it needs to be updated in the utils.py for bedrock.
import anthropic
client = anthropic.Anthropic()
response = client.messages.count_tokens(
model="claude-3-5-sonnet-20241022",
system="You are a scientist",
messages=[{
"role": "user",
"content": "Hello, Claude"
}],
)
print(response.json())
The text was updated successfully, but these errors were encountered: