Skip to content

server : do not forward --api-key-file to router-spawned child instances - #28938

Merged
ServeurpersoCom merged 1 commit into
ggml-org:masterfrom
nandan2003:fix-router-api-key-forwarding
Sep 21, 2026
Merged

ServeurpersoCom merged 1 commit into
ggml-org:masterfrom
nandan2003:fix-router-api-key-forwarding

Conversation

@nandan2003

Copy link
Copy Markdown
Contributor

Overview

In router mode, authentication belongs to the router. unset_reserved_args() already unset LLAMA_API_KEY, but did not unset LLAMA_ARG_API_KEY_FILE. When --api-key-file was passed, children re-validated against file keys only, causing clients using --api-key to 401 on chat completions (#28820). In addition, router internal calls without auth headers (such as POST /v1/streams/lookup and DELETE /v1/stream) were silently rejected with 401.

Unset LLAMA_ARG_API_KEY_FILE in unset_reserved_args() so no API keys reach child instances. This keeps keys out of child argv, ensures all keys the router accepts work end-to-end, and prevents router internal stream calls from 401ing.

Fixes #28820

Additional information

Implements the approach suggested by @ServeurpersoCom in #28820 (comment)

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - used an AI assistant to explore the codebase and verify the maintainer's suggested fix. I have reviewed and understand the changes.

In router mode, authentication belongs to the router. unset_reserved_args()
already unset LLAMA_API_KEY, but did not unset LLAMA_ARG_API_KEY_FILE.
When --api-key-file was passed, children re-validated against file keys only,
causing clients using --api-key to 401 on chat completions (ggml-org#28820).
In addition, router internal calls without auth headers (such as
POST /v1/streams/lookup and DELETE /v1/stream) were silently rejected with 401.

Unset LLAMA_ARG_API_KEY_FILE in unset_reserved_args() so no API keys reach
child instances. This keeps keys out of child argv, ensures all keys the router
accepts work end-to-end, and prevents router internal stream calls from 401ing.

Fixes ggml-org#28820
@nandan2003
nandan2003 requested a review from a team as a code owner September 15, 2026 09:16
@ServeurpersoCom

Copy link
Copy Markdown
Contributor

I ran the full matrix on master with and without the line, router mode with --api-key and --api-key-file together, plus the preset INI and environment variable paths:

case without the line with the line
/v1/models, CLI key 200 OK 200 OK
/v1/models, file key 200 OK 200 OK
/v1/chat/completions, CLI key 401 NOK 200 OK
/v1/chat/completions, file key 200 OK 200 OK
wrong key 401 OK 401 OK
no key 401 OK 401 OK
--api-key-file in child argv present NOK absent OK
child direct, POST /v1/streams/lookup 401 NOK 200 OK
child direct, DELETE /v1/stream 401 NOK 204 OK
key set in the INI model section forwarded NOK stripped OK
key set via LLAMA_ARG_API_KEY_FILE in env forwarded NOK forwarded NOK
child port reachable without a key no OK yes NOK, by design
CORS warning in the router log absent OK present NOK, cosmetic

@ServeurpersoCom ServeurpersoCom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Clear improvement in router mode, inert in single model mode

@ServeurpersoCom

Copy link
Copy Markdown
Contributor

And to be sure: the CLI key never reached the child in the first place, so the line changes nothing for --api-key alone, and the whole fix lands on --api-key-file, which is the nominal case and the one that leaves a child asking for a key the router never sends on its two internal calls.

I don't see a case where you would need both flags at the same time, and I think the simplest thing would be to reject them when they are passed together.

--api-key 6614372 alone:

case without the line with the line
/v1/models, valid key 200 OK 200 OK
/v1/models, wrong key 401 OK 401 OK
/v1/models, no key 401 OK 401 OK
/chat/completions, valid key 200 OK 200 OK
/chat/completions, wrong key 401 OK 401 OK
--api-key in child argv absent OK absent OK
--api-key-file in child argv absent OK absent OK
child direct, GET /v1/models 200 NOK, pre-existing 200 NOK, pre-existing
child direct, POST /v1/streams/lookup 200 OK 200 OK
child direct, DELETE /v1/stream 204 OK 204 OK
CORS warning in the router log present NOK, pre-existing present NOK, pre-existing

--api-key-file keys.txt alone:

case without the line with the line
/v1/models, valid key 200 OK 200 OK
/v1/models, wrong key 401 OK 401 OK
/v1/models, no key 401 OK 401 OK
/chat/completions, valid key 200 OK 200 OK
/chat/completions, wrong key 401 OK 401 OK
--api-key in child argv absent OK absent OK
--api-key-file in child argv present NOK absent OK
child direct, GET /v1/models 401 OK 200 NOK, by design
child direct, POST /v1/streams/lookup 401 NOK 200 OK
child direct, DELETE /v1/stream 401 NOK 204 OK
CORS warning in the router log absent OK present NOK, cosmetic

@nandan2003

nandan2003 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @ggerganov , @allozaur

Could you please have a look at this PR when you get a chance? I believe it is a clean merge.

Thanks

@ServeurpersoCom

Copy link
Copy Markdown
Contributor

cc @ngxson because he has the router's architecture in mind :)

@ServeurpersoCom
ServeurpersoCom merged commit 982a332 into ggml-org:master Sep 21, 2026
23 of 26 checks passed
@nandan2003
nandan2003 deleted the fix-router-api-key-forwarding branch September 21, 2026 11:06
LadislavSopko pushed a commit to 0ics-srls/llama.cpp that referenced this pull request Oct 5, 2026
…ces (ggml-org#28938)

In router mode, authentication belongs to the router. unset_reserved_args()
already unset LLAMA_API_KEY, but did not unset LLAMA_ARG_API_KEY_FILE.
When --api-key-file was passed, children re-validated against file keys only,
causing clients using --api-key to 401 on chat completions (ggml-org#28820).
In addition, router internal calls without auth headers (such as
POST /v1/streams/lookup and DELETE /v1/stream) were silently rejected with 401.

Unset LLAMA_ARG_API_KEY_FILE in unset_reserved_args() so no API keys reach
child instances. This keeps keys out of child argv, ensures all keys the router
accepts work end-to-end, and prevents router internal stream calls from 401ing.

Fixes ggml-org#28820
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 7, 2026
…ces (ggml-org#28938)

In router mode, authentication belongs to the router. unset_reserved_args()
already unset LLAMA_API_KEY, but did not unset LLAMA_ARG_API_KEY_FILE.
When --api-key-file was passed, children re-validated against file keys only,
causing clients using --api-key to 401 on chat completions (ggml-org#28820).
In addition, router internal calls without auth headers (such as
POST /v1/streams/lookup and DELETE /v1/stream) were silently rejected with 401.

Unset LLAMA_ARG_API_KEY_FILE in unset_reserved_args() so no API keys reach
child instances. This keeps keys out of child argv, ensures all keys the router
accepts work end-to-end, and prevents router internal stream calls from 401ing.

Fixes ggml-org#28820

(cherry picked from commit 982a332)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misc. bug: server: (router) --api-key is not forwarded to child instances while --api-key-file is

3 participants