Getting Started with AI Gateway: A Developer's Guide
This guide walks you through setting up AI Gateway and making your first API call. By the end, you'll have a working integration that routes requests across multiple AI models through a single endpoint.
Step 1: Create Your Account
Head to ai.hopeagrico.com and sign up for a free account. The free tier includes enough credits to thoroughly test the platform with no time limit.
Once registered, navigate to the dashboard and open the API Keys section. Click Create Key, give it a name like "dev-testing", and copy the generated key. Treat it like a password — you won't be able to see it again.
Step 2: Make Your First Request
AI Gateway uses the OpenAI-compatible API format. If you've used the OpenAI SDK before, you can point it at our endpoint with zero code changes. Here's a quick example using curl:
curl https://ai.hopeagrico.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello, world!"}]
}'
That's it. You'll get back a standard OpenAI-format response with the model's completion.
Step 3: Understand Model Selection
By default, AI Gateway lets you specify which model to use. You can choose from GPT-4o, Claude 3.5 Sonnet, Gemini Pro, Mistral, Llama, and more. Each model has different characteristics:
- **gpt-4o** — Best for complex reasoning and code generation
- **claude-3-5-sonnet** — Excellent for long-form content and instruction following
- **gemini-pro** — Strong at multimodal tasks and large contexts
- **mistral** — Fast and cost-effective for simpler tasks
- **llama-3** — Open-source option with solid general performance
Step 4: Enable Smart Routing
Once you're comfortable with manual model selection, enable smart routing by setting "model": "auto" in your request. The gateway will analyze your prompt and route it to the best model for the task. This typically gives you the best balance of quality and cost.
You can configure routing preferences in the dashboard — for example, prioritizing lower cost, higher speed, or specific providers.
Step 5: Monitor Your Usage
The dashboard provides real-time usage analytics. Track token consumption, costs per model, response times, and error rates. Set up usage alerts to avoid surprises when approaching your credit limit.
Tips for Production
- **Use environment variables** to store your API key, never hardcode it
- **Implement retry logic** with exponential backoff for rate-limited requests
- **Set max_tokens** appropriately to control costs
- **Start with smart routing** and override with specific models only when you have a reason
You're now ready to integrate AI Gateway into your application. Check out our other guides for advanced topics like cost optimization, streaming responses, and building AI-powered workflows.