anthropic-sdk-python icon indicating copy to clipboard operation
anthropic-sdk-python copied to clipboard

Vertex "Could not resolve API token from the environment"

Open kkhangv opened this issue 1 year ago • 1 comments

Screenshot 2024-07-10 at 4 56 29 PM For some reasons after the update, Vertex now keeps asking for API Tokens but we are using GCP service account to authorize VertexAI and it was fine until this morning. Did the new release change or require something new?

kkhangv avatar Jul 10 '24 20:07 kkhangv

I downgraded to the previous version and it worked. Hopefully not a wide spread Issue.

kkhangv avatar Jul 10 '24 21:07 kkhangv

Hey @kkhangv, sorry about this, can you share more details on how you're authenticating? Where is that error coming from - is there a stack trace?

Nothing new should be required in the last release but we did change some of our logic around handling google credentials but it was not intentionally breaking.

RobertCraigie avatar Jul 11 '24 09:07 RobertCraigie

Using oauth2:

`from google.oauth2 import service_account from google.auth.credentials import Credentials

def get_gcp_credentials() -> tuple[Credentials, str, str]: key_dict = {`

kkhangv avatar Jul 11 '24 22:07 kkhangv

Just hit this as well. Can confirm downgrading to anthropic==0.30 works here.

Service account has the "Vertex AI User" role in gcp, and my auth is set up like this:

claude = AnthropicVertex(region=region, project_id=project, credentials=google.auth.load_credentials_from_file('credentials.json', scopes=["https://www.googleapis.com/auth/cloud-platform"])[0])

hantusk avatar Jul 17 '24 06:07 hantusk

Thanks both, unfortunately I'm struggling to reproduce this but I've merged a change that I think should fix this issue.

Would anyone be able to test this out and let me know if it works for you? thanks!

python -m pip install -U git+https://github.com/anthropics/anthropic-sdk-python@next

RobertCraigie avatar Jul 17 '24 09:07 RobertCraigie

Yup that works for me 👍 consider having a separate version number or suffix for the next branch.

hantusk avatar Jul 17 '24 09:07 hantusk

Awesome, thanks!

consider having a separate version number or suffix for the next branch.

Ah we have a separate PR that includes the version bump: https://github.com/anthropics/anthropic-sdk-python/pull/595

So until that's released (hopefully later today) you can use that branch if you want the version bump

python -m pip install -U git+https://github.com/anthropics/anthropic-sdk-python@release-please--branches--main--changes--next

RobertCraigie avatar Jul 17 '24 09:07 RobertCraigie

v0.31.2 has been released with this fix!

RobertCraigie avatar Jul 17 '24 15:07 RobertCraigie

Amazing. Save lots of people! :)

kkhangv avatar Jul 17 '24 15:07 kkhangv