Repository: promptfoo/promptfoo
Issue: import environment variables in the providers
Root cause: Validation Gap

Hello,
First of all, i would like to thank you for your reactivity in implementing new features asked by the community.

Following this issue that has been closed #1552 , is it possible to you env variables in the yaml config file for all the fields ?

Here is an exemple : 

```
# env variables are in .env
providers:
  - id: azureopenai:chat:{{ env.AZURE_OPENAI_DEPLOYMENT_NAME }}
    config:
      apiBaseUrl: {{ env.AZURE_OPENAI_ENDPOINT }}
      apiKey: {{ env.AZURE_OPENAI_API_KEY }}
      apiVersion: {{ env.AZURE_OPENAI_API_VERSION }}
```
When using it in this example : 

```

providers:
  - id: azureopenai:chat:gpt-4o-mini
    config:
      apiBaseUrl: {{ env.AZURE_OPENAI_ENDPOINT }}

```

i get the following error : 

```
TypeError: this.apiBaseUrl.replace is not a function
    at AzureChatCompletionProvider.getApiBaseUrl (/Users/aminedjeghri/PycharmProjects/ai-cloud-project-template/node_modules/promptfoo/dist/src/providers/azure.js:262:36)
    at AzureChatCompletionProvider.callApi (/Users/aminedjeghri/PycharmProjects/ai-cloud-project-template/node_modules/promptfoo/dist/src/providers/azure.js:474:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async Evaluator.runEval (/Users/aminedjeghri/PycharmProjects/ai-cloud-project-template/node_modules/promptfoo/dist/src/evaluator.js:182:28)
    at async processEvalStep (/Users/aminedjeghri/PycharmProjects/ai-cloud-project-template/node_modules/promptfoo/dist/src/evaluator.js:552:25)
```

You should be able to set AZURE_API_BASE_URL directly without the config and it will be picked up. See https://github.com/promptfoo/promptfoo/blob/main/src/providers/azure.ts#L219 

> You should be able to set AZURE_API_BASE_URL directly without the config and it will be picked up. See https://github.com/promptfoo/promptfoo/blob/main/src/providers/azure.ts#L219

I think the piece of code you were linking to has changed? Do you have an example of how to do this as I have the same issue as AmineDjeghri

That environment variable is still available if you ctrl+f in the file.
Have you tried using it?

On Tue, Jan 7, 2025 at 7:28 AM nfrancis-esure ***@***.***>
wrote:

> You should be able to set AZURE_API_BASE_URL directly without the config
> and it will be picked up. See
> https://github.com/promptfoo/promptfoo/blob/main/src/providers/azure.ts#L219
>
> I think the piece of code you were linking to has changed? Do you have an
> example of how to do this as I have the same issue as AmineDjeghri
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/promptfoo/promptfoo/issues/2224#issuecomment-2575576424>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AACLYJSRSQTF5UWUW6PXOMD2JPXAXAVCNFSM6AAAAABSMPLSEGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNZVGU3TMNBSGQ>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>



Yes using that environment variable works but I want to override this and use an environment variable with a different name. My initial thought was to  add something like `apiBaseUrl: {{ env.ENDPOINT_NAME }}` to the YAML, but it doesn't work.

My use case is that I have a bunch of tests running on the same machine that will use different hosts that are all defined as environment variables, so i want each test to use their own environment variable.

Just tagging you in case you hadn't seen my reply @typpo