Skip to content
Help guide the future of agentgateway — Take the survey

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Basic authentication

Page as Markdown

Configure simple username and password authentication for your routes.

Attaches to:

Route

Note

Agentgateway supports more than one configuration style. Where a feature can also be configured in the simplified llm or mcp modes, the examples on this page show each option in tabs. For more information, see Routing-based configuration.

Basic authentication enables a simple username/password authentication mechanism.

Warning

Basic authentication is not generally recommended for production use. At a minimum, use basic authentication along with TLS encryption.

The htpasswd field specifies the username/password pairs. See the htpasswd documentation. If you set it to {file: <path>}, agentgateway watches the file and reloads the configuration when the file changes, so you can add users or rotate passwords without a restart. For bcrypt hashes, use cost 14 or lower. The htpasswd parser ignores hashes with a higher cost. The realm field, optionally, specifies the realm name returned in error responses. The realm defaults to Restricted. A request that fails authentication gets a 401 Unauthorized response with a WWW-Authenticate: Basic realm="<realm>" header, which makes a browser prompt for credentials.

The htpasswd entries can use the following hash formats. Plaintext passwords are not supported.

Hash formathtpasswd optionHash prefix
bcrypt-B$2y$, $2a$, or $2b$
Apache MD5-m$apr1$
SHA-1-s{SHA}
crypt-dNone

Additionally, authentication can run in two different modes:

  • Strict: A valid username/password pair must be present.
  • Optional (default): If a username/password pair exists, validate it.
    Warning: This allows requests without a username/password pair!

Warning

Agentgateway expands environment variables in the whole configuration file before parsing the file, including in comments. In an inline htpasswd value, write each $ of a hash as $$, as in the following examples. A single $ makes the configuration fail to load, with an error about an environment variable that is not found. A file that you reference with htpasswd.file is read as is, so do not escape the $ characters in that file.

# yaml-language-server: $schema=https://agentgateway.dev/schema/config
llm:
  policies:
    basicAuth:
      mode: strict
      # Generated with `htpasswd -nb -B user1 agentgateway`
      # You can also use:
      # htpasswd:
      #   file: /path/to/htpasswd
      # With inline configuration, $ must be escaped to $$.
      htpasswd: |
        user1:$$2y$$05$$LMZ.8WGNqvagmtJz2Gw6VuiE6khXc2zc0FDTHrfWJyLT66HM8BMAa
      realm: example.com
  models:
  - name: "*"
    provider: openAI
    params:
      apiKey: "$OPENAI_API_KEY"

Now to send requests, include the username and password.

curl http://user1:agentgateway@localhost:3000
Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate ↵ select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.