#need help with gemini api in python

26 messages · Page 1 of 1 (latest)

crimson dagger
#

hello guys im very very new to python and i tried using ai to make a project for my college and i tried to make a dnd where gemini acts as the DM but when i try to run it it says the bellow so could anyone please help me, thank you.

green hemlockBOT
#

Hello! It looks like you're having trouble with the Gemini API in Python. To get the best help, please provide more details about your problem. This includes:

  • Your code: Please share the code you're using, formatted with markdown.
  • Error messages: If you're getting any errors, please share the full error messages.
  • Context: Explain what you're trying to do and what you've already tried.

The more information you provide, the better we can understand your issue and help you. Thanks!

wide wigeon
#

You're not sending your API key correctly. Like the bot said (using Gemini to read your messages), you need to share your code.

crimson dagger
wide wigeon
#

Where'd you put that?

crimson dagger
#

in the commandprompt?

wide wigeon
#

It's hard to answer without seeing your code.

crimson dagger
quartz shoalBOT
#

-# :warning: Files from unknown sources can be dangerous. Download with care. :warning:

crimson dagger
#

there

wide wigeon
#

If you print out the api key do you see the correct key?

crimson dagger
wide wigeon
#

I mean in your code, print it out to see what is actually being sent as the x-goog-api-key header

#

Also make it all lowercaes, no capital X

crimson dagger
wide wigeon
#

Just change that X to x and see if it works

crimson dagger
wide wigeon
#

Ok, after

GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")

put

print("'" + GEMINI_API_KEY + "'")

You should see something like 'nklTV0yMYEQ4iFkdlnbcXjxU7VOfzirqoLfSbj8' and it should EXACTLY MATCH the key you set in the command prompt.

crimson dagger
#

okayy

wide wigeon
#

I put quotes around it so you can see if there are any spaces or if it is empty

crimson dagger
#

😭

crimson dagger
#

i fixed it somehow thanks for ur help

#

i used 2.5 flash model after fixing up some lines

#

@wide wigeon i apprieciate ur help 🙏