"use client"; import { useState, useEffect, useCallback } from "react"; import Card from "@/shared/components/Card"; import Badge from "@/shared/components/Badge"; import Button from "@/shared/components/Button"; import { useNotificationStore } from "@/store/notificationStore"; interface RelayToken { id: string; name: string; tokenPrefix: string; description: string; comboId: string | null; allowedModels: string; maxRequestsPerMinute: number; maxRequestsPerDay: number; enabled: boolean; createdAt: number; lastUsedAt: number | null; } export default function RelayProxyClient() { const [tokens, setTokens] = useState([]); const [loading, setLoading] = useState(true); const [showCreate, setShowCreate] = useState(false); const [newTokenData, setNewTokenData] = useState<{ rawToken: string; name: string } | null>(null); const [form, setForm] = useState({ name: "", description: "", maxRpm: "60", maxRpd: "10000" }); const addNotification = useNotificationStore((s) => s.addNotification); const fetchTokens = useCallback(async () => { setLoading(true); try { const res = await fetch("/api/relay/tokens"); const data = await res.json(); setTokens(Array.isArray(data) ? data : []); } catch { setTokens([]); } finally { setLoading(false); } }, []); useEffect(() => { fetchTokens(); }, [fetchTokens]); const createToken = async () => { if (!form.name.trim()) return; try { const res = await fetch("/api/relay/tokens", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ name: form.name, description: form.description, maxRequestsPerMinute: Number(form.maxRpm), maxRequestsPerDay: Number(form.maxRpd), }), }); const data = await res.json(); if (res.ok) { setNewTokenData({ rawToken: data.rawToken, name: data.name }); setForm({ name: "", description: "", maxRpm: "60", maxRpd: "10000" }); setShowCreate(false); addNotification({ type: "success", message: "Relay token created" }); fetchTokens(); } else { addNotification({ type: "error", message: data.error || "Failed to create token" }); } } catch { addNotification({ type: "error", message: "Failed to create token" }); } }; const toggleToken = async (id: string, enabled: boolean) => { try { await fetch(`/api/relay/tokens/${id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ enabled }), }); fetchTokens(); } catch { addNotification({ type: "error", message: "Failed to toggle token" }); } }; const deleteToken = async (id: string) => { if (!confirm("Delete this relay token? This cannot be undone.")) return; try { await fetch(`/api/relay/tokens/${id}`, { method: "DELETE" }); addNotification({ type: "success", message: "Token deleted" }); fetchTokens(); } catch { addNotification({ type: "error", message: "Failed to delete token" }); } }; return (

Serverless Relay Proxies

Create public API endpoints that proxy to OmniRoute with rate limiting and access control

{/* Create Form */} {showCreate && (

Create Relay Token

setForm({ ...form, name: e.target.value })} placeholder="my-api-relay" />
setForm({ ...form, description: e.target.value })} placeholder="For my serverless functions" />
setForm({ ...form, maxRpm: e.target.value })} />
setForm({ ...form, maxRpd: e.target.value })} />
)} {/* Token Display (shown once after creation) */} {newTokenData && (

Token Created — Copy it now!

Token for {newTokenData.name}:

{newTokenData.rawToken}

This token will not be shown again. Store it securely.

)} {/* Usage Guide */}

Usage

Send requests to your relay endpoint:

{`curl http://localhost:20128/v1/relay/chat/completions \\
  -H "Authorization: Bearer relay_..." \\
  -H "Content-Type: application/json" \\
  -d '{"model":"claude-sonnet-4","messages":[{"role":"user","content":"Hello"}]}'`}
          
{/* Tokens List */}

Relay Tokens ({tokens.length})

{loading ? (

Loading...

) : tokens.length === 0 ? (

No relay tokens configured. Create one to get started.

) : (
{tokens.map((t) => (
{t.name}
{t.tokenPrefix}...
{t.description && (
{t.description}
)}
{t.maxRequestsPerMinute}/min {t.maxRequestsPerDay}/day
))}
)}
); }