AgentsAgentBase

get_basic_auth_credentials

View as MarkdownOpen in Claude

Retrieve the username and password used for HTTP Basic Auth on this agent. Optionally includes a source label indicating where the credentials came from.

Parameters

include_source
boolDefaults to False

When True, the returned tuple includes a third element indicating the credential source: "provided" (set explicitly), "environment" (from SWML_BASIC_AUTH_USER / SWML_BASIC_AUTH_PASSWORD environment variables), or "generated" (auto-generated at startup).

Returns

tuple[str, str](username, password) when include_source is False.

tuple[str, str, str](username, password, source) when include_source is True.

Examples

Log credentials at startup

1from signalwire import AgentBase
2
3agent = AgentBase(name="assistant", route="/assistant")
4agent.set_prompt_text("You are a helpful assistant.")
5user, password = agent.get_basic_auth_credentials()
6print(f"Auth: {user}:{password}")
7agent.serve()

Check credential source

1from signalwire import AgentBase
2
3agent = AgentBase(name="assistant", route="/assistant")
4agent.set_prompt_text("You are a helpful assistant.")
5user, password, source = agent.get_basic_auth_credentials(include_source=True)
6if source == "generated":
7 print(f"Auto-generated credentials: {user}:{password}")
8 print("Set SWML_BASIC_AUTH_USER and SWML_BASIC_AUTH_PASSWORD to use your own.")
9agent.serve()