Problem/Motivation

Your module is tied to openai.
There is a module (the AI module) https://www.drupal.org/project/ai that provides a connector where you can easily switch to other AI providers.

Proposed resolution

Use the AI modules connector so your module is not tied to openai only.

Example image generation call via AI module


   $config = [
      "n" => 1,
      "response_format" => "url",
      "size" => "1024x1024",
      "quality" => "standard",
      "style" => "vivid",
    ];
    $tags = ["tag_1", "tag_2"];
    try {
      $ai_provider->setConfiguration($config);
      $input = new TextToImageInput($prompt);
      $response = $ai_provider->textToImage($input_prompt, $default_model, $tags);
      $url = $this->saveAndGetImageUrl($response);

Comments

wouters_f created an issue.