ApiKey Property  
 

Sets or returns the API key used for the current session.

Syntax

object.ApiKey [= value ]

Remarks

The ApiKey property is a String value that specifies the API key used to authenticate with the provider. The API key may be provided using a literal string, an environment variable, or a value stored in the Windows Credential Manager. Using an environment variable or secure credential storage is recommended for production applications to avoid exposing sensitive information in source code or application binaries.

If the selected provider requires authentication, the API key can be provided in several formats, allowing applications to provide credentials in a way that balances convenience and security:

  • Literal string
    The API key is provided directly as a string. This is the simplest approach and is convenient for testing or small internal tools, but it is not recommended for production applications. The string may be exposed in source code, configuration files, diagnostic logs or the compiled application binary.
  • Environment variable
    The name of an environment variable enclosed in percent symbols, for example "%OPENAI_API_KEY%". The value of the environment variable is used as the API key. This avoids embedding the key directly in the application and is useful for development, scripts and deployment environments. However, environment variables may still be visible to the current user, inherited by child processes or exposed through system configuration, so they should still be protected appropriately.
  • Windows credential
    A credential name enclosed in braces, for example "{MyAppName/OpenAI}". The API key is retrieved from the Windows Credential Manager using the specified name. This is the recommended approach for most Windows applications because the secret is stored outside the application and managed by the operating system. The credential can be created manually using Credential Manager, or programmatically by the application using the Windows Credential Management API. Applications should choose a unique credential name and document it clearly if users or administrators are expected to configure the value themselves.

For production applications, it is recommended that you avoid using literal API key strings and instead use an environment variable or a value stored in the Windows Credential Manager. If you must provide the API key as a literal string, you should take additional steps to protect it, such as storing the key in an encrypted form and limiting access to authorized users or processes. Avoid embedding API keys directly in application source code, configuration files, installers or other content that could be exposed through version control systems, logs or public repositories.

Data Type

String

See Also

BaseUrl Property, Provider Property, ProviderName Property, ModelName Property, Connect Method