Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
import { NextResponse } from "next/server";
import { getApiKeyById } from "@/lib/db/apiKeys";
import { isApiKeyRevealEnabled } from "@/lib/apiKeyExposure";
import {
requireCredentialForManagementScopedKey,
requireManagementAuth,
} from "@/lib/api/requireManagementAuth";
import * as log from "@/sse/utils/logger";
// GET /api/keys/[id]/reveal - Reveal full API key for explicit copy actions
export async function GET(request, { params }) {
const authError = await requireManagementAuth(request);
if (authError) return authError;
try {
if (!isApiKeyRevealEnabled()) {
return NextResponse.json({ error: "API key reveal is disabled" }, { status: 403 });
}
const { id } = await params;
const key = await getApiKeyById(id);
if (!key || typeof key.key !== "string") {
return NextResponse.json({ error: "Key not found" }, { status: 404 });
}
const scopeAuthError = await requireCredentialForManagementScopedKey(request, key.scopes);
if (scopeAuthError) return scopeAuthError;
return NextResponse.json({ key: key.key });
} catch (error) {
log.error("keys", "Error revealing key", error);
return NextResponse.json({ error: "Failed to reveal key" }, { status: 500 });
}
}