Spaces:
Sleeping
Download docs/02_hugging_face_and_api_keys.md from UWRFR/UWaterlooRFRChatBot: direct link, hf CLI and curl.
- Browser
- Download file 4.25 kB
-
https://huggingface.co/spaces/UWRFR/UWaterlooRFRChatBot/resolve/main/docs/02_hugging_face_and_api_keys.md
- Command line
-
hf download hf://spaces/UWRFR/UWaterlooRFRChatBot/docs/02_hugging_face_and_api_keys.md
-
curl -L -o 02_hugging_face_and_api_keys.md https://huggingface.co/spaces/UWRFR/UWaterlooRFRChatBot/resolve/main/docs/02_hugging_face_and_api_keys.md
A newer version of the Streamlit SDK is available: 1.67.0
02 - Hugging Face, Secrets, and API Keys
This guide explains where the live website runs and how API keys are managed.
Where the Website Runs
The live website is a Hugging Face Space:
https://huggingface.co/spaces/UWRFR/UWaterlooRFRChatBot
The public app URL is:
https://uwrfr-uwaterloorfrchatbot.hf.space
Hugging Face stores:
- The deployed app code.
- Space settings.
- Runtime logs.
- Variables and secrets.
- The mounted storage bucket, if enabled.
How to See Space Logs
- Open the Hugging Face Space.
- Click Logs near the top of the Space page.
- Look for Python errors, missing secrets, API failures, or build errors.
Useful CLI command:
hf spaces info UWRFR/UWaterlooRFRChatBot
This shows the current commit SHA and runtime state.
Hugging Face Variables and Secrets
Go to:
Hugging Face Space -> Settings -> Variables and secrets
Use Variables for non-sensitive values.
Use Secrets for private values, such as API keys.
Important: Hugging Face does not show the value of an existing secret after it is saved. You can see that the secret exists, but you cannot reveal the stored key. If a key is lost or wrong, replace the secret with a new value.
Required Secrets
For LLM answers:
ANTHROPIC_API_KEY
or, if using OpenAI:
OPENAI_API_KEY
OPENAI_MODEL
For Google Drive request uploads:
GOOGLE_OAUTH_CLIENT_ID
GOOGLE_OAUTH_CLIENT_SECRET
GOOGLE_OAUTH_REFRESH_TOKEN
Optional override for the new case study request intake folder:
RFR_REQUESTS_DRIVE_FOLDER_ID
Current request intake folder ID:
10n_-uOCT2GXu_G3r1qi5qJr8hHoy-E_y
What Each Secret Does
ANTHROPIC_API_KEY
Used by the chatbot when the app is configured to answer with Claude.
If this key is missing, expired, or has no credits, the Ask tab can fail.
OPENAI_API_KEY
Used when the app or local pipeline is configured to use OpenAI.
If using OpenAI, also set:
OPENAI_MODEL
Example:
gpt-4o-mini
Google Drive Request Upload Secrets
Used by the website to upload New Case Study Requests into Google Drive.
Preferred setup uses OAuth for the shared Google account that should own the uploaded folders and PDFs, usually:
rfr.rag.uwaterloo@gmail.com
Set these Hugging Face secrets:
GOOGLE_OAUTH_CLIENT_ID
GOOGLE_OAUTH_CLIENT_SECRET
GOOGLE_OAUTH_REFRESH_TOKEN
Generate the secret values locally:
python3 -m case_study_pipeline.create_drive_oauth_secrets \
--credentials-file /path/to/oauth-client.json \
--space-id UWRFR/UWaterlooRFRChatBot
When the browser opens, sign in as rfr.rag.uwaterloo@gmail.com. The script
prints the hf spaces secrets add ... commands to run.
The older fallback secret is:
GOOGLE_SERVICE_ACCOUNT_JSON
That service-account option works best with a Google Shared Drive. It can fail in normal My Drive folders because service accounts do not have storage quota.
How to Add or Replace a Secret
- Open the Hugging Face Space.
- Click Settings.
- Scroll to Variables and secrets.
- Click New secret.
- Enter the exact name, such as
ANTHROPIC_API_KEY. - Paste the value.
- Save.
- Restart or rebuild the Space if needed.
How to Check Whether a Secret Is the Problem
Open Space logs and look for messages like:
ANTHROPIC_API_KEY is not set
OPENAI_API_KEY is not set
GOOGLE_SERVICE_ACCOUNT_JSON is not set
GOOGLE_OAUTH_REFRESH_TOKEN is not set
credit balance is too low
invalid_api_key
permission denied
For Drive upload problems, check:
- The three OAuth secrets exist:
GOOGLE_OAUTH_CLIENT_ID,GOOGLE_OAUTH_CLIENT_SECRET, andGOOGLE_OAUTH_REFRESH_TOKEN. - The OAuth token was created by signing in as the account that owns or can edit the intake folder.
- The intake folder ID is set correctly with
RFR_REQUESTS_DRIVE_FOLDER_ID. - The Space was restarted after the secret was added.
Do Not Put API Keys in GitHub
Never commit API keys to:
README.md.env- Python files
- Markdown docs
- screenshots
Use Hugging Face secrets for the live website.
Use a local .env file for your own computer. Do not commit .env.