Edits history of script submission #18770 for ' List collections of models (replicate)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Replicate = {
      token: string;
    };
    /**
     * List collections of models
     * Example cURL request:
    
    ```console
    curl -s \
      -H "Authorization: Bearer $REPLICATE_API_TOKEN" \
      https://api.replicate.com/v1/collections
    ```
    
    The response will be a paginated JSON list of collection objects:
    
    ```json
    {
      "next": "null",
      "previous": null,
      "results": [
        {
          "name": "Super resolution",
          "slug": "super-resolution",
          "description": "Upscaling models that create high-quality images from low-quality images."
        }
      ]
    }
    ```
    
     */
    export async function main(auth: Replicate) {
      const url = new URL(`https://api.replicate.com/v1/collections`);
    
      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