Resolving API Endpoint Error for Fine-Tuned Gemini 1.0 Model

I’ve fine-tuned Gemini 1.0 in Google AI Studio and am now trying to use the model for production. I created a Service Account in my Google Cloud project, which provided me with a JSON file. I am attempting to make a call to my model using the following code:

const auth = new google.auth.GoogleAuth({
      keyFile: './keyfile-path.json',
      scopes: [
        'https://www.googleapis.com/auth/cloud-platform',
        'https://www.googleapis.com/auth/generative-language',
      ],
    });
    const client = await auth.getClient();
    const accToken = await client.getAccessToken();
    const authclient = client.setCredentials({ access_token: accToken.token });
    const response = await firstValueFrom(
      this.http.post(
        'https://generativelanguage.googleapis.com/v1/model=tunedModels/my-model-name-here:generateContent',
        {
          prompt: prompt,
        },
        {
          headers: {
            Authorization: `Bearer ${accToken.token}`,
            'Content-Type': 'application/json',
          },
        },
      ),
    );
    return response;

But I am facing error with this:
'https://generativelanguage.googleapis.com/v1/model=tunedModels/my-model-name-here:generateContent'

what could be the problem? am I writing this URL incorrectly?
Thank you in advance for your help. I would be grateful for any assistance you can provide.

It would help if you specified what error, exactly, you’re getting when you attempt.

However, in this case, you’re correct. The URL format you’re using isn’t quite right. The “gRPC transcoding syntax” mentioned at Method: tunedModels.generateContent  |  Google AI for Developers  |  Google for Developers can be confusing, but I tend to think of it this way.

When it says the format is:
POST https://generativelanguage.googleapis.com/v1/{model=tunedModels/*}:generateContent
it means:

  • There is a parameter named “model” that is (usually) described in the documentation
  • It should be in the format of “tunedModels/*”
    • Meaning there is a fixed part called “tunedModels”
    • and a wildcard that can take “any” characters

So the URL should look something more like:
https://generativelanguage.googleapis.com/v1/tunedModels/my-model-name-here:generateContent

In this case it also doesn’t help that the documentation gives the format incorrectly in two ways.

(As an aside - make sure that you’ve permitted the service account access to that model. But that’s a whole other mess.)

Good luck!

Hi, yes your URL pattern is wrong regarding the model reference. That part should read “/tunedModels/your-model-name:” Use the ListModels() method to get the exact writing and then you shall be able to use your tuned model.