Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[PredictionServiceClient] Bug in embedContent and EmbedContentRequest: Invalid model/endpoint mappings causing INVALID_ARGUMENT or undefined method errors

Open
#9,276 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
php
Domain
api

Research direction

Start by tracing PredictionServiceClient::embedContent() and EmbedContentRequest through the google.cloud.aiplatform.v1 PredictionService/EmbedContent RPC bindings. Reproduce the model and endpoint cases from the issue, then verify that the request maps successfully and returns an EmbedContentResponse without the oneof, URI-template, or undefined-method errors.

Written by the indexing model from the issue text.

Description

When attempting to use PredictionServiceClient::embedContent() with the newer EmbedContentRequest class, the underlying gRPC bindings fail to resolve the model or endpoint correctly. This makes it impossible to use the native text-embedding endpoints via the official PHP SDK.

Steps to reproduce:
If we try to construct the request by setting the model using setModel():

use Google\Cloud\AIPlatform\V1\Client\PredictionServiceClient;
use Google\Cloud\AIPlatform\V1\EmbedContentRequest;
use Google\Cloud\AIPlatform\V1\Content;
use Google\Cloud\AIPlatform\V1\Part;
 
$client = new PredictionServiceClient([
    'apiEndpoint' => 'us-central1-aiplatform.googleapis.com',
    'credentials' => '/path/to/credentials.json'
]);
 
$content = (new Content())->setParts([(new Part())->setText('Hello world')]);
 
$req = new EmbedContentRequest();
$req->setModel('projects/MY_PROJECT/locations/us-central1/publishers/google/models/text-embedding-004');
$req->setContent($content);
 
$res = $client->embedContent($req);

Actual Result: An ApiException is thrown from the backend:

{
    "message": "Invalid value (oneof), oneof field '_model' is already set. Cannot set 'model'",
    "code": 3,
    "status": "INVALID_ARGUMENT",
    "details": [ ... ]
}

If we try to supply an endpoint via the $optionalArgs to bypass the model binding:

$res = $client->embedContent($req, [
    'endpoint' => 'projects/MY_PROJECT/locations/us-central1/publishers/google/models/text-embedding-004'
]);

Actual Result:

Google\ApiCore\ValidationException: Could not map bindings for google.cloud.aiplatform.v1.PredictionService/EmbedContent to any Uri template.

If we attempt to use setEndpoint() on the request object itself (which is available on PredictRequest but seems to be missing here):

$req->setEndpoint('projects/MY_PROJECT/locations/us-central1/publishers/google/models/text-embedding-004');

Actual Result:

Fatal error: Call to undefined method Google\Cloud\AIPlatform\V1\EmbedContentRequest::setEndpoint()

Expected Result:
The EmbedContentRequest should properly bind the model parameter to the gRPC URI template (e.g. /v1/{model=projects//locations//publishers//models/}:embedContent) without throwing a protobuf oneof conflict (_model vs model), and should successfully return the EmbedContentResponse.

Workaround (for others facing this issue):

Currently, the only way to get embeddings via PHP is to bypass EmbedContentRequest and use the older PredictRequest with raw Protobuf Structs:

$instanceValue = new \Google\Protobuf\Value();
$struct = new \Google\Protobuf\Struct();
$struct->setFields(['content' => (new \Google\Protobuf\Value())->setStringValue('Hello World')]);
$instanceValue->setStructValue($struct);
 
$request = (new PredictRequest())
    ->setEndpoint('projects/MY_PROJECT/locations/us-central1/publishers/google/models/text-embedding-004')
    ->setInstances([$instanceValue]);
 
$response = $client->predict($request);

Environment details:
OS: Linux
PHP version: 8.0+
Package name and version: google/cloud-ai-platform (Tested on versions ^1.13.0 up to 1.60.1)

Dominant language
PHP
Stars
1.2k
Forks
464
Avg merge
2d 2h
Merged PRs (30d)
103

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-cloud-php

All issues in googleapis/google-cloud-php

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.