Spaces:
Running
how to use openai api key?
After deplicating the space, where to use my own api key?
After duplicating the space, head over to Repository Secrets under Settings and add a new secret with name as "OPENAI_API_KEY" and the value as your key
To use your environment variables in a secure way you need to do this:
- Go to https://huggingface.co/spaces/USER/SPACE_ID/settings [USER = Your hugging face user name ; SPACE ID = space name as in space home
- Create Private Secret
- Go to your app.py script and add these lines:
'''
... your code....
import os
api_key = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=api_key)
... the rest of your code.....
'''
That should do the trick.
Would be nice if the huggingface's team adds this little detail to the docs: https://huggingface.co/docs/hub/spaces-overview#managing-secrets
still getting an error 'No API found' , i am using the groq api key
Hey bro, groq is a different provider. You'll need openAI API Keys to work with this space