[Bug] API Key error (400/401) despite valid key, cannot resolve ${env:...}
Closed this issue · 2 comments
Before submitting your bug report
- I've tried using the "Ask AI" feature on the Continue docs site to see if the docs have an answer
- I believe this is a bug. I'll try to join the Continue Discord for questions
- I'm not able to find an open issue that reports the same bug
- I've seen the troubleshooting guide on the Continue Docs
Relevant environment info
### System Info
- **OS:** Windows 11
- **VS Code Version:** 1.104
- **Continue Version:** 1.2.2Description
Describe the bug
The Continue extension fails to connect to both OpenAI and Google Gemini APIs, returning 401 and 400 errors respectively. The error messages indicate an invalid API key, even when the key is hardcoded into config.yaml.
Steps to Reproduce
- Installed Continue on Windows with VS Code.
- Configured
config.yamlto use either environment variables (${env:VAR_NAME}) or a hardcoded API key for OpenAI and Google Gemini. - Restarted VS Code completely.
- Attempted to send a request to any model.
Expected behavior
The extension should connect to the API and return a valid response.
Actual behavior
Gemini Error:
[{
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.ErrorInfo",
"reason": "API_KEY_INVALID",
"domain": "googleapis.com",
"metadata": {
"service": "generativelanguage.googleapis.com"
}
},
{
"@type": "type.googleapis.com/google.rpc.LocalizedMessage",
"locale": "en-US",
"message": "API key not valid. Please pass a valid API key."
}
]
}
}
]
OpenAI Error:
401 Incorrect API key provided: ${env:OP*************KEY}. You can find your API key at https://platform.openai.com/account/api-keys.
CRITICAL INFORMATION:
Standalone Python scripts (gemini_test.py and openai_test.py) using the official google-generativeai and openai libraries work perfectly with the exact same API keys loaded from the same .env file. This proves the keys and cloud project configurations are correct, and the issue is specific to the Continue extension's environment.
To reproduce
No response
Log output
@NagyLZ the syntax for using secrets is {{ secrets.NAME }}. Try replacing ${env:VAR_NAME} with that. Hardcoded api keys should work. Please share the exact config (with api key redacted) if you're finding a hardcoded key isn't working
please confirm if this is still an issue @NagyLZ - We need a bit more context to triage. Also leaving related links, but again not sure if this is helpful without more context on your config.
https://docs.continue.dev/guides/configuring-models-rules-tools#working-with-secrets