Authentication
Complete guide to UniterRouter API authentication. Learn how to generate API keys, implement secure Bearer token auth, and protect your LLM API requests with best practices.
Authentication
All API requests to UniterRouter require authentication using an API key. This guide covers how to obtain and use your API key securely.
Obtaining an API Key
- Sign in to the UniterRouter Dashboard
- Navigate to your Project â API Keys
- Click Create API Key
- Copy the key immediately â it will only be shown once
Security Note: Your API key is a secret credential. Never expose it in client-side code, public repositories, or share it with others.
Using Your API Key
Include your API key in the Authorization header of every request using the Bearer token format:
Authorization: Bearer YOUR_API_KEYExample Request
curl https://api.uniterouter.ai/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $UNITEROUTER_API_KEY" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}]
}'import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.uniterouter.ai/v1",
api_key=os.environ.get("UNITEROUTER_API_KEY"),
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello!"}]
)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.uniterouter.ai/v1",
apiKey: process.env.UNITEROUTER_API_KEY,
});
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }],
});package main
import (
"context"
"os"
openai "github.com/sashabaranov/go-openai"
)
func main() {
config := openai.DefaultConfig(os.Getenv("UNITEROUTER_API_KEY"))
config.BaseURL = "https://api.uniterouter.ai/v1"
client := openai.NewClientWithConfig(config)
resp, _ := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: "gpt-4o",
Messages: []openai.ChatCompletionMessage{
{Role: "user", Content: "Hello!"},
},
},
)
}Environment Variables
We recommend storing your API key in environment variables:
# Add to your shell profile (.bashrc, .zshrc, etc.)
export UNITEROUTER_API_KEY="sk_..."For production applications, use a secrets manager or environment configuration provided by your deployment platform.
API Key Formats
UniterRouter API keys follow this format:
| Prefix | Description |
|---|---|
sk_ | Standard API key |
sk_test_ | Test environment key (if applicable) |
Authentication Errors
If authentication fails, the API returns a 401 Unauthorized response:
{
"error": {
"message": "Incorrect API key provided. You can find your API key at https://uniterouter.ai/dashboard.",
"type": "invalid_request_error",
"code": "invalid_api_key"
}
}Common authentication issues:
| Issue | Solution |
|---|---|
Missing Authorization header | Add the header with your API key |
| Invalid key format | Ensure the key starts with the correct prefix |
| Expired or revoked key | Generate a new key in the dashboard |
| Key belongs to disabled project | Re-enable the project or use a different key |
Security Best Practices
Recommended Security Practices
- Never hardcode API keys â Use environment variables or secrets managers
- Rotate keys periodically â Create new keys and deprecate old ones
- Use separate keys per environment â Different keys for development, staging, and production
- Set usage limits â Configure spending limits on each API key
- Monitor usage â Regularly review API key activity in the dashboard
- Revoke compromised keys immediately â If a key is exposed, disable it and create a new one
Organization & Project Structure
UniterRouter uses a hierarchical structure for access management:
Organization
âââ Project
âââ API Keys- Organization: Your top-level account
- Project: A logical grouping of API keys and settings
- API Key: Credentials scoped to a specific project
Each API key inherits the permissions and settings of its parent project.
Next Steps
- Learn about API Key Management & IAM Rules
- Explore the API Reference
- Set up Error Handling
How is this guide?
Quick Start
Start using UniterRouter's unified AI API in minutes. Step-by-step guide to integrate GPT-4, Claude, Gemini and 200+ LLM models into your Python, JavaScript, or cURL applications.
Error Handling
UniterRouter API error codes and troubleshooting guide. Handle rate limits, authentication errors, model errors for GPT-4, Claude, Gemini APIs with best practices.