Omni Gateway Cổng Định Tuyến AI Omni Gateway
A universal AI routing gateway with smart multi-provider fallback, token-aware request cleanup, format translation across OpenAI, Gemini, and Anthropic, and secure credential pool management. Cổng trung chuyển và định tuyến AI đa nhà cung cấp với cơ chế chuyển đổi dự phòng thông minh, tự động cắt tỉa tối ưu token, chuẩn hóa giao thức giữa OpenAI, Gemini, Claude và quản lý kho khóa an toàn.
🌟 Executive Overview
Omni Gateway is an enterprise-grade, universal AI router and proxy built for modern AI coding tools, IDE assistants, and autonomous agentic workflows (e.g. Codex, Claude Code, Antigravity, OpenCode, Aider).
Modern developer setups often juggle heterogeneous clients and model providers: OpenAI-compatible tooling, Gemini-native SDKs, Anthropic-style agents, and emerging xAI Grok APIs. Omni Gateway sits transparently between these clients and backends, providing automatic resilience, rate-limit bypass, fair credential rotation, and cross-format payload translation through a single unified API surface.
🏗️ Architectural Matrix
flowchart TD
Client["AI Coding Agents / IDE Assistants\n(Claude Code, Codex, Antigravity, Aider)"] -->|"Universal API / REST"| Router["Omni Gateway Engine\n(FastAPI + AsyncIO)"]
subgraph Engine ["Core Processing Pipeline"]
Router --> Auth["Credential Vault & Fingerprinting\n(OAuth PKCE, API Keys, Non-reversible hashes)"]
Auth --> TokenEngine["Token-Aware Trimmer\n(Sliding Turn Window, Preserves Tool & System Prompts)"]
TokenEngine --> Translater["Protocol Adapter\n(OpenAI ⟷ Gemini ⟷ Anthropic Messages)"]
end
Translater --> Fallback["Smart Circuit Breaker & Fallback Pool"]
Fallback -->|Primary Route| Google["Google Gemini / Vertex AI"]
Fallback -->|Auto Failover 1| OpenAI["OpenAI Platform / Codex"]
Fallback -->|Auto Failover 2| Anthropic["Anthropic Claude"]
Fallback -->|Auto Failover 3| XAI["xAI Grok / SpaceXAI"]
Engine -.-> Storage[("State & Analytics\nSQLite WAL / Postgres / Redis")]
🚀 Key Engineering Breakthroughs
1. Smart Auto-Fallback & Circuit Breaking
- Credential Reservation: Concurrently balances load across multiple active accounts and API keys.
- Dynamic Failover: Detects HTTP 429 rate limits, HTTP 5xx backend downtime, token quota depletion, and transient network errors within milliseconds, seamlessly rerouting the in-flight prompt to healthy standby providers.
- Fair Usage Rotation: Implements round-robin and least-recently-used heuristics to prevent hitting single-account concurrency caps.
2. Token-Aware Sliding Window Normalization
- AI coding agents frequently send oversized conversation histories that exceed provider context windows.
- Omni Gateway analyzes token budgets and prunes older dialogue turns strictly at conversational turn boundaries—guaranteeing that crucial system instructions, active tool declarations, and the latest turns remain intact.
3. Bi-directional Protocol Translation
- Accept requests formatted for OpenAI Chat Completions, Gemini Native API, or Anthropic Messages API.
- Converts streaming server-sent events (SSE) dynamically, ensuring clients receive tokens in their native streaming syntax regardless of the underlying model answering the call.
4. Zero-Leak Credential Vault & Deduplication
- Secures OAuth PKCE refresh tokens, Google Antigravity session keys, and OpenAI platform secrets.
- Uses SHA-256 non-reversible fingerprinting for deduplication during bulk credential imports (
.zip,.json) without logging or exposing plaintext credentials.
📦 Deployment & Containerization
Available directly as a multi-arch container on GitHub Packages and Docker Hub:
docker pull ghcr.io/nguywnben/omni-gateway:latest
docker run -d \
-p 8000:8000 \
-v /opt/omni-gateway/creds:/app/backend/data/creds \
-v /opt/omni-gateway/logs:/app/backend/data/logs \
-e API_KEY="your-gateway-secret" \
-e PANEL_PASSWORD="your-console-password" \
ghcr.io/nguywnben/omni-gateway:latest
🌟 Tổng Quan Kiến Trúc
Omni Gateway là cổng định tuyến (router) và proxy AI cấp doanh nghiệp, được thiết kế chuyên biệt cho các công cụ AI coding, trợ lý IDE và quy trình AI agent tự trị (như Codex, Claude Code, Antigravity, OpenCode, Aider).
Trong thực tế phát triển, kỹ sư thường phải xử lý nhiều nhà cung cấp mô hình khác nhau: công cụ tương thích OpenAI, SDK chính thống của Google Gemini, agent chuẩn Anthropic Claude và API xAI Grok. Omni Gateway hoạt động như một lớp trung gian trong suốt, cung cấp khả năng tự phục hồi lỗi, vượt giới hạn tần suất (rate-limit bypass), luân chuyển kho khóa thông minh và chuyển đổi định dạng giao thức linh hoạt thông qua một endpoint duy nhất.
🏗️ Sơ Đồ Kiến Trúc Hệ Thống
flowchart TD
Client["AI Coding Agents / Trợ Lý IDE\n(Claude Code, Codex, Antigravity, Aider)"] -->|"API Hợp Nhất / REST"| Router["Động Cơ Omni Gateway\n(FastAPI + AsyncIO)"]
subgraph Engine ["Quy Trình Xử Lý Cốt Lõi"]
Router --> Auth["Kho Khóa An Toàn & Định Danh\n(OAuth PKCE, API Key, Mã băm không hoàn nguyên)"]
Auth --> TokenEngine["Bộ Tối Ưu Ngữ Cảnh Token\n(Sliding Window, Giữ nguyên System Prompt & Tool)"]
TokenEngine --> Translater["Bộ Chuyển Đổi Giao Thức\n(OpenAI ⟷ Gemini ⟷ Anthropic Messages)"]
end
Translater --> Fallback["Cơ Chế Ngắt Mạch & Dự Phòng Tự Động"]
Fallback -->|Tuyến chính| Google["Google Gemini / Vertex AI"]
Fallback -->|Dự phòng 1| OpenAI["OpenAI Platform / Codex"]
Fallback -->|Dự phòng 2| Anthropic["Anthropic Claude"]
Fallback -->|Dự phòng 3| XAI["xAI Grok / SpaceXAI"]
Engine -.-> Storage[("Lưu Trữ Trạng Thái & Thống Kê\nSQLite WAL / Postgres / Redis")]
🚀 Các Đột Phá Kỹ Thuật Trọng Tâm
1. Tự Động Chuyển Đổi Dự Phòng & Ngắt Mạch Thông Minh (Circuit Breaking)
- Đặt trước tài nguyên (Credential Reservation): Cân bằng tải đồng thời giữa nhiều tài khoản và API key đang hoạt động.
- Dự phòng thời gian thực: Phát hiện tức thì các lỗi HTTP 429 (vượt hạn ngạch), HTTP 5xx (máy chủ gián đoạn) hoặc lỗi mạng trong vài mili-giây để định tuyến yêu cầu sang các nhà cung cấp dự phòng khỏe mạnh.
- Thuật toán luân chuyển công bằng: Áp dụng round-robin và least-recently-used để tránh chạm giới hạn đồng thời của từng tài khoản đơn lẻ.
2. Cắt Tỉa Ngữ Cảnh Token Theo Sliding Window
- Các AI coding agent thường gửi kèm lịch sử hội thoại rất dài, dễ làm tràn cửa sổ ngữ cảnh của mô hình.
- Omni Gateway phân tích ngân sách token và cắt tỉa các lượt hội thoại cũ theo đúng ranh giới của từng lượt trao đổi — đảm bảo tuyệt đối rằng chỉ dẫn hệ thống (system prompt), định nghĩa công cụ (tools) và các lượt hội thoại mới nhất luôn được giữ nguyên vẹn.
3. Chuyển Đổi Giao Thức Hai Chiều
- Tiếp nhận yêu cầu theo mọi định dạng: OpenAI Chat Completions, Gemini Native API hoặc Anthropic Messages API.
- Tự động chuyển đổi luồng dữ liệu Server-Sent Events (SSE) theo thời gian thực, đảm bảo client nhận đúng cú pháp streaming mà không phụ thuộc vào việc mô hình nào ở backend đang trả lời.
4. Kho Khóa Bảo Mật Không Thất Thoát (Zero-Leak)
- Lưu trữ an toàn refresh token OAuth PKCE, khóa phiên Google Antigravity và bí mật OpenAI.
- Sử dụng thuật toán băm SHA-256 không thể hoàn nguyên để khử trùng lặp khóa khi nhập hàng loạt (
.zip,.json) mà không bao giờ ghi nhật ký (log) khóa gốc dạng văn bản thuần.
📦 Triển Khai & Container Hóa
Được đóng gói sẵn dưới dạng multi-arch container trên GitHub Packages và Docker Hub:
docker pull ghcr.io/nguywnben/omni-gateway:latest
docker run -d \
-p 8000:8000 \
-v /opt/omni-gateway/creds:/app/backend/data/creds \
-v /opt/omni-gateway/logs:/app/backend/data/logs \
-e API_KEY="khoa-bi-mat-gateway-cua-ban" \
-e PANEL_PASSWORD="mat-khau-quan-tri-bang-dieu-khien" \
ghcr.io/nguywnben/omni-gateway:latest