Gemini api requests not working
thomasvmc
FREEOP

21 days ago

I made a discord bot for a school project that uses the gemini-2.5 flash model. It works locally but on railway the requests sent to gemini dont seem to work.
project id: 064561f6-ee63-4793-9aff-36ef213e04f5

Solved

0 Replies

medim
MODERATOR

21 days ago

Does it throw an error? I doubt this is related to Railway itself but I can help you investigate this.


medim
MODERATOR

21 days ago

If the repo is public I can take a look



medim
MODERATOR

21 days ago

Does it throw any type of error?


thomasvmc
FREEOP

21 days ago

i would have to start it again but i think it was every request to gemini not working


thomasvmc
FREEOP

21 days ago

the first error was getting refresh token


thomasvmc
FREEOP

21 days ago

oh wait its still on


thomasvmc
FREEOP

21 days ago

hostname: '169.254.169.254',
config: {
port: '',
url: URL {
pathname: '/computeMetadata/v1/instance/service-accounts/default/token',
href: '[http://169.254.169.254](http://169.254.169.254)/computeMetadata/v1/instance/service-accounts/default/token?scopes=https%3A%2F%[2Fwww.googleapis.com](2Fwww.googleapis.com)%2Fauth%2Fcloud-platform%2Fauth%2Fcloud-platform)',
search: '?scopes=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform',
origin: 'http://169.254.169.254',
searchParams: URLSearchParams { 'scopes' => 'https://www.googleapis.com/auth/cloud-platform' },
protocol: 'http:',
username: '',
password: '',
host: '169.254.169.254',
Unexpected error creating chat: GaxiosError: Could not refresh access token: request to [http://169.254.169.254](http://169.254.169.254)/computeMetadata/v1/instance/service-accounts/default/token?scopes=https%3A%2F%[2Fwww.googleapis.com](2Fwww.googleapis.com)%2Fauth%2Fcloud-platform%2Fauth%2Fcloud-platform) failed, reason: connect ETIMEDOUT 169.254.169.254:80
at Gaxios.request (/app/nodemodules/gaxios/build/cjs/src/gaxios.js:165:23)
at process.processTicksAndRejections (node:internal/process/taskqueues:105:5) at async metadataAccessor (/app/nodemodules/gcp-metadata/build/src/index.js:160:17)
at async Compute.refreshTokenNoCache (/app/node_modules/google-auth-library/build/src/auth/computeclient.js:57:20) {
response: undefined,
params: { scopes: 'https://www.googleapis.com/auth/cloud-platform' },
retry: 3,
code: 'ETIMEDOUT',
responseType: 'text',
httpMethodsToRetry: [Array],
status: undefined,
timeout: 0,


thomasvmc
FREEOP

21 days ago

I just don't get that its identical to my local setup and it doesnt work on railway


thomasvmc
FREEOP

21 days ago

it doesnt crash just sends the error


medim
MODERATOR

21 days ago

Hmmmm code seems fine, try replacing the chat.sendMessageStream to just chat.sendMessage


medim
MODERATOR

21 days ago

And make sure you've properly set the environment vars on Railway


medim
MODERATOR

21 days ago

Add some type of logging on startup to check if the env vars are really there


thomasvmc
FREEOP

21 days ago

Ive already submitted this can't change it


medim
MODERATOR

21 days ago

What do you mean you can't change it?


thomasvmc
FREEOP

21 days ago

unless i can make changes on railway outside of github


thomasvmc
FREEOP

21 days ago

its an assignment


thomasvmc
FREEOP

21 days ago

for school


medim
MODERATOR

21 days ago

Through the CLI, you can clone the repo and do a railway up



thomasvmc
FREEOP

21 days ago

alr


medim
MODERATOR

21 days ago

Another weird thing I spotted is that you send an empty object to GoogleGenAi
e.g: const ai = new GoogleGenAI({});
Maybe try explicity sending the API key there

const ai = new GoogleGenAI({
  apiKey: process.env.GEMINI_API_KEY,
});

thomasvmc
FREEOP

21 days ago

its like that in the documentation they say it gets the token from the environment but ill try adding it to see if it helps


thomasvmc
FREEOP

21 days ago

Unexpected error creating chat: Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
at GoogleAuth.getApplicationDefaultAsync (/app/nodemodules/google-auth-library/build/src/auth/googleauth.js:284:15) at async #determineClient (/app/nodemodules/google-auth-library/build/src/auth/googleauth.js:764:36)
at async GoogleAuth.getClient (/app/nodemodules/google-auth-library/build/src/auth/googleauth.js:741:20) at async GoogleAuth.getRequestHeaders (/app/nodemodules/google-auth-library/build/src/auth/googleauth.js:793:24)
at async NodeAuth.addGoogleAuthHeaders (file:///app/nodemodules/@google/genai/dist/node/index.mjs:15480:29) at async ApiClient.getHeadersInternal (file:///app/nodemodules/@google/genai/dist/node/index.mjs:11239:9)
at async ApiClient.includeExtraHttpOptionsToRequestInit (file:///app/nodemodules/@google/genai/dist/node/index.mjs:11114:31) at async ApiClient.requestStream (file:///app/nodemodules/@google/genai/dist/node/index.mjs:11087:23)
at async Models.generateContentStream (file:///app/node_modules/@google/genai/dist/node/index.mjs:12524:24)
(node:20) MetadataLookupWarning: received unexpected error = All promises were rejected code = UNKNOWN


thomasvmc
FREEOP

21 days ago

does it have something to do with that its on railroad because this literally works locally


thomasvmc
FREEOP

21 days ago

i already copied and pasted the gemini token a few times so i dont think thats it


medim
MODERATOR

21 days ago

Now I'm sure it's related to the env vars


medim
MODERATOR

21 days ago

are you hardcoding it or using env vars?


medim
MODERATOR

21 days ago

are they properly set on your service variables tab?


thomasvmc
FREEOP

21 days ago

wait


thomasvmc
FREEOP

21 days ago

i think i see it lol


thomasvmc
FREEOP

21 days ago

1438664778817077500


thomasvmc
FREEOP

21 days ago

it should be key


medim
MODERATOR

21 days ago

yep


thomasvmc
FREEOP

21 days ago

i cant believe i didnt see that


thomasvmc
FREEOP

21 days ago

and it works now thats so stupid


medim
MODERATOR

21 days ago

that's more common than you think lol


medim
MODERATOR

21 days ago

is everything working fine now?


thomasvmc
FREEOP

21 days ago

yep


medim
MODERATOR

21 days ago

nice, can I mark this thread as solved?


thomasvmc
FREEOP

21 days ago

yep


Status changed to Solved medim 21 days ago


Loading...