Skip to content

Commit c1d0139

Browse files
committed
fix: Remove query parameter fallback for API key extraction and simplify error messages
1 parent fb889b9 commit c1d0139

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/lib/api-key-auth.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ function extractApiKey(c: Context): string | undefined {
2222
return anthropicKey
2323
}
2424

25-
// Fallback: query parameter, for extra compatibility of `/usage` or `/token` route
26-
const queryKey = c.req.query("apiKey")
27-
if (queryKey) {
28-
return queryKey
29-
}
30-
3125
return undefined
3226
}
3327

@@ -47,8 +41,7 @@ export const apiKeyAuthMiddleware: MiddlewareHandler = async (c, next) => {
4741
// If no API key is provided, return 401
4842
if (!providedKey) {
4943
throw new HTTPException(401, {
50-
message:
51-
"API key required. Please provide a valid API key in the Authorization header (Bearer token) or x-api-key header.",
44+
message: "Missing API key",
5245
})
5346
}
5447

@@ -59,7 +52,7 @@ export const apiKeyAuthMiddleware: MiddlewareHandler = async (c, next) => {
5952

6053
if (!isValidKey) {
6154
throw new HTTPException(401, {
62-
message: "Invalid API key. Please provide a valid API key.",
55+
message: "Invalid API key",
6356
})
6457
}
6558

0 commit comments

Comments
 (0)