If the method succeeds, the return value is the number of
characters copied into the string buffer, not including the
terminating null character. If the method fails, the return
value is zero. To get extended error information, call
GetLastError.
The GetUserAgent method retrieves the user-agent string
currently configured for the client session. This value is included
in HTTP requests sent to the provider unless disabled using the
LLM_OPTION_NOUSERAGENT option.
If no user-agent string has been explicitly set using
SetUserAgent, the method may return a default value
defined by the library, or no value depending on the current
configuration.
To determine the required buffer size, call this method with
lpszUserAgent set to NULL. The return value specifies the
number of characters in the string, excluding the terminating
null character. If there is no user-agent string defined for the session, the
method returns zero and the last error value is cleared
(set to NO_ERROR). This condition should not be treated as a failure.
In most cases, the user-agent string will be relatively small. A buffer
of 256 characters is typically sufficient for standard user-agent values.
If a custom user-agent string is used, a larger buffer (such as 512
characters) may be more appropriate. Applications that require complete
flexibility should query the required length and allocate the buffer
dynamically.
The user-agent string is typically used by providers for logging
or request identification. Developers should avoid including
sensitive information in this value.
TCHAR szUserAgent[256] = _T("");
if (llmClient.GetUserAgent(szUserAgent, _countof(szUserAgent)) > 0)
{
_tprintf(_T("User-Agent: %s\n"), szUserAgent);
}
else
{
DWORD dwError = llmClient.GetLastError();
_tprintf(_T("Error retrieving user-agent (0x%08lX)\n"), dwError);
}