ollama / validate_api_key.lua
barisaydin's picture
Update validate_api_key.lua
00c24e6 verified
raw
history blame
477 Bytes
local valid_api_key = os.getenv("OLLAMA_API_KEY")
if not valid_api_key then
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("Internal Server Error: API key not set")
return ngx.exit(ngx.HTTP_INTERNAL_SERVER_ERROR)
end
local headers = ngx.req.get_headers()
local api_key = headers["Authorization"]
if api_key ~= "Bearer " .. valid_api_key then
ngx.status = ngx.HTTP_UNAUTHORIZED
ngx.say("Unauthorized")
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
end