# Local llm error with enviromental variable OPENAI key

**URL:** <https://forum.rasa.com/t/local-llm-error-with-enviromental-variable-openai-key/63655>\
**Category:** Rasa CALM\
**Created:** [October 1, 2024, 3:14pm UTC](https://forum.rasa.com/t/local-llm-error-with-enviromental-variable-openai-key/63655 "2024-10-01T15:14:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![chatz](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@chatz](https://forum.rasa.com/u/chatz)\
**Post date:** [October 1, 2024, 3:14pm UTC](https://forum.rasa.com/t/local-llm-error-with-enviromental-variable-openai-key/63655/1 "2024-10-01T15:14:54Z")

</div>

Hello everyone, I have installed the latest rasa version and I am trying to use a local llm but I get this error:

```
Unable to create the LLM client for component - ContextualResponseRephraser. 
Please make sure you specified the required environment variables. 
Error: Environment variables: ['OPENAI_API_KEY'] not set. Required for API calls.

```

This is my config file:

```
recipe: default.v1
language: en
pipeline:
- name: LLMCommandGenerator
  llm:
    provider: self-hosted
    model: 'merged_model_gemma_27b_it'
    type: "openai"
    openai_api_key: foobar
    api_base: http://127.0.0.1:5000/v1 
    timeout: 800
    temperature: 0.7

```

If i add the open api key in the environmental variables as NULL or blank or something else it returns connection error from openai.

Thank you very much

---

<div class="post-metadata">

**Author:** ![Elliot94](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@Elliot94](https://forum.rasa.com/u/Elliot94)\
**Post date:** [October 2, 2024, 1:04pm UTC](https://forum.rasa.com/t/local-llm-error-with-enviromental-variable-openai-key/63655/2 "2024-10-02T13:04:27Z")

</div>

Can you try without mentioning the type as openai, and also without the openai\_api\_key? Like it is done here:

> **[LLM Configuration](https://rasa.com/docs/rasa-pro/concepts/components/llm-configuration/#self-hosted-model-server)**

---

<div class="post-metadata">

**Author:** ![chatz](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@chatz](https://forum.rasa.com/u/chatz)\
**Post date:** [October 2, 2024, 2:04pm UTC](https://forum.rasa.com/t/local-llm-error-with-enviromental-variable-openai-key/63655/3 "2024-10-02T14:04:33Z")

</div>

yes I have tried like this but it is not working.

---

<div class="post-metadata">

**Author:** ![thinkinnet](https://avatars.discourse-cdn.com/v4/letter/t/cc9497/32.png) [@thinkinnet](https://forum.rasa.com/u/thinkinnet)\
**Post date:** [November 18, 2024, 2:13pm UTC](https://forum.rasa.com/t/local-llm-error-with-enviromental-variable-openai-key/63655/4 "2024-11-18T14:13:00Z")

</div>

Hi all,

looks like we have the same problem using a Mistral model. First we got an error that says the command generator needs an `OPENAI_API_KEY` and after disabling the flow retrieval like in this post [Rasa Pro Tutorial with Azure OpenAI Service not working - #2 by emilymoore04](https://forum.rasa.com/t/rasa-pro-tutorial-with-azure-openai-service-not-working/61810/2) we can train successfully but when chatting with the bot, another tool asks for the OPENAI\_API\_KEY

What we are trying is just get some experience with CALM with our Mistral model. And we are trying to get the default tutorial running with this model ([Tutorial](https://rasa.com/docs/rasa-pro/tutorial))

Our config looks like this:

```auto
recipe: default.v1
language: en
pipeline:
  - name: SingleStepLLMCommandGenerator
    llm:
      provider: mistral
      model: mistral-large-latest
    flow_retrieval:
      active: false

policies:
  - name: FlowPolicy
# - name: EnterpriseSearchPolicy
# - name: RulePolicy

```

And our .env file looks like:

```auto
RASA_PRO_LICENSE='rasa_pro_license_key'
MISTRAL_API_KEY='mistral_api_key'

```

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![chatz](https://avatars.discourse-cdn.com/v4/letter/c/b77776/32.png) [@chatz](https://forum.rasa.com/u/chatz)\
**Post date:** [December 11, 2024, 5:30pm UTC](https://forum.rasa.com/t/local-llm-error-with-enviromental-variable-openai-key/63655/5 "2024-12-11T17:30:03Z")

</div>

Hello, sorry for the late reply. I fixed this by running these two commands in my command line:

```
export OPENAI_API_KEY="sk-111111111111111111111111111111111111111111111111"
export OPENAI_API_BASE="http://127.0.0.1:5000/v1"

```

I found this dummy OPENAPI key somewhere in the internet I cannot remember where. I believe there would be something similar for mistral. Except if your error is exactly the same about openai api so I believe this will fix your error.

Hope that this helps.

---

<div class="post-metadata">

**Author:** ![Gray430](https://avatars.discourse-cdn.com/v4/letter/g/cab0a1/32.png) [@Gray430](https://forum.rasa.com/u/Gray430)\
**Post date:** [March 17, 2025, 10:31am UTC](https://forum.rasa.com/t/local-llm-error-with-enviromental-variable-openai-key/63655/6 "2025-03-17T10:31:14Z")

</div>

Thanks a mil!! It really helps. Plus, if someone is using llama.cpp, specifically llama-server.exe, need to add a --pooling mean param to fit the API.
