continuedev/continue

[Bug] API Key error (400/401) despite valid key, cannot resolve ${env:...}

Closed this issue · 2 comments

Before submitting your bug report

Relevant environment info

### System Info
- **OS:** Windows 11
- **VS Code Version:** 1.104
- **Continue Version:** 1.2.2

Description

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

  1. Installed Continue on Windows with VS Code.
  2. Configured config.yaml to use either environment variables (${env:VAR_NAME}) or a hardcoded API key for OpenAI and Google Gemini.
  3. Restarted VS Code completely.
  4. 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