Genkit JS API reference
    Preparing search index...

    Function openAICompatible

    • This module provides the openAICompatible plugin factory for Genkit. It enables interaction with OpenAI-compatible API endpoints, allowing users to leverage various AI models by configuring API keys and other client options.

      The core export is openAICompatible, a function that accepts PluginOptions and returns a Genkit plugin.

      Key PluginOptions include:

      • name: A string to uniquely identify this plugin instance (e.g., 'deepSeek', 'customOpenAI').
      • apiKey: The API key for the service. If not provided directly, the plugin will attempt to use the OPENAI_API_KEY environment variable.
      • initializer: An optional asynchronous function for custom setup after the OpenAI client is initialized. It receives the Genkit instance and the OpenAI client.
      • Additional properties from OpenAI's ClientOptions (like baseURL, timeout, etc.) can be passed to customize the OpenAI client.

      The returned plugin initializes an OpenAI client tailored to the provided options, making configured models available for use within Genkit flows.

      Parameters

      Returns GenkitPluginV2Instance

      A Genkit plugin configured for an OpenAI-compatible service.

      Usage: Import openAICompatible (or your chosen import name for the default export) from this package (e.g., genkitx-openai). Then, invoke it within the plugins array of configureGenkit, providing the necessary PluginOptions.

      Example:

      import myOpenAICompatiblePlugin from 'genkitx-openai'; // Default import

      export default configureGenkit({
      plugins: [
      myOpenAICompatiblePlugin({
      name: 'gpt4o', // Name for this specific plugin configuration
      apiKey: process.env.OPENAI_API_KEY,
      // For a non-OpenAI compatible endpoint:
      // baseURL: 'https://api.custom-llm-provider.com/v1',
      }),
      myOpenAICompatiblePlugin({
      name: 'localLlama',
      apiKey: 'ollama', // Or specific key if required by local server
      baseURL: 'http://localhost:11434/v1', // Example for Ollama
      }),
      // ... other plugins
      ],
      });