Edits history of script submission #18759 for ' Get a collection of models (replicate)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Replicate = {
      token: string;
    };
    /**
     * Get a collection of models
     * Example cURL request:
    
    ```console
    curl -s \
      -H "Authorization: Bearer $REPLICATE_API_TOKEN" \
      https://api.replicate.com/v1/collections/super-resolution
    ```
    
    The response will be a collection object with a nested list of the models in that collection:
    
    ```json
    {
      "name": "Super resolution",
      "slug": "super-resolution",
      "description": "Upscaling models that create high-quality images from low-quality images.",
      "models": [...]
    }
    ```
    
     */
    export async function main(auth: Replicate, collection_slug: string) {
      const url = new URL(
        `https://api.replicate.com/v1/collections/${collection_slug}`,
      );
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago