Edits history of script submission #5861 for ' Create image (openai)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Openai = {
      api_key: string;
      organization_id: string;
    };
    /**
     * Create image
     * Creates an image given a prompt.
     */
    export async function main(
      auth: Openai,
      body: {
        prompt: string;
        model?: string | ("dall-e-2" | "dall-e-3");
        n?: number;
        quality?: "standard" | "hd";
        response_format?: "url" | "b64_json";
        size?: "256x256" | "512x512" | "1024x1024" | "1792x1024" | "1024x1792";
        style?: "vivid" | "natural";
        user?: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(`https://api.openai.com/v1/images/generations`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "OpenAI-Organization": auth.organization_id,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.api_key,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 372 days ago

  • nativets
    type Openai = {
      api_key: string;
      organization_id: string;
    };
    /**
     * Create image
     * Creates an image given a prompt.
     */
    export async function main(
      auth: Openai,
      body: {
        prompt: string;
        model?: string | ("dall-e-2" | "dall-e-3");
        n?: number;
        quality?: "standard" | "hd";
        response_format?: "url" | "b64_json";
        size?: "256x256" | "512x512" | "1024x1024" | "1792x1024" | "1024x1792";
        style?: "vivid" | "natural";
        user?: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(`https://api.openai.com/v1/images/generations`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "OpenAI-Organization": auth.organization_id,
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.api_key,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 895 days ago