Edits history of script submission #12503 for ' Calculating API Cost (leonardoai)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Leonardoai = {
      apiKey: string;
    };
    /**
     * Calculating API Cost
     * This endpoint returns the cost used for generating images using a particular service type.
     */
    export async function main(
      auth: Leonardoai,
      body: {
        service?:
          | "IMAGE_GENERATION"
          | "FANTASY_AVATAR_GENERATION"
          | "MOTION_GENERATION"
          | "LCM_GENERATION"
          | "MODEL_TRAINING"
          | "TEXTURE_GENERATION"
          | "UNIVERSAL_UPSCALER"
          | "UNIVERSAL_UPSCALER_ULTRA";
        serviceParams?: {
          IMAGE_GENERATION?: {
            imageHeight?: number;
            imageWidth?: number;
            numImages?: number;
            inferenceSteps?: number;
            promptMagic?: false | true;
            promptMagicStrength?: number;
            promptMagicVersion?: string;
            alchemyMode?: false | true;
            photoRealMode?: false | true;
            photoRealStrength?: number;
            photoRealVersion?: string;
            highResolution?: false | true;
            loraCount?: number;
            isModelCustom?: false | true;
            controlnetsCost?: number;
            isPhoenix?: false | true;
            isSDXL?: false | true;
            isSDXLLightning?: false | true;
            ultra?: false | true;
          };
          FANTASY_AVATAR_GENERATION?: {
            imageHeight?: number;
            imageWidth?: number;
            numImages?: number;
          };
          MOTION_GENERATION?: { durationSeconds?: number };
          LCM_GENERATION?: {
            height?: number;
            width?: number;
            instantRefine?: false | true;
            refine?: false | true;
          };
          MODEL_TRAINING?: { resolution?: number };
          TEXTURE_GENERATION?: { preview?: false | true };
          UNIVERSAL_UPSCALER?: { megapixel?: number };
          UNIVERSAL_UPSCALER_ULTRA?: {
            inputWidth?: number;
            inputHeight?: number;
            upscaleMultiplier?: number;
          };
        };
      },
    ) {
      const url = new URL(
        `https://cloud.leonardo.ai/api/rest/v1/pricing-calculator`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        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 428 days ago