Skip to main content

Prerequisites

  • MegaLLM API key (Get one here)
  • Python 3.7+ or Node.js 14+ installed
  • Basic programming knowledge

Step 1: Create Project

Step 2: Store API Key

Create a .env file:
Add .env to .gitignore to avoid committing your API key!

Step 3: Basic Request

Create app.py:
Run it:

Step 4: Add Conversation Context

Let’s make it conversational:

Step 5: Try Different Models

Switch models by changing the model parameter:

Step 6: Add Parameters

Customize the response with parameters:

Step 7: Error Handling

Add proper error handling:

Step 8: Interactive Chat

Build a simple chatbot:

Understanding the Response

The API returns a rich response object:

Next Steps

Streaming

Real-time streaming responses

Function Calling

Let AI use external tools

Browse Models

Explore all available models

Best Practices

Tips for production apps

Troubleshooting

Make sure you installed the SDK:
  • Check your API key is correct
  • Verify .env file is in the same directory
  • Make sure you called load_dotenv() (Python) or dotenv.config() (JS)
  • You’re making too many requests
  • Add delays between requests
  • Consider upgrading your plan
  • Try a faster model like gpt-3.5-turbo
  • Reduce max_tokens
  • Use streaming for better UX

Need Help?