Class OpenAIPlugin

java.lang.Object
com.google.genkit.plugins.openai.OpenAIPlugin
All Implemented Interfaces:
Plugin

public class OpenAIPlugin extends Object implements Plugin
OpenAIPlugin provides OpenAI model integrations for Genkit. This plugin registers OpenAI models (GPT-4, GPT-3.5-turbo, etc.), embeddings (text-embedding-ada-002, etc.), and image generation models (DALL-E, gpt-image-1) as Genkit actions.
  • Field Details

    • SUPPORTED_MODELS

      public static final List<String> SUPPORTED_MODELS
      Supported GPT models.
    • SUPPORTED_EMBEDDING_MODELS

      public static final List<String> SUPPORTED_EMBEDDING_MODELS
      Supported embedding models.
    • SUPPORTED_IMAGE_MODELS

      public static final List<String> SUPPORTED_IMAGE_MODELS
      Supported image generation models.
  • Constructor Details

    • OpenAIPlugin

      public OpenAIPlugin()
      Creates an OpenAIPlugin with default options.
    • OpenAIPlugin

      public OpenAIPlugin(OpenAIPluginOptions options)
      Creates an OpenAIPlugin with the specified options.
      Parameters:
      options - the plugin options
  • Method Details

    • create

      public static OpenAIPlugin create(String apiKey)
      Creates an OpenAIPlugin with the specified API key.
      Parameters:
      apiKey - the OpenAI API key
      Returns:
      a new OpenAIPlugin
    • create

      public static OpenAIPlugin create()
      Creates an OpenAIPlugin using the OPENAI_API_KEY environment variable.
      Returns:
      a new OpenAIPlugin
    • getName

      public String getName()
      Description copied from interface: Plugin
      Returns the unique identifier for the plugin. This name is used for registration and lookup.
      Specified by:
      getName in interface Plugin
      Returns:
      the plugin name
    • init

      public List<Action<?,?,?>> init()
      Description copied from interface: Plugin
      Initializes the plugin. This method is called once during Genkit initialization. The plugin should return a list of actions that it provides.
      Specified by:
      init in interface Plugin
      Returns:
      list of actions provided by this plugin
    • customModel

      public OpenAIPlugin customModel(String modelName)
      Registers a custom chat model name. Use this to work with models not in the default list. Call this method before passing the plugin to Genkit.builder().
      Parameters:
      modelName - the model name (e.g., "gpt-5.3")
      Returns:
      this plugin instance for method chaining
    • customEmbeddingModel

      public OpenAIPlugin customEmbeddingModel(String modelName)
      Registers a custom embedding model name. Use this to work with embedding models not in the default list. Call this method before passing the plugin to Genkit.builder().
      Parameters:
      modelName - the embedding model name (e.g., "text-embedding-4-large")
      Returns:
      this plugin instance for method chaining
    • customImageModel

      public OpenAIPlugin customImageModel(String modelName)
      Registers a custom image generation model name. Use this to work with image models not in the default list. Call this method before passing the plugin to Genkit.builder().
      Parameters:
      modelName - the image model name (e.g., "dall-e-4")
      Returns:
      this plugin instance for method chaining
    • getOptions

      public OpenAIPluginOptions getOptions()
      Gets the plugin options.
      Returns:
      the options