Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Not able to use anthropic claude 3.5 model API

# pip install -U 'anthropic[vertex]'

import os

# Replace with the path to your service account JSON key file
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "C:/dev/gcpkey/radiant-oven-440907-u7-b59deb49881e.json"

from anthropic import AnthropicVertex

LOCATION= "us-central1" #"europe-west1" #or us-east5" # or

client = AnthropicVertex(region=LOCATION, project_id="radiant-oven-440907-u7")

message = client.messages.create(
  max_tokens=1024,
  messages=[
    {
      "role": "user",
      "content": "Send me a recipe for banana bread.",
    }
  ],
  model="claude-3-5-sonnet-v2@20241022",
)
print(message.model_dump_json(indent=2))
 
Getting below Error
 
Exception has occurred: BadRequestError
  •  
Error code: 400 - {'error': {'code': 400, 'message': 'Project `865461809122` is not allowed to use Publisher Model `projects/radiant-oven-440907-u7/locations/us-central1/publishers/anthropic/models/claude-3-5-sonnet-v2@20241022`', 'status': 'FAILED_PRECONDITION'}}
httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://us-central1-aiplatform.googleapis.com/v1/projects/radiant-oven-440907-u7/locations/us-centra...' For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400 During handling of the above exception, another exception occurred: File "C:\dev\alkason\scr\automated_trading_system\tests\test-anthropic.py", line 14, in <module> message = client.messages.create( ^^^^^^^^^^^^^^^^^^^^^^^ anthropic.BadRequestError: Error code: 400 - {'error': {'code': 400, 'message': 'Project `865461809122` is not allowed to use Publisher Model `projects/radiant-oven-440907-u7/locations/us-central1/publishers/anthropic/models/claude-3-5-sonnet-v2@20241022`', 'status': 'FAILED_PRECONDITION'}}
0 2 5,001
2 REPLIES 2