Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@nicodemuz
Copy link

Q A
Bug fix? no
New feature? yes
Docs? need to be updated
License MIT

Vertex AI supports multiple methods of authentication. This PR adds support for API keys.

@carsonbot carsonbot added Feature New feature Platform Issues & PRs about the AI Platform component Status: Needs Review labels Dec 15, 2025
@OskarStark
Copy link
Contributor

Please add tests

@nicodemuz
Copy link
Author

Please add tests

Sure. Before I spend more time on tests, can you review that the approach/solution is correct? I'm relatively new to the symfony/ai project and not sure how other Bridges handle this.

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. WDYT @chr-hertel ?

@nicodemuz can you please check if it is also supported for Gemini. This should also be configurable via the AiBundle config

@nicodemuz
Copy link
Author

Looks good to me. WDYT @chr-hertel ?

@nicodemuz can you please check if it is also supported for Gemini. This should also be configurable via the AiBundle config

@OskarStark You mean to configure whether the key should be sent via a query parameter or the headers? For Gemini, I think the API key is sent via HTTP headers:

return new RawHttpResult($this->httpClient->request('POST', $url, [
'headers' => [
'x-goog-api-key' => $this->apiKey,
],
'json' => array_merge($generationConfig, $payload),
]));

@OskarStark
Copy link
Contributor

@OskarStark You mean to configure whether the key should be sent via a query parameter or the headers? For Gemini, I think the API key is sent via HTTP headers:

Thanks for double checking

Comment on lines 26 to 28
========================================
1. Application Default Credentials (ADC)
========================================
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
========================================
1. Application Default Credentials (ADC)
========================================
Application Default Credentials (ADC)
-------------------------------------

Same for the other headlines

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated the headings as per your suggestion. I was trying to make these headings as subheadings of "Authentication", but now they became top level headings:

image

@nicodemuz
Copy link
Author

Please add tests

@OskarStark I'm trying to fix the tests, and there's one test failing with:

1) Symfony\AI\AiBundle\Tests\DependencyInjection\AiBundleTest::testExtensionLoadDoesNotThrow
Failed to load platform service "ai.platform.vertexai" or call getModelCatalog(). Original error: Symfony\AI\Platform\Bridge\VertexAi\PlatformFactory::create(): Argument #3 ($httpClient) must be of type ?Symfony\Contracts\HttpClient\HttpClientInterface, string given, called in /home/runner/work/ai/ai/src/ai-bundle/vendor/symfony/dependency-injection/ContainerBuilder.php on line 1178 (in /home/runner/work/ai/ai/src/ai-bundle/vendor/symfony/ai-vertex-ai-platform/PlatformFactory.php:33)

/home/runner/work/ai/ai/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php:123

Is it trying to run code from some other repo/branch? Since it's referring to ai-vertex-ai-platform/PlatformFactory.php:33? How do I fix this?

@OskarStark
Copy link
Contributor

Tests still needed

# Vertex AI
GOOGLE_CLOUD_LOCATION=global
GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
GOOGLE_CLOUD_VERTEX_API_KEY=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GOOGLE_CLOUD_VERTEX_API_KEY=
GOOGLE_CLOUD_API_KEY=

in the whole PR

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't google cloud have hundreds of APIs that can be accessed with a product specific API key? This API key is for the key that can be created at https://console.cloud.google.com/vertex-ai/studio/settings/api-keys

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm you might be right 🤔


require_once __DIR__.'/bootstrap.php';

$platform = PlatformFactory::create(env('GOOGLE_CLOUD_LOCATION'), env('GOOGLE_CLOUD_PROJECT'), env('GOOGLE_CLOUD_VERTEX_API_KEY'), httpClient: adc_aware_http_client());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this still uses the adc_aware_http_client

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed! 👍

@OskarStark
Copy link
Contributor

It looks like your committer email is not associated with your GitHub account

Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

# Vertex AI
GOOGLE_CLOUD_LOCATION=global
GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
GOOGLE_CLOUD_VERTEX_API_KEY=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm you might be right 🤔

Comment on lines 51 to 53
if (null !== $this->apiKey) {
$url .= '?key='.$this->apiKey;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big fan of string-based concatenation when it comes to ? and & - might be brittle when extending later
can we use the query part of the HttpClient's request method here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 56 to 58
if (null !== $this->apiKey) {
$url .= '?key='.$this->apiKey;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we def need this - thanks @nicodemuz!

only minor comments but broken pipeline

@nicodemuz
Copy link
Author

Yes, we def need this - thanks @nicodemuz!

only minor comments but broken pipeline

Any ideas about the broken pipeline? See my comment here:

#1139 (comment)

@nicodemuz
Copy link
Author

It looks like your committer email is not associated with your GitHub account

Will this prevent from the PR getting merged? I remember getting a lot of spam after entering my email address in public repos.

@OskarStark
Copy link
Contributor

Will this prevent from the PR getting merged? I remember getting a lot of spam after entering my email address in public repos.

No it will not

@OskarStark
Copy link
Contributor

Can you please check the tests? They look related

@nicodemuz
Copy link
Author

Can you please check the tests? They look related

Regarding the error mentioned in here https://github.com/symfony/ai/actions/runs/20368930248/job/58530711175?pr=1139:

Failed to load platform service "ai.platform.vertexai" or call getModelCatalog(). Original error: Symfony\AI\Platform\Bridge\VertexAi\PlatformFactory::create(): Argument 3 ($httpClient) must be of type ?Symfony\Contracts\HttpClient\HttpClientInterface, string given, called in /home/runner/work/ai/ai/src/ai-bundle/vendor/symfony/dependency-injection/ContainerBuilder.php on line 1178 (in /home/runner/work/ai/ai/src/ai-bundle/vendor/symfony/ai-vertex-ai-platform/PlatformFactory.php:33)

I have updated the 3rd parameter of PlatformFactory::create() to accept the $apiKey:
https://github.com/nicodemuz/ai/blob/c5bd3ec2282d73688189c8836437cdf20a9e4e16/src/platform/src/Bridge/VertexAi/PlatformFactory.php#L36

And I have updated code to also pass the 3rd parameter as the apiKey:
https://github.com/nicodemuz/ai/blob/c5bd3ec2282d73688189c8836437cdf20a9e4e16/src/ai-bundle/src/AiBundle.php#L589

I'm a bit confused why it's calling an outdated PlatformFacory via the vendor folder:

in /home/runner/work/ai/ai/src/ai-bundle/vendor/symfony/ai-vertex-ai-platform/PlatformFactory.php:33

How should I address this? Should I add the new parameter as the last parameter in PlatformFactory::create()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New feature Platform Issues & PRs about the AI Platform component Status: Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants