πŸ”‘ How to Get Your OpenAI API Key

Sujin KooΒ·2025λ…„ 10μ›” 17일

[Eng] Dev Tips

λͺ©λ‘ 보기
1/2
post-thumbnail

βœ… What Is an API Key?

To use GPT models in your code, you need an API Key.

Instead of using ChatGPT through the website,
the OpenAI API lets you bring GPT directly into your own code.

With it, you can do things like πŸ‘‡

  • Automatically summarize new arXiv papers every morning (e.g., arxiv-daily-plus)
  • Build your own chatbot πŸ€–
  • Generate speech or images from text 🎨

The API Key acts as the β€œkey” that unlocks access to these models.
Here’s how you can create and use one.


1️⃣ Create an OpenAI Account

If you already have a ChatGPT account,
you can use it directly πŸ™Œ

You’ll need an OpenAI account first.

  1. Go to the OpenAI Sign Up Page.
  2. Sign in with your email, Google, or Microsoft account.
  3. Check your email to verify your account.
  4. Log in from the OpenAI Login Page.

2️⃣ Generate Your API Key

Now, let’s actually create your key πŸ”‘

  1. Go to the OpenAI Dashboard (top-right menu).

  2. In the left sidebar, click API keys.

  3. Click β€œCreate new secret key.”

  4. Choose any name you like (e.g., key4arxiv) and click β€œCreate secret key.”
    You’ll get a key that starts with sk-.

⚠️ The key will be shown only once!
Make sure to copy and save it securely.
(If you forget it, you’ll need to generate a new one πŸ˜…)


3️⃣ Keep Your Key Safe

This part is really important.
If someone else gets your API key, they can use GPT under your billing account β€” so make sure it’s secure.

- For Local Development (.env file)

OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx

Then load it in your code πŸ‘‡

import os
api_key = os.getenv("OPENAI_API_KEY")

- For GitHub Actions

In your GitHub repository β†’
Settings β†’ Security β†’ Secrets and variables β†’ Actions
Add a new secret named OPENAI_API_KEY.

For example, the arxiv-daily-plus project
fetches new papers every day and uses this key
to summarize them with GPT.


πŸ”’ Security Tips

  • Never upload your API key to GitHub ❌
  • Always add .env to your .gitignore file
  • If your key is exposed, delete it immediately from the API Keys page
profile
AI 😎

0개의 λŒ“κΈ€