How to Connect Your Own AI Model: OpenRouter, Custom APIs, and Proxies
In 2026, flexibility in working with artificial intelligence is not a luxury but a necessity. There is no longer any point in being tied to a single provider: ChatGPT, Claude, Gemini, or local LLMs. True freedom begins when you know how to connect an AI model through universal tools — OpenRouter, custom endpoints, or proxies. In this article, I'll show you how to set everything up in 15 minutes, without unnecessary code and with full control over costs.
Why Should You Abandon a Single Provider?
The AI model market in 2026 consists of dozens of solutions: from open-source (Llama 3, Mistral) to proprietary (GPT-4o, Claude 3.5 Sonnet). Each model excels in its own task: one writes code, another creates creative texts, and a third analyzes data. If you use only one AI provider, you lose out on speed, quality, and price. OpenRouter solves this problem by combining dozens of models under a single API.
Step 1. Connecting via OpenRouter
OpenRouter is an API aggregator that provides access to 50+ models through a single key. Here's how to set it up:
- Register at openrouter.ai and get an API key in the "Keys" section.
- Choose a model — for example,
anthropic/claude-3.5-sonnetoropenai/gpt-4o. - Send a request via cURL or any HTTP client:
curl -X POST https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-3.5-sonnet",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Tip: OpenRouter supports fallback — if a model is unavailable, the request is automatically redirected to a backup. This increases fault tolerance.
Step 2. Custom APIs and Endpoints
If you need privacy or a specific model (e.g., locally deployed), use a custom API. This could be:
- A local server (via Ollama, vLLM, llama.cpp).
- Your own cloud instance (AWS, GCP, Azure).
- A private API from a closed provider.
Connection principle:
- Deploy the model (e.g.,
ollama run llama3.2). - Get the endpoint — usually
http://localhost:11434/api/chat. - Set up a proxy layer for request routing.
Example in Python using the requests library:
import requests
response = requests.post(
"http://localhost:11434/api/chat",
json={
"model": "llama3.2",
"messages": [{"role": "user", "content": "Tell me about AI"}]
}
)
print(response.json())
Step 3. Proxy as a Universal Layer
A proxy server (e.g., Nginx, Traefik, or Cloudflare Workers) allows you to:
- Route requests between providers.
- Cache responses to save costs.
- Add logic (load balancing, authentication).
Example of setting up a simple proxy in Node.js:
const express = require('express');
const axios = require('axios');
const app = express();
app.post('/chat', async (req, res) => {
const provider = req.query.provider || 'openrouter';
const endpoints = {
'openrouter': 'https://openrouter.ai/api/v1/chat/completions',
'openai': 'https://api.openai.com/v1/chat/completions'
};
const response = await axios.post(endpoints[provider], req.body, {
headers: { Authorization: `Bearer ${process.env.API_KEY}` }
});
res.json(response.data);
});
app.listen(3000);
Comparison of Connection Methods
| Criteria | OpenRouter | Custom API | Proxy |
|---|---|---|---|
| Ease of setup | High | Medium | Low |
| Model flexibility | 50+ | 1–5 | Any |
| Data control | Low | Full | Medium |
| Cost | Pay-as-you-go | Fixed | Depends on |
| Fault tolerance | Built-in | Manual | Manual |
Practical Tips for Saving Money
- Use request caching via Redis — repeated questions won't be charged.
- Choose models with m
Comments