CLlmClient::GetProviderId Method  
 
DWORD GetProviderId();
DWORD GetProviderId(
  LPCTSTR lpszProviderName,  
  LPCTSTR lpszBaseUrl,  
  LPCTSTR lpszModelName  
);

The GetProviderId method returns the current provider ID or one based on a provider name, endpoint URL or model name.

Parameters

lpszProviderName
A null-terminated string which specifies the provider name. This parameter may be NULL if you do not wish to match against a provider name. At least one parameter must be specified. If a provider name is specified, it is given precedence over the other parameters.
lpszBaseUrl
A null-terminated string which specifies an endpoint URL. This parameter may be NULL if you do not wish to match against an endpoint URL. At least one parameter must be specified. An endpoint URL will only be used if the function is unable to determine the provider ID from the lpszProviderName parameter. If an endpoint URL is specified, it is given precedence over a model name.
lpszModelName
A null-terminated string which specifies a model name. This parameter may be NULL if you do not wish to match against a model name. At least one parameter must be specified. A model name will only be used if the function is unable to determine the provider ID from the lpszProviderName or lpszBaseUrl parameters.

Return Value

If the method succeeds, the return value is the provider ID. If the method fails, the return value is LLM_PROVIDER_UNKNOWN. To get extended error information, call GetLastError.

Remarks

The GetProviderId method can be called in two different ways. If the method is called without any arguments, it will return the provider ID associated with the current client session. This is useful when an application supports multiple providers and needs to adjust its behavior based on the active provider.

Another version of this method attempts to determine the provider ID using the parameters passed to it in order of precedence. If a provider name is specified and recognized, that value is considered authoritative and the remaining parameters are ignored. If the provider name is not recognized, the method will attempt to determine the provider from the endpoint URL. If the provider cannot be determined from the endpoint URL, the method will attempt to infer the provider from the model name.

The method performs normalization on the input values before matching them against known providers. Leading and trailing whitespace is ignored, provider names are matched without regard to case and common variations of provider names are recognized.

When matching against a model name, the method identifies the company or organization most commonly associated with the model family. This may not reflect the actual service endpoint hosting the model. For example, a model hosted by a local inference server or aggregate provider may still be identified as the company who originally created the model.

This method only recognizes well-known providers, endpoint URLs and model families. If the provider cannot be determined, the method will return LLM_PROVIDER_UNKNOWN and the last error code will be set to ST_ERROR_PROVIDER_NOT_FOUND.

Example

// Get the provider ID for the current client session
DWORD dwProviderId = llmClient.GetProviderId();

if (dwProviderId != LLM_PROVIDER_UNKNOWN)
{
    TCHAR szBaseUrl[128] = {0};
    llmClient.GetProviderUrl(szBaseUrl, _countof(szBaseUrl));
    
    _tprintf(_T("Provider ID: %lu\n"), dwProviderId);
    _tprintf(_T("Base URL: %s\n"), szBaseUrl);
}
else
{
    DWORD dwError = llmClient.GetLastError();
    _tprintf(_T("Unable to get provider information, error 0x%08lx\n"), dwError);
}

// Determine the provider ID using a base endpoint URL
LPCTSTR lpszUrl = _T("https://api.openai.com/v1/")

dwProviderId = llmClient.GetProviderId(NULL, lpszUrl, NULL);

if (dwProviderId != LLM_PROVIDER_UNKNOWN)
{
    TCHAR szName[64] = {0};
    llmClient.GetProviderName(dwProviderId, szName, _countof(szName));
    
    _tprintf(_T("The provider for %s is %s\n"), lpszUrl, szName);
}
else
{
    DWORD dwError = llmClient.GetLastError();
    _tprintf(_T("Unable to get the provider ID, error 0x%08lx\n"), dwError);
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: csllmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also