Skip to content

anthropic[vertex] has missing requests dependency #738

@shobsi

Description

@shobsi

I install anthropic[vertex]

pip install anthropic[vertex]

Then write this code:

def anthropic_transformer(message: str) -> str: from anthropic import AnthropicVertex client = AnthropicVertex(region=LOCATION, project_id=PROJECT) message = client.messages.create( max_tokens=1024, messages=[ { "role": "user", "content": message, } ], model="claude-3-5-sonnet@20240620", ) content_text = message.content[0].text if message.content else "" return content_text

It is running into the following exception:

line 7, in anthropic_transformer File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/_utils/_utils.py\", line 275, in wrapper return func(*args, **kwargs) File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/resources/messages.py\", line 888, in create return self._post( File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/_base_client.py\", line 1277, in post return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)) File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/_base_client.py\", line 954, in request return self._request( File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/_base_client.py\", line 981, in _request self._prepare_request(request) File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/lib/vertex/_client.py\", line 159, in _prepare_request request.headers[\"Authorization\"] = f\"Bearer {self._ensure_access_token()}\" File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/lib/vertex/_client.py\", line 166, in _ensure_access_token self.credentials, project_id = load_auth(project_id=self.project_id) File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/lib/vertex/_auth.py\", line 19, in load_auth from google.auth.transport.requests import Request # type: ignore[import-untyped] File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/google/auth/transport/requests.py\", line 28, in <module> raise ImportError( ImportError: The requests library is not installed from please install the requests package to use the requests transport. "} . 

Looks like google-auth needs requests library:

https://github.com/googleapis/google-auth-library-python/blob/3fae8f8368d4651cd11d4af3d80f687eab033175/google/auth/transport/requests.py#L28

google-auth defined "requests" extra:

https://github.com/googleapis/google-auth-library-python/blob/3fae8f8368d4651cd11d4af3d80f687eab033175/setup.py#L33

But anthropic[vertex] uses plain google-auth dependency:

vertex = ["google-auth >=2, <3"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions