Skip to content

[Python] Fix Hugging Face API token fallback - #40779

Draft
bvolpato wants to merge 1 commit into
apache:masterfrom
bvolpato:bvolpato/huggingface-api-error-reporting
Draft

bvolpato wants to merge 1 commit into
apache:masterfrom
bvolpato:bvolpato/huggingface-api-error-reporting

Conversation

@bvolpato

@bvolpato bvolpato commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Related #30799.

When the token comes from HF_TOKEN, the redundant request header replaces the valid session header with Bearer None, and the provider rejects the request. Reuse the authorization established when loading the session.

Pass the URL to the API URL log call, which currently prints a literal %s.

The HTTP error handling from the first version of this change landed separately in #40953. This PR keeps that handling and adds regression checks for it.

In a real pipeline against a local fake endpoint, current master sends Bearer None for the HF_TOKEN fallback, and this change sends the real token. The token regression check fails without this change and passes with it. The module tests, Ruff, and YAPF ran locally. The live Inference API tests need a token, so they were not run.

@github-actions github-actions Bot added python size/s S: 10-49 lines changed labels Oct 25, 2026
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.85%. Comparing base (12bbb17) to head (657faba).
⚠️ Report is 19 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40779      +/-   ##
==========================================
+ Coverage   79.83%   79.85%   +0.02%     
==========================================
  Files         494      494              
  Lines       83575    83582       +7     
==========================================
+ Hits        66722    66747      +25     
+ Misses      16853    16835      -18     
Flag Coverage Δ
python 79.85% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bvolpato
bvolpato force-pushed the bvolpato/huggingface-api-error-reporting branch 2 times, most recently from 74c1d31 to 48dcc1f Compare November 3, 2026 03:46
The handler passed an authorization header on each request, which replaced the header of the session. When the token came from the HF_TOKEN environment variable, the request sent Bearer None and the provider rejected it.

Reuse the authorization established when loading the session. Also pass the URL to the API URL log call, which printed a literal %s.
@bvolpato
bvolpato force-pushed the bvolpato/huggingface-api-error-reporting branch from 48dcc1f to 3605e47 Compare November 4, 2026 15:19
@bvolpato bvolpato changed the title [Python] Fix Hugging Face API error and token handling [Python] Fix Hugging Face API token fallback Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python size/s S: 10-49 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant