Merged
Conversation
grzegorz-roboflow
approved these changes
Apr 9, 2026
| return await call_next(request) | ||
|
|
||
| def _unauthorized_response(msg): | ||
| def _authorization_error_response(status_code: int, msg: str): |
Collaborator
There was a problem hiding this comment.
I know the _unauthorized_response was already here, but maybe we can move _authorization_error_response outside of check_authorization_serverless middleware (since it's potentially hot path)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/serverless/usage-check200auth results for 1 hour and short-lived401/402failures for 1 minuteWhy
Serverless inference should fail as early as possible when an API key is not authorized for inference or when the resolved workspace can no longer spend credits.
Impact
Serverless requests now distinguish unauthorized keys from billing-restricted workspaces, while preserving the existing route skip list and workspace header behavior on success.
Root Cause
The existing middleware only verified that an API key resolved to a workspace ID, which did not catch inference authorization and billing-cap failures early enough for serverless deployments.
Validation
python -m py_compile inference/core/roboflow_api.py inference/core/interfaces/http/http_api.py tests/inference/unit_tests/core/test_roboflow_api.py tests/inference/unit_tests/core/interfaces/http/test_http_api.pypython -m pytest ...could not be run in this shell becausepytestis not installed in the active Python environment