# CrewAI is not allowing the use of a knowledge source when using an Ollama-based LLM. It defaults to requiring an OpenAI API key, even though Ollama is correctly configure

**URL:** <https://community.crewai.com/t/crewai-is-not-allowing-the-use-of-a-knowledge-source-when-using-an-ollama-based-llm-it-defaults-to-requiring-an-openai-api-key-even-though-ollama-is-correctly-configure/3378>\
**Category:** General\
**Tags:** openai, agent, crewai\
**Created:** [January 30, 2025, 1:41pm UTC](https://community.crewai.com/t/crewai-is-not-allowing-the-use-of-a-knowledge-source-when-using-an-ollama-based-llm-it-defaults-to-requiring-an-openai-api-key-even-though-ollama-is-correctly-configure/3378 "2025-01-30T13:41:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cc.aiproduct\_CC](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/cc.aiproduct_cc/32/2330_2.png) [@cc.aiproduct\_CC](https://community.crewai.com/u/cc.aiproduct_CC)\
**Post date:** [January 30, 2025, 1:41pm UTC](https://community.crewai.com/t/crewai-is-not-allowing-the-use-of-a-knowledge-source-when-using-an-ollama-based-llm-it-defaults-to-requiring-an-openai-api-key-even-though-ollama-is-correctly-configure/3378/1 "2025-01-30T13:41:23Z")

</div>

Error Message = Value error, Invalid Knowledge Configuration: Please provide an OpenAI API key. You can get one at [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys)

### Source Code

I am running my Ollama model on Runpod.

```python
from crewai import Agent, Crew, Process, Task, LLM
from crewai.project import CrewBase, agent, crew, task
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
from dotenv import load_dotenv
import os
from crewai.knowledge.source.crew_docling_source import CrewDoclingSource

text_source = CrewDoclingSource(
    file_paths=["boilerplate.md"]
)

# Load environment variables from .env file
load_dotenv()

# Access the variables
MODEL = os.getenv("MODEL")
API_BASE = os.getenv("API_BASE")
os.environ["MODEL"] = MODEL
os.environ["API_BASE"] = API_BASE

# Create a knowledge source
content = "Users name is Savi. He is 26 years old and lives in Ahemdabad."
string_source = StringKnowledgeSource(
    content=content,
)

@CrewBase
class CrewaiCodingAgents():
    """CrewaiCodingAgents crew"""
    agents_config = 'config/agents.yaml'
    tasks_config = 'config/tasks.yaml'

    @agent
    def Senior_HTML_Developer(self) -> Agent:
        return Agent(
            config=self.agents_config['Senior_HTML_Developer'],
            verbose=True,
            knowledge_sources=[string_source, text_source],
            llm=LLM(
                model="ollama/deepseek-coder-v2",
                api_key="",
                base_url=os.getenv("API_BASE") 
            ),
            memory=True,
            temperature=0.5
        )

    @task
    def navbar_html(self) -> Task:
        return Task(
            config=self.tasks_config['navbar_html'],
        )

    @crew
    def crew(self) -> Crew:
        """Creates the CrewaiCodingAgents crew"""
        return Crew(
            agents=self.agents, 
            tasks=self.tasks, 
            process=Process.sequential,
            verbose=True,
            memory=True,
            embedder={
                "provider": "ollama",
                "config": {
                    "model": "ollama/nomic-embed-text:latest",
                    "api_key": "",
                    "base_url": os.getenv("API_BASE") 
                }
            }
        )
```

---

<div class="post-metadata">

**Author:** ![jaysus](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/jaysus/32/2430_2.png) [@jaysus](https://community.crewai.com/u/jaysus)\
**Post date:** [February 5, 2025, 1:21pm UTC](https://community.crewai.com/t/crewai-is-not-allowing-the-use-of-a-knowledge-source-when-using-an-ollama-based-llm-it-defaults-to-requiring-an-openai-api-key-even-though-ollama-is-correctly-configure/3378/2 "2025-02-05T13:21:43Z")

</div>

same issue here when using ollama LLM with a knowledge source, keep getting asked for Open API key. Anyone manage to get to the bottom of this?

---

<div class="post-metadata">

**Author:** ![Ruben\_Casillas](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/ruben_casillas/32/439_2.png) [@Ruben\_Casillas](https://community.crewai.com/u/Ruben_Casillas)\
**Post date:** [February 5, 2025, 5:48pm UTC](https://community.crewai.com/t/crewai-is-not-allowing-the-use-of-a-knowledge-source-when-using-an-ollama-based-llm-it-defaults-to-requiring-an-openai-api-key-even-though-ollama-is-correctly-configure/3378/3 "2025-02-05T17:48:57Z")

</div>

I’ve been asking the same question for a week now.  
Any help will be appreciated

---

<div class="post-metadata">

**Author:** ![Guigui\_DuSud](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/guigui_dusud/32/2436_2.png) [@Guigui\_DuSud](https://community.crewai.com/u/Guigui_DuSud)\
**Post date:** [February 5, 2025, 8:21pm UTC](https://community.crewai.com/t/crewai-is-not-allowing-the-use-of-a-knowledge-source-when-using-an-ollama-based-llm-it-defaults-to-requiring-an-openai-api-key-even-though-ollama-is-correctly-configure/3378/4 "2025-02-05T20:21:44Z")

</div>

Happy to see i m not the only one ! Happy to know the right approach if not s pure bug ?

---

<div class="post-metadata">

**Author:** ![Crypto\_Gen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/crypto_gen/32/1605_2.png) [@Crypto\_Gen](https://community.crewai.com/u/Crypto_Gen)\
**Post date:** [February 6, 2025, 7:23am UTC](https://community.crewai.com/t/crewai-is-not-allowing-the-use-of-a-knowledge-source-when-using-an-ollama-based-llm-it-defaults-to-requiring-an-openai-api-key-even-though-ollama-is-correctly-configure/3378/5 "2025-02-06T07:23:55Z")

</div>

Another solution is mentioned here - [Unable to Initiate Crew using Local Ollama](https://community.crewai.com/t/unable-to-initiate-crew-using-local-ollama/1098)

Please check

---

<div class="post-metadata">

**Author:** ![Guigui\_DuSud](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/guigui_dusud/32/2436_2.png) [@Guigui\_DuSud](https://community.crewai.com/u/Guigui_DuSud)\
**Post date:** [February 6, 2025, 9:06am UTC](https://community.crewai.com/t/crewai-is-not-allowing-the-use-of-a-knowledge-source-when-using-an-ollama-based-llm-it-defaults-to-requiring-an-openai-api-key-even-though-ollama-is-correctly-configure/3378/6 "2025-02-06T09:06:13Z")

</div>

not at all memory issue . it is embeder issue that trigger open AI per default instead running ollama. see [String Knowledge sources not working with Gemini](https://community.crewai.com/t/string-knowledge-sources-not-working-with-gemini/2057)

---

<div class="post-metadata">

**Author:** ![Crypto\_Gen](https://sea1.discourse-cdn.com/flex025/user_avatar/community.crewai.com/crypto_gen/32/1605_2.png) [@Crypto\_Gen](https://community.crewai.com/u/Crypto_Gen)\
**Post date:** [February 6, 2025, 12:25pm UTC](https://community.crewai.com/t/crewai-is-not-allowing-the-use-of-a-knowledge-source-when-using-an-ollama-based-llm-it-defaults-to-requiring-an-openai-api-key-even-though-ollama-is-correctly-configure/3378/7 "2025-02-06T12:25:29Z")

</div>

Found a way to fix this. Use this approach. You can use a random/dummy API key for open ai API key env variable and then use the ChatOpenAI class instead of LLM class. It worked fine for me in local with the Ollama model

os.environ[“OPENAI\_API\_KEY”] = “testapikey”  
llm\_local = ChatOpenAI(  
model=“ollama/deepseek-r1:latest”,  
base\_url=“[http://localhost:11434](http://localhost:11434)”  
)
