Skip to content

vertexai's request path is not appended to the url when using a custom base_url #2021

@saucoide

Description

@saucoide

This started to happen with 1.47 and is still the case as of the latest version (1.61 now)

this was the change that causes it: 7bd1bde#diff-4c1a4bac9ab6ed029428abb29a40ab24b267b55c306720b2113dca092cd14625R1071

join_url_path is not called on every case now, and the combination of vertex ai + custom base url results in the url never being correctly built

reproducer using the example from the library's own documentation

base_url = 'http://localhost:8080'
client = Client(
    vertexai=True,  # Currently only vertexai=True is supported
    http_options={
        'base_url': base_url,
        'headers': {'Authorization': 'Bearer test_token'},
    },
)
response = client.models.generate_content(
    model="gemini-2.5-flash-image",
    contents="Why is the sky blue? explain with an image",
) 

this results in a POST http://localhost:8080
but it should be POST http://localhost:8080/v1beta1/publishers/google/models/gemini-2.5-flash-image:generateContent

There is a workaround to make it correctly append the path, by adding a dummy api key

    client =Client(
        vertexai=True,
        api_key="dummy",  # <----
        http_options={
            "base_url": base_url,
            "headers": {"Authorization": f"Bearer test-token"},
        },
    )

and there is already a PR that tries to address it #1701 , but it adds an extra param to hammer it in place, while probably the library should handle all the combinations directly in _build_request and not require the user to force certain behavior

creating the issue because i couldn't find anything referencing it other than the PR itself

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions