Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh API Key Store on API Key Creation #549

Merged
merged 6 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,5 @@ core
app.config.js
wandb
.vscode
api_keys.json
prompting/api/api_keys.json
**/api_keys.json
weights.csv
2 changes: 2 additions & 0 deletions validator_api/api_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def validate_api_key(api_key: str = Header(...)):
@router.post("/create-api-key/")
def create_api_key(rate_limit: int, admin_key: str = Depends(validate_admin_key)):
"""Creates a new API key with a specified rate limit."""
global _keys
new_api_key = secrets.token_hex(16)
_keys[new_api_key] = {"rate_limit": rate_limit, "usage": 0}
save_api_keys(_keys)
_keys = load_api_keys()
return {"message": "API key created", "api_key": new_api_key}


Expand Down
5 changes: 1 addition & 4 deletions validator_api/gpt_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
from shared.epistula import SynapseStreamResult, query_miners
from shared.settings import shared_settings
from shared.uids import get_uids
from validator_api.api_management import _keys
from validator_api.chat_completion import chat_completion
from validator_api.mixture_of_miners import mixture_of_miners
from validator_api.utils import forward_response

router = APIRouter()

# load api keys from api_keys.json
with open("api_keys.json", "r") as f:
_keys = json.load(f)


def validate_api_key(api_key: str = Header(...)):
if api_key not in _keys:
Expand Down
Loading