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" (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

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

Check credential source

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