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 3,394
2 REPLIES 2

AndrewB
Community Manager
Community Manager

Are you able to file a quota increase request? https://cloud.google.com/docs/quotas/view-manage

can you give some example code to run in local machine

i've tried and got some error, can you identify and resolve this issue

import os

# Replace with the path to your service account JSON key file

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "C:/credentials-770ba63bd0a0.json"

from anthropic import AnthropicVertex

LOCATION= "us-east4"

client = AnthropicVertex(region=LOCATION, project_id="proj-id")

message = client.messages.create(

  max_tokens=1024,

  messages=[

    {

      "role": "user",

      "content": "Send me a recipe for banana bread.",

    }

  ],

  model="claude-3-5-haiku@20241022",

)

print(message.model_dump_json(indent=2))

NotFoundError Traceback (most recent call last) Cell In[2], line 12  8 LOCATION= "us-east4" #"europe-west1" #or us-east5" # or  10 client = AnthropicVertex(region=LOCATION, project_id="proj-id") ---> 12 message = client.messages.create(  13 max_tokens=1024,  14 messages=[  15 {  16 "role": "user",  17 "content": "Send me a recipe for banana bread.",  18 }  19 ],  20 model="claude-3-5-haiku@20241022",  21 )  22 print(message.model_dump_json(indent=2))  File c:\proj\fm-env\Lib\site-packages\anthropic\_utils\_utils.py:275, in required_args.<locals>.inner.<locals>.wrapper(*args, **kwargs)  273 msg = f"Missing required argument: {quote(missing[0])}"  274 raise TypeError(msg) --> 275 return func(*args, **kwargs)  File c:proj\fm-env\Lib\site-packages\anthropic\resources\messages.py:888, in Messages.create(self, max_tokens, messages, model, metadata, stop_sequences, stream, system, temperature, tool_choice, tools, top_k, top_p, extra_headers, extra_query, extra_body, timeout)  881 if model in DEPRECATED_MODELS:  882 warnings.warn (...)  1068 retries_taken=retries_taken,  1069 )  NotFoundError: Error code: 404 - {'error': {'code': 404, 'message': 'Publisher Model `projects/proj-id/locations/us-east4/publishers/anthropic/models/claude-3-5-haiku@20241022` not found.', 'status': 'NOT_FOUND'}}