# 02. OpenAI API key issuance and testing

### OpenAI API key issuance and setup <a href="#openai-api" id="openai-api"></a>

1\) OpenAI API key issuance

**Access to OpenAI API web site** To.

* link: <https://platform.openai.com/docs/overview>

Top right **"Sign Up"** Press **Membership** To. (If you are already signed up **Press the "Log in" button to log in** To.

![](https://wikidocs.net/images/page/233342/capture-20240611-114944.png)

Top right **Set by pressing Setting** Go to

\
Top right **Set by pressing Setting** Go to

![](https://wikidocs.net/images/page/233342/capture-20240611-115127.png)

left **"Billing"** From menu **"Payment methods"** Click **Register a credit card** To.

![](https://wikidocs.net/images/page/233342/capture-20240611-115218.png)

If you have registered a credit card, the registered credit card will appear in the list as below.

<br>

![](https://wikidocs.net/images/page/233342/capture-20240611-115316.png)

**"Add to credit balance"** Press the button to enter the US dollar (dollar) to use.

![](https://wikidocs.net/images/page/233342/capture-20240611-115442.png)

amount **$5** You can add a booster. (In other words, the minimum payment amount $5 or higher must be paid)

After entering the amount **"Continue"** Press to proceed with payment.

![](https://wikidocs.net/images/page/233342/capture-20240611-115549.png)

Left **"Limits"** You can set the monthly usage on the tab.

* **"Set a month budge"** : Specifies monthly usage. When this amount is reached, the API will stop using it without further billing.
* **"Set an email notification threshold"** : You can specify the rate at which the email is sent. An email will be sent when this amount is reached.

![](https://wikidocs.net/images/page/233342/capture-20240611-115735.png)

Right **Profile image** click - **"Your profile"**

![](https://wikidocs.net/images/page/233342/capture-20240611-212254.png)

**API Key Management Menu** Access with.

* <https://platform.openai.com/api-keys>

**"Create new secret key"** Click.

![](https://wikidocs.net/images/page/233342/capture-20240611-212634.png)

**Name** and **project** Enter. (If you don't have a project you created separately, set up Default project)

![](https://wikidocs.net/images/page/233342/capture-20240611-212716.png)

Right **"Copy"** Press the button to copy the key.

**caution!!!**

* When the key is leaked, someone else can use my API KEY to use GPT, and payments are made in my wallet.
* never **Keep the key in a safe place, not share it with others** Do it! (I think it's a password)

![](https://wikidocs.net/images/page/233342/capture-20240611-212824.png)

2\) `.env` File settings

1. To the project root directory `.env` Create a file.
2. `.env` To file `OPENAI_API_KEY=방금복사한 키를 입력` Press Ctrl + S to save and close the file.

![](https://wikidocs.net/images/page/233342/capture-20240611-213141.png)

```python
# LangChain 업데이트
!pip install -r https://raw.githubusercontent.com/teddylee777/langchain-kr/main/requirements.txt
```

```python
# API KEY를 환경변수로 관리하기 위한 설정 파일
# 설치: pip install python-dotenv
from dotenv import load_dotenv

# API KEY 정보로드
load_dotenv()
```

```
 True 
```

Make sure API Key is set well.

```python
Copyimport os

print(f"[API KEY]\n{os.environ['OPENAI_API_KEY']}")
```

<br>
