grok2api icon indicating copy to clipboard operation
grok2api copied to clipboard

bug: /v1/admin/tokens returns 500 (NameError: get_config not defined) on latest/main

Open coolxll opened this issue 8 months ago • 1 comments

### Summary /v1/admin/tokens can return 500 Internal Server Error on the current main/latest image because get_config is used but not imported in app/api/v1/admin/token.py.

Affected image/revision

  • GHCR image: ghcr.io/chenyme/grok2api:latest / latest-amd64
  • Observed OCI revision label: 7796e080849b158514a40a5d62f0bec140e53842

Reproduction

  1. Deploy ghcr.io/chenyme/grok2api:latest.
  2. Call GET /v1/admin/tokens with a valid admin/app auth token.
  3. Server responds 500.

Requests without auth still return 401, so this can be missed unless authenticated path is tested.

Error log

File "/app/app/api/v1/admin/token.py", line 53, in get_tokens
  consumed_mode = get_config("token.consumed_mode_enabled", False)
NameError: name 'get_config' is not defined

Root cause

In app/api/v1/admin/token.py, get_tokens() calls get_config(...) but the module lacks:

from app.core.config import get_config

Fix

Add the missing import near other app.core.* imports:

diff --git a/app/api/v1/admin/token.py b/app/api/v1/admin/token.py
@@
 from app.core.auth import get_app_key, verify_app_key
 from app.core.batch import create_task, expire_task, get_task
+from app.core.config import get_config
 from app.core.logger import logger
 from app.core.storage import get_storage

Temporary hotfix for running container

docker exec grok2api sh -lc "sed -i '/from app.core.batch/a from app.core.config import get_config' /app/app/api/v1/admin/token.py"
docker compose restart grok2api

Notes

I also noticed existing reports (#345, #353). Posting this as a reproducible RCA + exact patch to simplify maintainers' verification and release fix.

coolxll avatar Mar 18 '26 02:03 coolxll

Hey! I may be able to help with this bug.

I build custom fixes for Python projects and automation systems.

If you'd like help resolving this issue quickly feel free to reach out.

Happy to take a look 👍

FocusMode-coder avatar Mar 18 '26 03:03 FocusMode-coder