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

Let users access the API using their HF token #1216

Merged
merged 2 commits into from
Aug 26, 2024

Conversation

nsarrazin
Copy link
Collaborator

Simple PR that lets you use bearer authentication against the API if the flag USE_HF_TOKEN_IN_API is set to true. (Currently false while we flesh out API & limits)

This stores token hashes in a cache with a TTL of 5min. If the cache misses, we check against whoami API, grab the user id and check it against our user DB.

Caveat is that the user needs to have signed up once on huggingchat before being able to use the API. (since we don't have access to the user DB of the hub) But I think that's fine

@nsarrazin nsarrazin added back This issue is related to the Svelte backend or the DB api labels May 29, 2024
@nsarrazin nsarrazin requested review from coyotte508 and XciD May 29, 2024 14:28
@nsarrazin
Copy link
Collaborator Author

no rush at all on the review, not on the roadmap just a nice to have I wanted to tackle 😄

@coyotte508
Copy link
Member

Caveat is that the user needs to have signed up once on huggingchat before being able to use the API. (since we don't have access to the user DB of the hub) But I think that's fine

We should have enough info in the whoami response to create the user I think

Also we probably want to make the backend calls to API inference with the token. In that case you can add a X-Required-Access: inference-api header to any calls (including whoami) to the hub to make sure the token has access to the inference api.

Note that we'll also want to use the OAuth access token to make calls to the inference backend (will open an issue)

@nsarrazin nsarrazin merged commit 6dbf140 into main Aug 26, 2024
4 checks passed
@nsarrazin nsarrazin deleted the feat/use_hf_token_for_api branch August 26, 2024 06:28
ice91 pushed a commit to ice91/chat-ui that referenced this pull request Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api back This issue is related to the Svelte backend or the DB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants