Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
bf668b5b
Unverified
Commit
bf668b5b
authored
Jul 30, 2025
by
Yan Pashkovsky
Committed by
GitHub
Jul 30, 2025
Browse files
[Feature] Support multiple api keys in server (#18548)
Signed-off-by:
Yan Pashkovsky
<
yanp.bugz@gmail.com
>
parent
da3e0bd6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
29 deletions
+30
-29
docs/getting_started/quickstart.md
docs/getting_started/quickstart.md
+1
-0
vllm/entrypoints/openai/api_server.py
vllm/entrypoints/openai/api_server.py
+6
-6
vllm/entrypoints/openai/cli_args.py
vllm/entrypoints/openai/cli_args.py
+23
-23
No files found.
docs/getting_started/quickstart.md
View file @
bf668b5b
...
...
@@ -126,6 +126,7 @@ curl http://localhost:8000/v1/models
```
You can pass in the argument
`--api-key`
or environment variable
`VLLM_API_KEY`
to enable the server to check for API key in the header.
You can pass multiple keys after
`--api-key`
, and the server will accept any of the keys passed, this can be useful for key rotation.
### OpenAI Completions API with vLLM
...
...
vllm/entrypoints/openai/api_server.py
View file @
bf668b5b
...
...
@@ -1239,9 +1239,9 @@ class AuthenticationMiddleware:
2. The request path doesn't start with /v1 (e.g. /health).
"""
def
__init__
(
self
,
app
:
ASGIApp
,
api_
token
:
str
)
->
None
:
def
__init__
(
self
,
app
:
ASGIApp
,
token
s
:
list
[
str
]
)
->
None
:
self
.
app
=
app
self
.
api_token
=
api_
token
self
.
api_token
s
=
{
f
"Bearer
{
token
}
"
for
token
in
token
s
}
def
__call__
(
self
,
scope
:
Scope
,
receive
:
Receive
,
send
:
Send
)
->
Awaitable
[
None
]:
...
...
@@ -1255,7 +1255,7 @@ class AuthenticationMiddleware:
headers
=
Headers
(
scope
=
scope
)
# Type narrow to satisfy mypy.
if
url_path
.
startswith
(
"/v1"
)
and
headers
.
get
(
"Authorization"
)
!=
f
"Bearer
{
self
.
api_token
}
"
:
"Authorization"
)
not
in
self
.
api_token
s
:
response
=
JSONResponse
(
content
=
{
"error"
:
"Unauthorized"
},
status_code
=
401
)
return
response
(
scope
,
receive
,
send
)
...
...
@@ -1512,8 +1512,8 @@ def build_app(args: Namespace) -> FastAPI:
status_code
=
HTTPStatus
.
BAD_REQUEST
)
# Ensure --api-key option from CLI takes precedence over VLLM_API_KEY
if
token
:
=
args
.
api_key
or
envs
.
VLLM_API_KEY
:
app
.
add_middleware
(
AuthenticationMiddleware
,
api_
token
=
token
)
if
token
s
:
=
[
key
for
key
in
(
args
.
api_key
or
[
envs
.
VLLM_API_KEY
])
if
key
]
:
app
.
add_middleware
(
AuthenticationMiddleware
,
token
s
=
token
s
)
if
args
.
enable_request_id_headers
:
app
.
add_middleware
(
XRequestIdMiddleware
)
...
...
vllm/entrypoints/openai/cli_args.py
View file @
bf668b5b
...
...
@@ -85,9 +85,9 @@ class FrontendArgs:
"""Allowed methods."""
allowed_headers
:
list
[
str
]
=
field
(
default_factory
=
lambda
:
[
"*"
])
"""Allowed headers."""
api_key
:
Optional
[
str
]
=
None
"""If provided, the server will require
this
key to be presented in
the
header."""
api_key
:
Optional
[
list
[
str
]
]
=
None
"""If provided, the server will require
one of these
key
s
to be presented in
the
header."""
lora_modules
:
Optional
[
list
[
LoRAModulePath
]]
=
None
"""LoRA modules configurations in either 'name=path' format or JSON format
or JSON list format. Example (old format): `'name=path'` Example (new
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment