Repository: promptfoo/promptfoo
Issue: Google providers: Adding an API key as an env var is not working
Root cause: Configuration Error

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior, including example Promptfoo configurations if applicable:

I've tried all permutations of the below
```
# Define providers (LLM models)
providers:
  - id: "google:gemini-2.0-flash-exp"
    config:
      temperature: 0.2
      apiKey: ${process.env.GOOGLE_API_KEY}
or 
      # apiKey: "${GOOGLE_API_KEY}"
      # apiKey: env.GOOGLE_API_KEY


env:
  GOOGLE_API_KEY: ${GOOGLE_API_KEY}
```

With several permutations of
```
GOOGLE_API_KEY=key npx promptfoo eval --verbose --config tests/promptfoo.yaml 
GOOGLE_API_KEY=key promptfoo eval --verbose --config tests/promptfoo.yaml --env-path ~/code/axis_codebase/workers/event-quantifier-processor/.env
```
etc. 
With no results. and always 
```
        Google API response: {"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."}]}}
```
Can anyone pls help? 

I'm using an .env file as well it's in `.` not `tests` though


**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**System information:**

If possible, please output the results of `promptfoo debug` and paste the output here.

- Promptfoo version:
0.105.1

**Additional context**
Add any other context about the problem here.


@jakubLangr running `GOOGLE_API_KEY=key npx promptfoo eval --verbose --config tests/promptfoo.yaml` should work. The API key is automatically picked up by your env unless you specify fallbacks. See https://github.com/promptfoo/promptfoo/blob/main/src/providers/google.ts#L67

I recommend changing your provider to

```yaml 
# Define providers (LLM models)
providers:
  - id: "google:gemini-2.0-flash-exp"
    config:
      temperature: 0.2
```

And just trying it. Specifying an api key in your config can actually hurt this because they override the default value.

If you want to specify a different env var name, we would need to do something like this: https://github.com/promptfoo/promptfoo/compare/fix/google-provider-template-variables?expand=1

Hi @mldangelo thanks for the prompt response

So you mean removing the path to the env file? I've tried that too does not work.

Neither does removing it from the config. 

Also if it's a fallback it should only be invoked if some other method fails?

Regerding the /compare/ you sent, I'm a bit confused how would I use Nunjucks—I've not used this templating engine before.

Many thanks!

@jakubLangr throw some time on my calendar: https://cal.com/michael-dangelo/15min

I just released something that will help with arbitrary env variables in [0.106.1](https://github.com/promptfoo/promptfoo/releases/tag/0.106.1).

Please let me know if this fully resolves the issue or if anything else pops up. Closing the issue for now but please feel free to comment / re-open.