getBasicAuthCredentials

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

includeSource
booleanDefaults 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

[string, string][username, password] when includeSource is false.

[string, string, string][username, password, source] when includeSource is true.

Examples

Log credentials at startup

1import { AgentBase } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'assistant', route: '/assistant' });
4agent.setPromptText('You are a helpful assistant.');
5const [user, password] = agent.getBasicAuthCredentials();
6console.log(`Auth: ${user}:${password}`);
7await agent.serve();

Check credential source

1import { AgentBase } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'assistant', route: '/assistant' });
4agent.setPromptText('You are a helpful assistant.');
5const [user, password, source] = agent.getBasicAuthCredentials(true);
6if (source === 'generated') {
7 console.log(`Auto-generated credentials: ${user}:${password}`);
8 console.log('Set SWML_BASIC_AUTH_USER and SWML_BASIC_AUTH_PASSWORD to use your own.');
9}
10await agent.serve();