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
0 Replies
21 days ago
Does it throw an error? I doubt this is related to Railway itself but I can help you investigate this.
21 days ago
If the repo is public I can take a look
21 days ago
Does it throw any type of error?
i would have to start it again but i think it was every request to gemini not working
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,
I just don't get that its identical to my local setup and it doesnt work on railway
21 days ago
Hmmmm code seems fine, try replacing the chat.sendMessageStream to just chat.sendMessage
21 days ago
And make sure you've properly set the environment vars on Railway
21 days ago
Add some type of logging on startup to check if the env vars are really there
21 days ago
What do you mean you can't change it?
21 days ago
Through the CLI, you can clone the repo and do a railway up
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,
});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
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
does it have something to do with that its on railroad because this literally works locally
i already copied and pasted the gemini token a few times so i dont think thats it
21 days ago
Now I'm sure it's related to the env vars
21 days ago
are you hardcoding it or using env vars?
21 days ago
are they properly set on your service variables tab?
21 days ago
yep
21 days ago
that's more common than you think lol
21 days ago
is everything working fine now?
21 days ago
nice, can I mark this thread as solved?
Status changed to Solved medim • 21 days ago
