mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-01 04:42:10 +03:00
OmniRoute is an intelligent API gateway that unifies 20+ AI providers behind a single OpenAI-compatible endpoint. Features include intelligent routing with 6 strategies, multi-format translation (OpenAI/Claude/Gemini/Responses API), circuit breakers, semantic caching, combo fallback chains, real-time health monitoring, and a full dashboard with provider management, analytics, and CLI tool integration. Key highlights: - 20+ providers (Claude Code, Codex, Gemini CLI, GitHub Copilot, iFlow, Qwen, Kiro, etc.) - 6 routing strategies (Fill First, Round Robin, P2C, Random, Least Used, Cost Optimized) - Export/Import database backup with full archive support - Translator Playground with 4 modes (Playground, Chat Tester, Test Bench, Live Monitor) - 100% TypeScript across src/ and open-sse/ - Docker support with multi-stage builds - Comprehensive documentation and 9 dashboard screenshots
66 lines
1.6 KiB
TypeScript
66 lines
1.6 KiB
TypeScript
/**
|
|
* API utility functions for making HTTP requests
|
|
*/
|
|
|
|
const DEFAULT_HEADERS: Record<string, string> = {
|
|
"Content-Type": "application/json",
|
|
};
|
|
|
|
interface ApiOptions extends RequestInit {
|
|
headers?: Record<string, string>;
|
|
}
|
|
|
|
export async function get(url: string, options: ApiOptions = {}) {
|
|
const response = await fetch(url, {
|
|
method: "GET",
|
|
headers: { ...DEFAULT_HEADERS, ...options.headers },
|
|
...options,
|
|
});
|
|
return handleResponse(response);
|
|
}
|
|
|
|
export async function post(url: string, data: unknown, options: ApiOptions = {}) {
|
|
const response = await fetch(url, {
|
|
method: "POST",
|
|
headers: { ...DEFAULT_HEADERS, ...options.headers },
|
|
body: JSON.stringify(data),
|
|
...options,
|
|
});
|
|
return handleResponse(response);
|
|
}
|
|
|
|
export async function put(url: string, data: unknown, options: ApiOptions = {}) {
|
|
const response = await fetch(url, {
|
|
method: "PUT",
|
|
headers: { ...DEFAULT_HEADERS, ...options.headers },
|
|
body: JSON.stringify(data),
|
|
...options,
|
|
});
|
|
return handleResponse(response);
|
|
}
|
|
|
|
export async function del(url: string, options: ApiOptions = {}) {
|
|
const response = await fetch(url, {
|
|
method: "DELETE",
|
|
headers: { ...DEFAULT_HEADERS, ...options.headers },
|
|
...options,
|
|
});
|
|
return handleResponse(response);
|
|
}
|
|
|
|
async function handleResponse(response: Response) {
|
|
const data = await response.json();
|
|
|
|
if (!response.ok) {
|
|
const error: any = new Error(data.error || "An error occurred");
|
|
error.status = response.status;
|
|
error.data = data;
|
|
throw error;
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
const api = { get, post, put, del };
|
|
export default api;
|