instance property

OpenAI get instance

The singleton instance of OpenAI, make sure to call the OpenAI.initialize method before accessing instance, otherwise it will throw an Exception. A MissingApiKeyException will be thrown, if the API key is not set.

Implementation

static OpenAI get instance {
  if (_internalApiKey == null) {
    throw Exception("""
    You must set the api key before accessing the instance of this class.
    Example:
    OpenAI.apiKey = "Your API Key";
    """);
  }

  return _instance;
}