What you'll build
You'll complete the trio by creating a chatbot with OpenAI's API, the creators of ChatGPT. The process is identical to Gemini and Claude: get API key, create the code, run it. When you're done, you'll know how to connect to the three main AI providers: Gemini, Claude, and OpenAI. You'll have the flexibility to choose any provider based on costs, capabilities, or project preferences.
โ ๏ธ Note: OpenAI API requires adding credits. Minimum $5 USD.
Step 1: Get your OpenAI API Key
- Go to platform.openai.com
- Create an account or sign in
- Go to API Keys (left menu)
- Click Create new secret key
- Copy the key (only shown once)
Step 2: Add credits
- Go to Settings โ Billing
- Add a payment method
- Add credits (minimum $5)
๐ก $5 USD is enough for thousands of messages with GPT-4o-mini.
Step 3: Ask an AI to write the code
Open Google AI Studio, ChatGPT, or any AI chat.
Copy and paste this prompt:
I need a simple Node.js chatbot that:
- Uses the OpenAI API (GPT-4o-mini)
- Works in the terminal
- Maintains conversation history
- Reads the API key from the OPENAI_API_KEY environment variable
Give me the complete code and installation commands.
Step 4: Configure the key in your system
| System | Command |
|---|---|
| macOS/Linux | export OPENAI_API_KEY="your-key-here" |
| Windows PowerShell | $env:OPENAI_API_KEY="your-key-here" |
Step 5: Follow the instructions
The AI gave you:
- Commands to create the project
- Code for the file
- The command to run it
Follow its instructions step by step.
Did it work?
You: Hello GPT
GPT: Hello! How can I help you?
If something failed
| Error | Cause | Solution |
|---|---|---|
invalid_api_key | Wrong key | Check at platform.openai.com/api-keys |
insufficient_quota | No credits | Add credits in Billing |
Cannot find module | Missing SDK | Run npm install openai |
rate_limit_exceeded | Too many requests | Wait a few seconds |
model_not_found | Wrong model | Use gpt-4o-mini or gpt-4o |
Comparison: Which one to use?
| API | Cost | Strength | Best for |
|---|---|---|---|
| Gemini | Free | Easy to start | Learning, prototypes |
| Claude | ~$3/M tokens | Code, reasoning | Serious development |
| OpenAI | ~$0.15/M tokens | Versatile, ecosystem | Production, plugins |
๐ก For learning, use Gemini. For serious projects, try all three and choose.
What's next?
You've completed the cloud API trio. Now you can:
โ Local Chatbot with Ollama โ 100% private, no internet โ Chat with Web UI โ Give it a nice face
Want to understand more?
โ What is an LLM?