chore: use hardcoded dummy API key

- Replace env-based API_KEY with sk-dummy-key hardcoded
- All entry points use same key: Authorization: Bearer sk-dummy-key
- Simplifies usage for library/client consumption

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-06-11 00:59:01 +07:00
co-authored by Claude Fable 5
parent c0a02279bd
commit 47b85fb396
3 changed files with 7 additions and 15 deletions
+1 -2
View File
@@ -41,10 +41,9 @@ const RELAY_VERSION = "1.0.0";
// ─── API Key Authentication ─────────────────────────────────────────────────────
const API_KEY = process.env.API_KEY ?? "";
const API_KEY = "sk-dummy-key";
function requireAuth(req: Request): Response | null {
if (!API_KEY) return null;
const header = req.headers.get("authorization") ?? req.headers.get("x-api-key") ?? "";
const key = header.replace(/^Bearer\s+/i, "").trim();
if (key === API_KEY) return null;
+1 -7
View File
@@ -45,15 +45,9 @@ const RELAY_VERSION = "1.0.0";
// ─── API Key Authentication ─────────────────────────────────────────────────────
const API_KEY = process.env.API_KEY ?? "";
const API_KEY = "sk-dummy-key";
/**
* Check if a request is authorized.
* Returns a 401 Response if unauthorized, or null if allowed.
* When API_KEY is empty, all requests pass through.
*/
function requireAuth(req: Request): Response | null {
if (!API_KEY) return null; // auth disabled
const header = req.headers.get("authorization") ?? req.headers.get("x-api-key") ?? "";
const key = header.replace(/^Bearer\s+/i, "").trim();
if (key === API_KEY) return null;
+5 -6
View File
@@ -70,11 +70,10 @@ function getClientIP(req: Request): string {
// ─── Auth Helper ─────────────────────────────────────────────────────────────────
function requireAuth(req: Request, apiKey: string | undefined): Response | null {
if (!apiKey) return null; // auth disabled
function requireAuth(req: Request): Response | null {
const header = req.headers.get("authorization") ?? req.headers.get("x-api-key") ?? "";
const key = header.replace(/^Bearer\s+/i, "").trim();
if (key === apiKey) return null;
if (key === "sk-dummy-key") return null;
return new Response(
JSON.stringify({ error: { message: "Unauthorized", type: "auth_error" } }),
{ status: 401, headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" } },
@@ -411,7 +410,7 @@ export default {
if (url.pathname === "/v1/chat/completions") {
if (req.method === "OPTIONS") return createCorsPreflightResponse();
if (req.method !== "POST") return new Response("Method Not Allowed", { status: 405 });
const authErr = requireAuth(req, env.API_KEY);
const authErr = requireAuth(req);
if (authErr) return authErr;
try {
const body = await req.json();
@@ -428,7 +427,7 @@ export default {
if (url.pathname === "/v1/messages") {
if (req.method === "OPTIONS") return createCorsPreflightResponse();
if (req.method !== "POST") return new Response("Method Not Allowed", { status: 405 });
const authErr = requireAuth(req, env.API_KEY);
const authErr = requireAuth(req);
if (authErr) return authErr;
try {
const body = await req.json();
@@ -443,7 +442,7 @@ export default {
// Models list
if (url.pathname === "/v1/models" && req.method === "GET") {
const authErr = requireAuth(req, env.API_KEY);
const authErr = requireAuth(req);
if (authErr) return authErr;
const models = listModels().map((id) => ({
id,