The Authorization
class is defined in authorization.h
at liboai::Authorization
. This class is responsible for sharing all set authorization information with all component classes in liboai
.
All authorization information should be set prior to the calling of any component methods such as Images
, Embeddings
, and so on. Failure to do so will result in a liboai::OpenAIException
due to authorization failure on OpenAI's end.
This document covers the method(s) located in authorization.h
. You can find their function signature(s) below.
Returns a reference to the liboai::Authorization
singleton shared among all components.
static Authorization& Authorizer() noexcept;
Sets the API key to use in subsequent component calls.
bool SetKey(std::string_view key) noexcept;
Sets the Azure API key to use in subsequent component calls.
bool SetAzureKey(std::string_view key) noexcept;
Sets the Active Directory Azure API key to use in subsequent component calls.
bool SetAzureKeyAD(std::string_view key) noexcept;
Sets the API key to use in subsequent component calls from data found in file at path.
bool SetKeyFile(const std::filesystem::path& path) noexcept;
Sets the Azure API key to use in subsequent component calls from data found in file at path.
bool SetAzureKeyFile(const std::filesystem::path& path) noexcept;
Sets the Active Directory Azure API key to use in subsequent component calls from data found in file at path.
bool SetAzureKeyFileAD(const std::filesystem::path& path) noexcept;
Sets the API key to use in subsequent component calls from an environment variable.
bool SetKeyEnv(std::string_view var) noexcept;
Sets the Azure API key to use in subsequent component calls from an environment variable.
bool SetAzureKeyEnv(std::string_view var) noexcept;
Sets the Active Directory Azure API key to use in subsequent component calls from an environment variable.
bool SetAzureKeyEnvAD(std::string_view var) noexcept;
Sets the organization ID to send in subsequent component calls.
bool SetOrganization(std::string_view org) noexcept;
Sets the organization ID to send in subsequent component calls from data found in file at path.
bool SetOrganizationFile(const std::filesystem::path& path) noexcept;
Sets the organization ID to send in subsequent component calls from an environment variable.
bool SetOrganizationEnv(std::string_view var) noexcept;
Sets the proxy, or proxies, to use in subsequent component calls.
void SetProxies(const std::initializer_list<std::pair<const std::string, std::string>>& hosts) noexcept;
void SetProxies(std::initializer_list<std::pair<const std::string, std::string>>&& hosts) noexcept;
void SetProxies(const std::map<std::string, std::string>& hosts) noexcept;
void SetProxies(std::map<std::string, std::string>&& hosts) noexcept;
Sets the username and password to use when using a certain proxy protocol.
void SetProxyAuth(const std::map<std::string, netimpl::components::EncodedAuthentication>& proto_up) noexcept;
Sets the timeout in milliseconds for the library to use in component calls.
void SetMaxTimeout(int32_t ms) noexcept
Returns the currently set API key.
constexpr const std::string& GetKey() const noexcept;
Returns the currently set organization ID.
constexpr const std::string& GetOrganization() const noexcept;
Returns the currently set proxies.
netimpl::components::Proxies GetProxies() const noexcept;
Returns the currently set proxy authentication information.
netimpl::components::ProxyAuthentication GetProxyAuth() const noexcept;
Returns the currently set timeout.
netimpl::components::Timeout GetMaxTimeout() const noexcept;
Returns the currently set authorization headers based on set information.
constexpr const netimpl::components::Header& GetAuthorizationHeaders() const noexcept;
Returns the currently set Azure authorization headers based on set information.
constexpr const netimpl::components::Header& GetAzureAuthorizationHeaders() const noexcept;
For example usage of the above function(s), please refer to the examples folder.