# First\_agent\_template issue app.py

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffirst-agent-template-issue-app-py%2F157024%3E%5C
**Category:** Beginners\
**Created:** [May 27, 2025, 4:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffirst-agent-template-issue-app-py%2F157024 "2025-05-27T16:25:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![WingNeville](https://avatars.discourse-cdn.com/v4/letter/w/e9a140/32.png) [@WingNeville](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FWingNeville)%5C
**Post date:** [May 27, 2025, 4:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffirst-agent-template-issue-app-py%2F157024%2F1 "2025-05-27T16:25:09Z")

</div>

Hi everyone,

I’m new here and currently working on my first agent course. I’m trying to build my first agent, but I’m having some difficulties managing the API key.

I followed the steps outlined in this discussion ([ysharma/ChatGPT4 · how to use openai api key?](https://huggingface.co/spaces/ysharma/ChatGPT4/discussions/23)), but I’m still encountering an error.

I put this code at the top

| | from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load\_tool,tool |
| --- | --- |
| | import datetime |
| | import requests |
| | import pytz |
| | import yaml |
| | from tools.final\_answer import FinalAnswerTool |
| | from openai import OpenAI |
| | import gradio as gr |
| | import os |
| | api\_key = os.getenv(“OPENAI\_API\_KEY”) |
| | client = OpenAI(api\_key=api\_key) |

==================================================

# runtime error

## Exit code: 1. Reason: Traceback (most recent call last): File “/home/user/app/app.py”, line 7, in from openai import OpenAI ModuleNotFoundError: No module named ‘openai’

Container logs:

```auto
===== Application Startup at 2025-05-27 16:31:22 =====

Traceback (most recent call last):
  File "/home/user/app/app.py", line 7, in <module>
    from openai import OpenAI
ModuleNotFoundError: No module named 'openai'

```

```auto

```

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/64626_2.png) [@mahmutc](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmahmutc)%5C
**Post date:** [May 27, 2025, 5:34pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffirst-agent-template-issue-app-py%2F157024%2F2 "2025-05-27T17:34:55Z")

</div>

Have you already installed OpenAI?

`pip install openai`

Let us know if you’re using a Hugging Face Space, Dockerfile, or something else — We can tailor the solution further!

---

<div class="post-metadata">

**Author:** ![mahmutc](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mahmutc/32/64626_2.png) [@mahmutc](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmahmutc)%5C
**Post date:** [May 27, 2025, 5:40pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffirst-agent-template-issue-app-py%2F157024%2F3 "2025-05-27T17:40:44Z")

</div>

[Handling Spaces Dependencies](https://huggingface.co/docs/hub/en/spaces-dependencies) gives more information about Space dependencies.

---

<div class="post-metadata">

**Author:** ![WingNeville](https://avatars.discourse-cdn.com/v4/letter/w/e9a140/32.png) [@WingNeville](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FWingNeville)%5C
**Post date:** [May 28, 2025, 9:13am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffirst-agent-template-issue-app-py%2F157024%2F4 "2025-05-28T09:13:30Z")

</div>

Thanks for your reply.

Currently, I am following the course outline to use the space from Hugging Face.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [May 28, 2025, 10:12am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffirst-agent-template-issue-app-py%2F157024%2F5 "2025-05-28T10:12:19Z")

</div>

If you have space on your base, add the following line to `requirements.txt` and it should work. If you don’t have`requirements.txt`, just create it.

```auto
openai

```
