Llama AuthKeys is a lightweight authentication service built with Flask. It provides token management capabilities, including creating, listing, and revoking tokens. The service also proxies requests to an external API while ensuring proper authorization based on token scopes.
- Token Management: Create, list, and revoke tokens.
- Scope-based Authorization: Tokens have associated scopes that determine access levels.
- Request Logging: Logs all incoming requests for auditing purposes.
- Proxy Requests: Forwards requests to an external API with proper authentication.
- Python 3+
- Flask
- SQLite3
-
Clone the repository:
git clone https://github.com/NeuralWeights/llama-server-authkeys.git cd llama-server-authkeys
-
Install dependencies:
pip install flask
Align the config.ini
file to your needs if needed.
[APP]
host=127.0.0.1
port=5001
[DB]
db_name=authwall.db
root_token=root
[INFER]
completions=http://localhost:1234/v1/chat/completions
v1=http://localhost:1234/v1
-
Start the application:
python app.py
-
Access the service at
http://localhost:5001
.
curl -X GET http://localhost:5001/list_tokens -H "Content-Type: application/json" -d "{\"token\": \"root\"}"
curl -X POST http://localhost:5001/create_token -H "Content-Type: application/json" -d "{\"token\": \"root\", \"scope\": \"infer:write\", \"expired_at\": 1756800000}"
curl -X POST http://localhost:5001/revoke_token -H "Content-Type: application/json" -d "{\"token\": \"root\", \"token_to_revoke\": \"the_token_to_revoke\"}"
curl -X POST http://localhost:5001/v1/chat/completions -H "Content-Type: application/json" -d "{\"token\": \"your_new_token\", \"model\": \"Llama-3.3-70B-instruct\", \"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful assistant\"}, {\"role\": \"user\", \"content\": \"Hello\"}], \"temperature\": 0.7}"
curl http://127.0.0.1:5001/v1/embeddings -H "Content-Type: application/json" -d "{ \"model\": \"text-embedding-nomic-embed-text-v1.5\", \"input\": \"Some text to embed\", \"token\": \"root\" }"