"use client"; import { useEffect, useState } from "react"; import { api, ApiError } from "@/lib/api"; import { fmtAgo, fmtDate, fmtNum } from "@/lib/format"; import type { ApiKey } from "@/lib/types"; import { Code, Modal, PageHeader, Pill, useToast } from "@/components/ui"; export default function KeysPage() { const toast = useToast(); const [keys, setKeys] = useState([]); const [name, setName] = useState(""); const [admin, setAdmin] = useState(false); const [created, setCreated] = useState(null); const [busy, setBusy] = useState(false); const load = () => api.get<{ keys: ApiKey[] }>("/api/keys").then((r) => setKeys(r.keys)).catch(() => {}); useEffect(() => { load(); }, []); const create = async (e: React.FormEvent) => { e.preventDefault(); setBusy(true); try { const r = await api.post<{ key: string }>("/api/keys", { name: name.trim() || "key", scopes: admin ? ["inference", "admin"] : ["inference"] }); setCreated(r.key); setName(""); setAdmin(false); load(); } catch (err) { toast.push(err instanceof ApiError ? err.message : "Failed", "bad"); } finally { setBusy(false); } }; const revoke = async (k: ApiKey) => { if (!confirm(`Revoke "${k.name}"? Clients using it will stop working.`)) return; await api.del(`/api/keys/${k.id}`); load(); }; const rename = async (k: ApiKey) => { const n = prompt("New name", k.name); if (!n) return; await api.patch(`/api/keys/${k.id}`, { name: n }); load(); }; const origin = typeof location !== "undefined" ? location.origin : "https://www.llm-api.io"; return (
{toast.view}
setName(e.target.value)} />
{keys.map((k) => ( ))} {!keys.length && }
NamePrefixScopesCreatedLast usedRequestsStatus
{k.name} {k.prefix}… {k.scopes.map((s) => {s})} {fmtDate(k.created_at)} {fmtAgo(k.last_used_at)} {fmtNum(k.request_count)} {k.revoked_at ? revoked : active} {!k.revoked_at && <> }
No keys yet.
setCreated(null)} title="Your new API key" width={640}>

Copy it now — it will not be shown again.

{created || ""}

Quick start:

{`from openai import OpenAI client = OpenAI(base_url="${origin}/v1", api_key="${created}") r = client.chat.completions.create(model="default", messages=[{"role": "user", "content": "Hello"}]) print(r.choices[0].message.content)`}
); }