From c06c8d594a7ab9b42a1e72387560e8088deb03d9 Mon Sep 17 00:00:00 2001 From: Pepijn Date: Tue, 28 Apr 2026 19:36:24 +0200 Subject: [PATCH] feat(annotate): use cached HF token from huggingface-cli login Fall back to huggingface_hub.get_token() when HF_TOKEN/HUGGINGFACE_API_KEY env vars aren't set. That picks up the token cached by 'huggingface-cli login' so users don't need to export it on every shell. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../annotations/steerable_pipeline/vlm_client.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lerobot/annotations/steerable_pipeline/vlm_client.py b/src/lerobot/annotations/steerable_pipeline/vlm_client.py index 8fe40b785..7bfc8e62c 100644 --- a/src/lerobot/annotations/steerable_pipeline/vlm_client.py +++ b/src/lerobot/annotations/steerable_pipeline/vlm_client.py @@ -283,10 +283,17 @@ def _make_openai_client(config: VlmConfig) -> VlmClient: if config.use_hf_inference_providers: api_base = "https://router.huggingface.co/v1" token = os.environ.get("HF_TOKEN") or os.environ.get("HUGGINGFACE_API_KEY") or "" + if not token: + try: + from huggingface_hub import get_token # noqa: PLC0415 + + token = get_token() or "" + except Exception: # noqa: BLE001 + token = "" if not token: raise RuntimeError( - "use_hf_inference_providers=True requires HF_TOKEN (or " - "HUGGINGFACE_API_KEY) in the environment." + "use_hf_inference_providers=True needs an HF token. Either set " + "HF_TOKEN in the environment, or run `huggingface-cli login` once." ) api_key = token auto_serve = False