Skip to content

Add CLI options for backend args (like headers and verify) #230

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kdelee
Copy link

@kdelee kdelee commented Jul 15, 2025

Adds command-line options to the "guidellm benchmark" command to support
custom authentication headers and skipping SSL verification when
communicating with the target system.

New options:
--target-header: Allows specifying a custom header(s) for the target.
--target-skip-ssl-verify: A flag to disable SSL certificate verification for the target.

These options provide more flexibility for benchmarking targets in
various environments, such as those with self-signed certificates or
custom authentication mechanisms. The names were chosen to align with
the existing --target argument to make it clear these apply to requests
made to the target.

The implementation now follows the following precedence for setting request headers:

  1. Headers from the --target-header CLI option (highest priority).
  2. Headers defined in a .env file or as environment variables.
  3. Default headers derived from other parameters like api_key, organization, or project (lowest
    priority).

This commit also adds documentation and tests for these new features,
covering both CLI usage and configuration via environment variables or a
.env file.

@kdelee kdelee marked this pull request as draft July 15, 2025 01:02
Copy link
Collaborator

@sjmonson sjmonson left a comment

Choose a reason for hiding this comment

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

Hey, thanks for the contribution. For backend specific arguments, please nest them under --backend_args and handle any parsing within the backend's __init__. Please also replace all occurrences of ssl with cert or some other protocol neutral term.

@kdelee
Copy link
Author

kdelee commented Jul 16, 2025

Ok thanks for feedback, will look into those changes

@kdelee kdelee changed the title [draft] Add CLI options for auth and ssl verify Add CLI options for backend args (like headers and verify) Jul 16, 2025
@kdelee kdelee marked this pull request as ready for review July 16, 2025 23:37
@kdelee kdelee requested a review from sjmonson July 16, 2025 23:37
kdelee added 4 commits July 16, 2025 19:39
Adds command-line options to the "guidellm benchmark" command to support
custom authentication headers and skipping SSL verification when
communicating with the target system.

New options:
  --target-header: Allows specifying a custom header(s) for the target.
  --target-skip-ssl-verify: A flag to disable SSL certificate verification for the target.

These options provide more flexibility for benchmarking targets in
various environments, such as those with self-signed certificates or
custom authentication mechanisms. The names were chosen to align with
the existing --target argument to make it clear these apply to requests
made to the target.

The implementation now follows the following precedence for setting request headers:
1. Headers from the `--target-header` CLI option (highest priority).
2. Headers defined in a `.env` file or as environment variables.
3. Default headers derived from other parameters like `api_key`, `organization`, or `project` (lowest
priority).

This commit also adds documentation and tests for these new features,
covering both CLI usage and configuration via environment variables or a
`.env` file.
Created new guides for configuration options (environment variables,
.env files) and supported data formats. It also updates the main CLI
reference and links to the new guides.
Refactors the CLI arguments to move backend-specific options under the
`--backend-args` flag.

- Removes `--target-header` and `--target-skip-ssl-verify` from the CLI.
- Updates the `OpenAIHTTPBackend` to parse `headers` and `verify` from the `backend_args` dictionary.
- Renames `verify_ssl` to the protocol-neutral term `verify`.
- Updates documentation and tests to reflect the new argument structure.
@kdelee kdelee force-pushed the ssl_verify_auth_header branch from 037cd42 to e816a81 Compare July 16, 2025 23:39
@kdelee
Copy link
Author

kdelee commented Jul 17, 2025

@sjmonson pushed some updates, looks like workflow needs approval

Copy link
Collaborator

@sjmonson sjmonson left a comment

Choose a reason for hiding this comment

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

Overall looks pretty good, just a few design nits. To fix markdown linting run python -m mdformat <files>

@@ -94,6 +94,7 @@ def __init__(
extra_query: Optional[dict] = None,
extra_body: Optional[dict] = None,
remove_from_body: Optional[list[str]] = None,
**kwargs,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Follow same pattern as other optionals

Suggested change
**kwargs,
headers: Optional[dict] = None,
verify: Optional[bool] = None,

Comment on lines +132 to +134
user_headers = kwargs.pop("headers", settings.openai.headers or {})
default_headers.update(user_headers)
self.headers = default_headers
Copy link
Collaborator

@sjmonson sjmonson Jul 17, 2025

Choose a reason for hiding this comment

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

It would be nice to layer this per-key and support removing headers. Something like this:

Suggested change
user_headers = kwargs.pop("headers", settings.openai.headers or {})
default_headers.update(user_headers)
self.headers = default_headers
default_headers.update(settings.openai.headers or {})
default_headers.update(headers)
self.headers = {k: v for k, v in default_headers.items() if v is not None}

This would also allow you to simplify the default_headers construction to something like:

default_headers = {
  "Authorization": f"Bearer {api_key}" if api_key else settings.openai.bearer_token,
  "OpenAI-Organization": self.organization,
  "OpenAI-Project": project or settings.openai.project,
}

self.timeout = timeout if timeout is not None else settings.request_timeout
self.http2 = http2 if http2 is not None else settings.request_http2
self.follow_redirects = (
follow_redirects
if follow_redirects is not None
else settings.request_follow_redirects
)
self.verify = kwargs.pop("verify", settings.openai.verify)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Due to above suggestion:

Suggested change
self.verify = kwargs.pop("verify", settings.openai.verify)
self.verify = verify or settings.openai.verify

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants