google-gemini / generative-ai-js

The official Node.js / Typescript library for the Google Gemini API
https://www.npmjs.com/package/@google/generative-ai
Apache License 2.0
679 stars 141 forks source link

Only works in localhost #183

Open henriqueArrazao opened 3 months ago

henriqueArrazao commented 3 months ago

Description of the bug:

Locally works fine and in the server not. It's not be cause of the local of the server (Germany) because I tested the Gemini request Curl in the terminal and worked.

This is the log of this package

Server is running on port 3000 🚀
/app/node_modules/@google/generative-ai/dist/index.js:353
            throw new GoogleGenerativeAIFetchError(`Error fetching from ${url.toString()}: [${response.status} ${response.statusText}] ${message}`, response.status, response.statusText, errorDetails);
                  ^

GoogleGenerativeAIFetchError: [GoogleGenerativeAI Error]: Error fetching from https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent: [403 Forbidden] 
    at _makeRequestInternal (/app/node_modules/@google/generative-ai/dist/index.js:353:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async generateCon
```tent (/app/node_modules/@google/generative-ai/dist/index.js:752:22) {
  status: 403,
  statusText: 'Forbidden',
  errorDetails: undefined
}

Node.js v18.20.2

The response of the raw request is this:

<title>Error 403 (Forbidden)!!1</title>
<p><b>403.</b> <ins>That’s an error.</ins></p>
<p>Your client does not have permission to get URL <code>/v1beta/models/gemini-1.5-flash:generateContent</code> from this server. <ins>That’s all we know.</ins></p>

My instance (working fine locally):

const aiModel = genAI.getGenerativeModel({
  model: 'gemini-1.5-flash',
  systemInstruction: CHAT_GPT_SYSTEM_PROMPT_MESSAGE,
});

No idea what is going on, I've been for a while on this.

singhniraj08 commented 3 months ago

@henriqueArrazao Thank you reporting this issue. This repository is for issues related to JS SDK client bugs or improvements and the client doesn't control the service's responses. For issues related to Gemini API, we would suggest you to use "Send Feedback" option in Gemini docs. Ref: Screenshot below. You can also post this issue on Discourse forum.

image

hsubox76 commented 2 months ago

Description of the bug:

Locally works fine and in the server not. It's not be cause of the local of the server (Germany) because I tested the Gemini request Curl in the terminal and worked.

Did you run the curl command while SSHd into the same server instance that you're seeing the error? Or on another machine in Germany? Can you paste the curl command? (you can obscure your API key)

henriqueArrazao commented 2 months ago

Description of the bug:

Locally works fine and in the server not. It's not be cause of the local of the server (Germany) because I tested the Gemini request Curl in the terminal and worked.

Did you run the curl command while SSHd into the same server instance that you're seeing the error? Or on another machine in Germany? Can you paste the curl command? (you can obscure your API key)

I ran in the same server instance through SSH. I'm using ChatGPT now, but here is the Curl:

curl --location 'https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent' \
--header 'content-type: application/json' \
--header 'x-goog-api-key: XXXXXXXXXXXXXXXXXXXXXXXX' \
--header 'x-goog-api-client: genai-js/0.12.0' \
--data '{
  "generationConfig": {
    "temperature": 0.5,
    "topP": 1,
    "topK": 100,
    "maxOutputTokens": 8192,
    "responseMimeType": "application/json"
  },
  "safetySettings": [],
  "systemInstruction": {
    "role": "system",
    "parts": [
      {
        "text": "make the sum"
      }
    ]
  },
  "contents": [
    {
      "parts": [
        {
          "text": "1 + 2"
        }
      ],
      "role": "user"
    }
  ]
}
'
rpgramesh commented 2 months ago

status: 400, statusText: 'Bad Request', errorDetails: [ { '@type': 'type.googleapis.com/google.rpc.ErrorInfo', reason: 'API_KEY_INVALID', domain: 'googleapis.com', metadata: { service: 'generativelanguage.googleapis.com' } } ]

How to solve this issue ?

nurlumeryem commented 1 month ago

durum: 400, durumMetni: 'Kötü İstek', hataAyrıntıları: [ { '@type': 'type.googleapis.com/google.rpc.ErrorInfo', neden: 'API_KEY_INVALID', etki alanı: 'googleapis.com', meta veri: { hizmet: 'generativelanguage.googleapis.com' } } ]

Bu sorunu nasıl çözebiliriz?

Did you find a solution? I'm facing the same issue.

vivekchavan14 commented 1 week ago

Same issue, did u find any solution to that?

image This is the error I'm facing

henriqueArrazao commented 3 days ago

Go with ChatGPT guys, that was the solution I found.